Changed permission view. Bank withdraw permission in the works

This commit is contained in:
Olof Larsson 2011-10-24 11:56:41 +02:00
parent 99e8acd79f
commit 5f437b1862
8 changed files with 72 additions and 56 deletions

View File

@ -187,7 +187,7 @@ public class Conf
//Faction banks, to pay for land claiming and other costs instead of individuals paying for them //Faction banks, to pay for land claiming and other costs instead of individuals paying for them
public static boolean bankEnabled = true; public static boolean bankEnabled = true;
public static boolean bankMembersCanWithdraw = false; //Have to be at least moderator to withdraw or pay money to another faction //public static boolean bankMembersCanWithdraw = false; //Have to be at least moderator to withdraw or pay money to another faction
public static boolean bankFactionPaysCosts = true; //The faction pays for faction command costs, such as sethome public static boolean bankFactionPaysCosts = true; //The faction pays for faction command costs, such as sethome
public static boolean bankFactionPaysLandCosts = true; //The faction pays for land claiming costs. public static boolean bankFactionPaysLandCosts = true; //The faction pays for land claiming costs.

View File

@ -46,13 +46,6 @@ public class Faction extends Entity implements EconomyParticipator
} }
return this.getTag(this.getColorTo(observer).toString()); return this.getTag(this.getColorTo(observer).toString());
} }
public String getTag(FPlayer otherFplayer) {
if (otherFplayer == null)
{
return getTag();
}
return this.getTag(this.getColorTo(otherFplayer).toString());
}
public void setTag(String str) public void setTag(String str)
{ {
if (Conf.factionTagForceUpperCase) if (Conf.factionTagForceUpperCase)

View File

@ -113,11 +113,11 @@ public class Factions extends EntityCollection<Faction>
faction.setFlag(FFlag.LIGHTNING, true); faction.setFlag(FFlag.LIGHTNING, true);
faction.setFlag(FFlag.ENDERGRIEF, true); faction.setFlag(FFlag.ENDERGRIEF, true);
faction.setPermittedRelations(FPerm.BUILD, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); faction.setPermittedRelations(FPerm.BUILD, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.DOOR, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.CONTAINER, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.BUTTON, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.LEVER, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
} }
public void setFlagsForSafeZone(Faction faction) public void setFlagsForSafeZone(Faction faction)
@ -134,11 +134,10 @@ public class Factions extends EntityCollection<Faction>
faction.setFlag(FFlag.LIGHTNING, false); faction.setFlag(FFlag.LIGHTNING, false);
faction.setFlag(FFlag.ENDERGRIEF, false); faction.setFlag(FFlag.ENDERGRIEF, false);
faction.setPermittedRelations(FPerm.BUILD, Rel.ALLY, Rel.MEMBER); faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.DOOR, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.CONTAINER, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.BUTTON, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.LEVER, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER);
} }
public void setFlagsForWarZone(Faction faction) public void setFlagsForWarZone(Faction faction)
@ -155,11 +154,10 @@ public class Factions extends EntityCollection<Faction>
faction.setFlag(FFlag.LIGHTNING, true); faction.setFlag(FFlag.LIGHTNING, true);
faction.setFlag(FFlag.ENDERGRIEF, true); faction.setFlag(FFlag.ENDERGRIEF, true);
faction.setPermittedRelations(FPerm.BUILD, Rel.ALLY, Rel.MEMBER); faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.DOOR, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.CONTAINER, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.BUTTON, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.LEVER, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER);
} }

View File

