From 5f437b186279800e4b2a42843ed75ecaa6c3575d Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 24 Oct 2011 11:56:41 +0200 Subject: [PATCH] Changed permission view. Bank withdraw permission in the works --- src/com/massivecraft/factions/Conf.java | 2 +- src/com/massivecraft/factions/Faction.java | 7 -- src/com/massivecraft/factions/Factions.java | 28 ++++---- .../massivecraft/factions/cmd/CmdFlag.java | 6 +- .../massivecraft/factions/cmd/CmdPerm.java | 9 ++- .../factions/integration/Econ.java | 6 +- .../massivecraft/factions/struct/FPerm.java | 68 ++++++++++++------- src/com/massivecraft/factions/struct/Rel.java | 2 +- 8 files changed, 72 insertions(+), 56 deletions(-) diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index 62709b95..730b2b11 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -187,7 +187,7 @@ public class Conf //Faction banks, to pay for land claiming and other costs instead of individuals paying for them 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 bankFactionPaysLandCosts = true; //The faction pays for land claiming costs. diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index 6247aa54..f93b77da 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -46,13 +46,6 @@ public class Faction extends Entity implements EconomyParticipator } 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) { if (Conf.factionTagForceUpperCase) diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 04accb9f..d5eee1f9 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -113,11 +113,11 @@ public class Factions extends EntityCollection faction.setFlag(FFlag.LIGHTNING, true); faction.setFlag(FFlag.ENDERGRIEF, true); - faction.setPermittedRelations(FPerm.BUILD, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); - faction.setPermittedRelations(FPerm.DOOR, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); - faction.setPermittedRelations(FPerm.CONTAINER, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); - faction.setPermittedRelations(FPerm.BUTTON, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); - faction.setPermittedRelations(FPerm.LEVER, 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.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); } public void setFlagsForSafeZone(Faction faction) @@ -134,11 +134,10 @@ public class Factions extends EntityCollection faction.setFlag(FFlag.LIGHTNING, false); faction.setFlag(FFlag.ENDERGRIEF, false); - faction.setPermittedRelations(FPerm.BUILD, Rel.ALLY, Rel.MEMBER); - faction.setPermittedRelations(FPerm.DOOR, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); - faction.setPermittedRelations(FPerm.CONTAINER, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); - faction.setPermittedRelations(FPerm.BUTTON, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); - faction.setPermittedRelations(FPerm.LEVER, 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.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); } public void setFlagsForWarZone(Faction faction) @@ -155,11 +154,10 @@ public class Factions extends EntityCollection faction.setFlag(FFlag.LIGHTNING, true); faction.setFlag(FFlag.ENDERGRIEF, true); - faction.setPermittedRelations(FPerm.BUILD, Rel.ALLY, Rel.MEMBER); - faction.setPermittedRelations(FPerm.DOOR, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); - faction.setPermittedRelations(FPerm.CONTAINER, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); - faction.setPermittedRelations(FPerm.BUTTON, Rel.ENEMY, Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.MEMBER); - faction.setPermittedRelations(FPerm.LEVER, 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.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); } diff --git a/src/com/massivecraft/factions/cmd/CmdFlag.java b/src/com/massivecraft/factions/cmd/CmdFlag.java index 77d1d121..7c73c9db 100644 --- a/src/com/massivecraft/factions/cmd/CmdFlag.java +++ b/src/com/massivecraft/factions/cmd/CmdFlag.java @@ -39,7 +39,7 @@ public class CmdFlag extends FCommand 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()) { msg(flag.getStateInfo(faction.getFlag(flag), true)); @@ -51,7 +51,7 @@ public class CmdFlag extends FCommand if (flag == null) return; 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)); return; } @@ -81,7 +81,7 @@ public class CmdFlag extends FCommand } // 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); msg(flag.getStateInfo(faction.getFlag(flag), true)); } diff --git a/src/com/massivecraft/factions/cmd/CmdPerm.java b/src/com/massivecraft/factions/cmd/CmdPerm.java index e963eb05..106d53ca 100644 --- a/src/com/massivecraft/factions/cmd/CmdPerm.java +++ b/src/com/massivecraft/factions/cmd/CmdPerm.java @@ -44,7 +44,8 @@ public class CmdPerm extends FCommand 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()) { msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); @@ -56,7 +57,8 @@ public class CmdPerm extends FCommand if (perm == null) return; 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)); return; } @@ -81,7 +83,8 @@ public class CmdPerm extends FCommand // Do the change 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)); } diff --git a/src/com/massivecraft/factions/integration/Econ.java b/src/com/massivecraft/factions/integration/Econ.java index 9f640bfe..8e5d666b 100644 --- a/src/com/massivecraft/factions/integration/Econ.java +++ b/src/com/massivecraft/factions/integration/Econ.java @@ -16,8 +16,8 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.P; import com.massivecraft.factions.iface.EconomyParticipator; +import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.util.RelationUtil; public class Econ @@ -106,8 +106,8 @@ public class Econ // Ohh by the way... Yes it could. For daily rent to the faction. if (i == fI && fI == fYou) return true; - // Factions can be controlled by members that are moderators... or any member if any member can withdraw. - if (you instanceof Faction && fI == fYou && (Conf.bankMembersCanWithdraw || ((FPlayer)i).getRole().isAtLeast(Rel.OFFICER))) return true; + // Factions can be controlled by those that have permissions + if (you instanceof Faction && FPerm.WITHDRAW.has(i, fYou)) return true; // Otherwise you may not! ;,,; i.msg("%s lack permission to controll %s's money.", i.describeTo(i, true), you.describeTo(i)); diff --git a/src/com/massivecraft/factions/struct/FPerm.java b/src/com/massivecraft/factions/struct/FPerm.java index 6668623b..ce13b6f4 100644 --- a/src/com/massivecraft/factions/struct/FPerm.java +++ b/src/com/massivecraft/factions/struct/FPerm.java @@ -15,7 +15,6 @@ import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.iface.RelationParticipator; 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. @@ -23,12 +22,13 @@ import com.massivecraft.factions.zcore.util.TextUtil; */ 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), - DOOR("door", "use doors", Rel.MEMBER, Rel.ALLY), - CONTAINER("container", "use containers", Rel.MEMBER), - BUTTON("button", "use stone buttons", Rel.MEMBER, Rel.ALLY), - LEVER("lever", "use levers", Rel.MEMBER, Rel.ALLY), + DOOR("door", "use doors", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY), + CONTAINER("container", "use containers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER), + BUTTON("button", "use stone buttons", Rel.LEADER, Rel.OFFICER, 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; @@ -69,30 +69,44 @@ public enum FPerm if (str.startsWith("c")) return CONTAINER; if (str.startsWith("but")) return BUTTON; if (str.startsWith("l")) return LEVER; + if (str.startsWith("w")) return WITHDRAW; 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 value, boolean withDesc) { - String ret = ""+this.getNicename()+ " "; + String ret = ""; - List rels = new ArrayList(); - for (Rel rel : value) + for (Rel rel : Rel.values()) { - rels.add("

