From 5988e8e5af9d093eef0291404f651154ffc13086 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 9 May 2012 06:29:52 +0200 Subject: [PATCH] Simplified the perm command. --- src/com/massivecraft/factions/Faction.java | 16 ++++++++ .../massivecraft/factions/cmd/CmdFlag.java | 2 +- .../massivecraft/factions/cmd/CmdPerm.java | 19 +++++----- .../massivecraft/factions/cmd/FCommand.java | 33 +++++++++++++++++ .../massivecraft/factions/struct/FPerm.java | 37 ------------------- .../massivecraft/factions/zcore/MCommand.java | 2 +- 6 files changed, 61 insertions(+), 48 deletions(-) diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index d31cd30c..bd75514f 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -136,6 +136,7 @@ public class Faction extends Entity implements EconomyParticipator return ret; } + /* public void addPermittedRelation(FPerm perm, Rel rel) { Set newPermittedRelations = EnumSet.noneOf(Rel.class); @@ -150,6 +151,21 @@ public class Faction extends Entity implements EconomyParticipator newPermittedRelations.addAll(this.getPermittedRelations(perm)); newPermittedRelations.remove(rel); this.setPermittedRelations(perm, newPermittedRelations); + }*/ + + public void setRelationPermitted(FPerm perm, Rel rel, boolean permitted) + { + Set newPermittedRelations = EnumSet.noneOf(Rel.class); + newPermittedRelations.addAll(this.getPermittedRelations(perm)); + if (permitted) + { + newPermittedRelations.add(rel); + } + else + { + newPermittedRelations.remove(rel); + } + this.setPermittedRelations(perm, newPermittedRelations); } public void setPermittedRelations(FPerm perm, Set rels) diff --git a/src/com/massivecraft/factions/cmd/CmdFlag.java b/src/com/massivecraft/factions/cmd/CmdFlag.java index ff8b2d47..33a65b91 100644 --- a/src/com/massivecraft/factions/cmd/CmdFlag.java +++ b/src/com/massivecraft/factions/cmd/CmdFlag.java @@ -15,7 +15,7 @@ public class CmdFlag extends FCommand //this.requiredArgs.add(""); this.optionalArgs.put("faction", "your"); this.optionalArgs.put("flag", "all"); - this.optionalArgs.put("on/off", "read"); + this.optionalArgs.put("yes/no", "read"); this.permission = Permission.FLAG.node; this.disableOnLock = true; diff --git a/src/com/massivecraft/factions/cmd/CmdPerm.java b/src/com/massivecraft/factions/cmd/CmdPerm.java index 52931a08..387a247f 100644 --- a/src/com/massivecraft/factions/cmd/CmdPerm.java +++ b/src/com/massivecraft/factions/cmd/CmdPerm.java @@ -1,12 +1,9 @@ package com.massivecraft.factions.cmd; -import java.util.Set; - import com.massivecraft.factions.Faction; import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Rel; -import com.massivecraft.factions.zcore.util.TextUtil; public class CmdPerm extends FCommand { @@ -16,10 +13,10 @@ public class CmdPerm extends FCommand super(); this.aliases.add("perm"); - //this.requiredArgs.add(""); this.optionalArgs.put("faction", "your"); this.optionalArgs.put("perm", "all"); - this.optionalArgs.put("relationdelta", "read"); + this.optionalArgs.put("relation", "read"); + this.optionalArgs.put("yes/no", "read"); this.permission = Permission.PERM.node; this.disableOnLock = true; @@ -66,17 +63,21 @@ public class CmdPerm extends FCommand // Do the sender have the right to change perms for this faction? if ( ! FPerm.PERMS.has(sender, faction, true)) return; + Rel rel = this.argAsRel(2); + if (rel == null) return; + + Boolean val = this.argAsBool(3, null); + if (val == null) return; + // Do the change - Set targetValue = FPerm.parseRelDeltas(TextUtil.implode(args.subList(2, args.size()), " "), faction.getPermittedRelations(perm)); + faction.setRelationPermitted(perm, rel, val); // The following is to make sure the leader always has the right to change perms if that is our goal. if (perm == FPerm.PERMS && FPerm.PERMS.getDefault().contains(Rel.LEADER)) { - targetValue.add(Rel.LEADER); + faction.setRelationPermitted(FPerm.PERMS, Rel.LEADER, true); } - faction.setPermittedRelations(perm, targetValue); - 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/cmd/FCommand.java b/src/com/massivecraft/factions/cmd/FCommand.java index faa099e2..ddc5e77e 100644 --- a/src/com/massivecraft/factions/cmd/FCommand.java +++ b/src/com/massivecraft/factions/cmd/FCommand.java @@ -343,6 +343,39 @@ public abstract class FCommand extends MCommand

return this.argAsFactionPerm(idx, null); } + // FACTION REL ====================== + public Rel strAsRel(String name, Rel def, boolean msg) + { + Rel ret = def; + + if (name != null) + { + Rel perm = Rel.parse(name); + if (perm != null) + { + ret = perm; + } + } + + if (msg && ret == null) + { + this.msg("The role \"

%s\" could not be found.", name); + } + + return ret; + } + public Rel argAsRel(int idx, Rel def, boolean msg) + { + return this.strAsRel(this.argAsString(idx), def, msg); + } + public Rel argAsRel(int idx, Rel def) + { + return this.argAsRel(idx, def, true); + } + public Rel argAsRel(int idx) + { + return this.argAsRel(idx, null); + } // -------------------------------------------- // // Commonly used logic diff --git a/src/com/massivecraft/factions/struct/FPerm.java b/src/com/massivecraft/factions/struct/FPerm.java index af3d993b..88504182 100644 --- a/src/com/massivecraft/factions/struct/FPerm.java +++ b/src/com/massivecraft/factions/struct/FPerm.java @@ -1,9 +1,7 @@ package com.massivecraft.factions.struct; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; -import java.util.List; import java.util.Set; import org.bukkit.Location; @@ -128,41 +126,6 @@ public enum FPerm return ret; } - public static Set parseRelDeltas(String str, Set current) - { - Set ret = new HashSet(); - ret.addAll(current); - - List nodes = new ArrayList(Arrays.asList(str.split("\\s+"))); - - for (String node : nodes) - { - boolean add = true; - if (node.startsWith("-")) - { - add = false; - node = node.substring(1); - } - else if (node.startsWith("+")) - { - node = node.substring(1); - } - Rel rel = Rel.parse(node); - - if (rel == null) continue; - - if (add) - { - ret.add(rel); - } - else - { - ret.remove(rel); - } - } - return ret; - } - private static final String errorpattern = "%s does not allow you to %s."; public boolean has(Object testSubject, Faction hostFaction, boolean informIfNot) { diff --git a/src/com/massivecraft/factions/zcore/MCommand.java b/src/com/massivecraft/factions/zcore/MCommand.java index 905b936d..0ef80fb6 100644 --- a/src/com/massivecraft/factions/zcore/MCommand.java +++ b/src/com/massivecraft/factions/zcore/MCommand.java @@ -388,7 +388,7 @@ public abstract class MCommand } return false; } - public Boolean argAsBool(int idx, boolean def) + public Boolean argAsBool(int idx, Boolean def) { String str = this.argAsString(idx); if (str == null) return def;