@ -39,7 +39,7 @@ public class CmdFlag extends FCommand
if ( ! this.argIsSet(1)) if ( ! this.argIsSet(1))
{ {
msg(p.txt.titleize("Flags for " + faction.describeTo(fme))); msg(p.txt.titleize("Flags for " + faction.describeTo(fme, true)));
for (FFlag flag : FFlag.values()) for (FFlag flag : FFlag.values())
{ {
msg(flag.getStateInfo(faction.getFlag(flag), true)); msg(flag.getStateInfo(faction.getFlag(flag), true));
@ -51,7 +51,7 @@ public class CmdFlag extends FCommand
if (flag == null) return; if (flag == null) return;
if ( ! this.argIsSet(2)) if ( ! this.argIsSet(2))
{ {
msg(p.txt.titleize("Flag for " + faction.describeTo(fme))); msg(p.txt.titleize("Flag for " + faction.describeTo(fme, true)));
msg(flag.getStateInfo(faction.getFlag(flag), true)); msg(flag.getStateInfo(faction.getFlag(flag), true));
return; return;
} }
@ -81,7 +81,7 @@ public class CmdFlag extends FCommand
} }
// Do the change // Do the change
msg(p.txt.titleize("Flag for " + faction.describeTo(fme))); msg(p.txt.titleize("Flag for " + faction.describeTo(fme, true)));
faction.setFlag(flag, targetValue); faction.setFlag(flag, targetValue);
msg(flag.getStateInfo(faction.getFlag(flag), true)); msg(flag.getStateInfo(faction.getFlag(flag), true));
} }

View File