"+rel); - } - if (rels.size() > 0) - { - ret += TextUtil.implode(rels, "+"); - } - else - { - ret += "NOONE"; + if (value.contains(rel)) + { + ret += "YES"; + } + else + { + ret += "NOO"; + } + ret += " "; } + ret +=""+this.getNicename(); if (withDesc) { - ret += " " + this.getDescription(); + ret += " " + this.getDescription(); } return ret; } @@ -133,18 +147,26 @@ public enum FPerm } private static final String errorpattern = "%s can't %s in the territory of %s."; - 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); - boolean ret = factionThere.getPermittedRelations(this).contains(factionThere.getRelationTo(factionDoer)); + boolean ret = hostFaction.getPermittedRelations(this).contains(hostFaction.getRelationTo(factionDoer)); if (!ret && informIfNot && testSubject instanceof FPlayer) { 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; } + 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) { FLocation floc = new FLocation(loc); diff --git a/src/com/massivecraft/factions/struct/Rel.java b/src/com/massivecraft/factions/struct/Rel.java index 7ca7f460..91030a31 100644 --- a/src/com/massivecraft/factions/struct/Rel.java +++ b/src/com/massivecraft/factions/struct/Rel.java @@ -93,7 +93,7 @@ public enum Rel public ChatColor getColor() { - if (this == MEMBER) + if (this.isAtLeast(MEMBER)) return Conf.colorMember; else if (this == ALLY) return Conf.colorAlly;