@ -44,7 +44,8 @@ public class CmdPerm extends FCommand
if ( ! this.argIsSet(1)) if ( ! this.argIsSet(1))
{ {
msg(p.txt.titleize("Perms for " + faction.describeTo(fme))); msg(p.txt.titleize("Perms for " + faction.describeTo(fme, true)));
msg(FPerm.getStateHeaders());
for (FPerm perm : FPerm.values()) for (FPerm perm : FPerm.values())
{ {
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
@ -56,7 +57,8 @@ public class CmdPerm extends FCommand
if (perm == null) return; if (perm == null) return;
if ( ! this.argIsSet(2)) if ( ! this.argIsSet(2))
{ {
msg(p.txt.titleize("Perm for " + faction.describeTo(fme))); msg(p.txt.titleize("Perm for " + faction.describeTo(fme, true)));
msg(FPerm.getStateHeaders());
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
return; return;
} }
@ -81,7 +83,8 @@ public class CmdPerm extends FCommand
// Do the change // Do the change
faction.setPermittedRelations(perm, targetValue); faction.setPermittedRelations(perm, targetValue);
msg(p.txt.titleize("Perm for " + faction.describeTo(fme))); msg(p.txt.titleize("Perm for " + faction.describeTo(fme, true)));
msg(FPerm.getStateHeaders());
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
} }

View File

@ -16,8 +16,8 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.struct.FPerm;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Rel;
import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.util.RelationUtil;
public class Econ public class Econ
@ -106,8 +106,8 @@ public class Econ
// Ohh by the way... Yes it could. For daily rent to the faction. // Ohh by the way... Yes it could. For daily rent to the faction.
if (i == fI && fI == fYou) return true; if (i == fI && fI == fYou) return true;
// Factions can be controlled by members that are moderators... or any member if any member can withdraw. // Factions can be controlled by those that have permissions
if (you instanceof Faction && fI == fYou && (Conf.bankMembersCanWithdraw || ((FPlayer)i).getRole().isAtLeast(Rel.OFFICER))) return true; if (you instanceof Faction && FPerm.WITHDRAW.has(i, fYou)) return true;
// Otherwise you may not! ;,,; // Otherwise you may not! ;,,;
i.msg("<h>%s<i> lack permission to controll <h>%s's<i> money.", i.describeTo(i, true), you.describeTo(i)); i.msg("<h>%s<i> lack permission to controll <h>%s's<i> money.", i.describeTo(i, true), you.describeTo(i));

View File

@ -15,7 +15,6 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.factions.zcore.util.TextUtil;
/** /**
* Permissions that you (a player) may or may not have in the territory of a certain faction. * Permissions that you (a player) may or may not have in the territory of a certain faction.
@ -23,12 +22,13 @@ import com.massivecraft.factions.zcore.util.TextUtil;
*/ */
public enum FPerm public enum FPerm
{ {
BUILD("build", "edit the terrain", Rel.MEMBER), BUILD("build", "edit the terrain", Rel.LEADER, Rel.OFFICER, Rel.MEMBER),
PAINBUILD("painbuild", "edit but take damage", Rel.ALLY), PAINBUILD("painbuild", "edit but take damage", Rel.ALLY),
DOOR("door", "use doors", Rel.MEMBER, Rel.ALLY), DOOR("door", "use doors", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY),
CONTAINER("container", "use containers", Rel.MEMBER), CONTAINER("container", "use containers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER),
BUTTON("button", "use stone buttons", Rel.MEMBER, Rel.ALLY), BUTTON("button", "use stone buttons", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY),
LEVER("lever", "use levers", Rel.MEMBER, Rel.ALLY), LEVER("lever", "use levers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY),
WITHDRAW("withdraw", "withdraw faction money", Rel.LEADER, Rel.OFFICER),
; ;
private final String nicename; private final String nicename;
@ -69,30 +69,44 @@ public enum FPerm
if (str.startsWith("c")) return CONTAINER; if (str.startsWith("c")) return CONTAINER;
if (str.startsWith("but")) return BUTTON; if (str.startsWith("but")) return BUTTON;
if (str.startsWith("l")) return LEVER; if (str.startsWith("l")) return LEVER;
if (str.startsWith("w")) return WITHDRAW;
return null; return null;
} }
public static String getStateHeaders()
{
String ret = "";
for (Rel rel : Rel.values())
{
ret += rel.getColor().toString();
ret += rel.toString().substring(0, 3);
ret += " ";
}
return ret;
}
public String getStateInfo(Set<Rel> value, boolean withDesc) public String getStateInfo(Set<Rel> value, boolean withDesc)
{ {
String ret = "<h>"+this.getNicename()+ " "; String ret = "";
List<String> rels = new ArrayList<String>(); for (Rel rel : Rel.values())
for (Rel rel : value)
{ {
rels.add("<p>"+rel); if (value.contains(rel))
} {
if (rels.size() > 0) ret += "<g>YES";
{ }
ret += TextUtil.implode(rels, "<c>+"); else
} {
else ret += "<b>NOO";
{ }
ret += "NOONE"; ret += " ";
} }
ret +="<h>"+this.getNicename();
if (withDesc) if (withDesc)
{ {
ret += " <i>" + this.getDescription(); ret += " <i>" + this.getDescription();
} }
return ret; return ret;
} }
@ -133,18 +147,26 @@ public enum FPerm
} }
private static final String errorpattern = "<b>%s<b> can't %s in the territory of %s<b>."; private static final String errorpattern = "<b>%s<b> can't %s in the territory of %s<b>.";
public boolean has(RelationParticipator testSubject, FLocation floc, boolean informIfNot) public boolean has(RelationParticipator testSubject, Faction hostFaction, boolean informIfNot)
{ {
Faction factionThere = Board.getFactionAt(floc);
Faction factionDoer = RelationUtil.getFaction(testSubject); Faction factionDoer = RelationUtil.getFaction(testSubject);
boolean ret = factionThere.getPermittedRelations(this).contains(factionThere.getRelationTo(factionDoer)); boolean ret = hostFaction.getPermittedRelations(this).contains(hostFaction.getRelationTo(factionDoer));
if (!ret && informIfNot && testSubject instanceof FPlayer) if (!ret && informIfNot && testSubject instanceof FPlayer)
{ {
FPlayer fplayer = (FPlayer)testSubject; FPlayer fplayer = (FPlayer)testSubject;
fplayer.msg(errorpattern, fplayer.describeTo(fplayer, true), this.getDescription(), factionThere.describeTo(fplayer)); fplayer.msg(errorpattern, fplayer.describeTo(fplayer, true), this.getDescription(), hostFaction.describeTo(fplayer));
} }
return ret; return ret;
} }
public boolean has(RelationParticipator testSubject, Faction hostFaction)
{
return this.has(testSubject, hostFaction, false);
}
public boolean has(RelationParticipator testSubject, FLocation floc, boolean informIfNot)
{
Faction factionThere = Board.getFactionAt(floc);
return this.has(testSubject, factionThere, informIfNot);
}
public boolean has(RelationParticipator testSubject, Location loc, boolean informIfNot) public boolean has(RelationParticipator testSubject, Location loc, boolean informIfNot)
{ {
FLocation floc = new FLocation(loc); FLocation floc = new FLocation(loc);

View File

@ -93,7 +93,7 @@ public enum Rel
public ChatColor getColor() public ChatColor getColor()
{ {
if (this == MEMBER) if (this.isAtLeast(MEMBER))
return Conf.colorMember; return Conf.colorMember;
else if (this == ALLY) else if (this == ALLY)
return Conf.colorAlly; return Conf.colorAlly;