From 79d4a885f85829439ce20f1aa3a74ee83a5b4a30 Mon Sep 17 00:00:00 2001 From: Trent Hensler Date: Thu, 4 Jan 2018 23:16:24 -0800 Subject: [PATCH] Allow bulk setting of permissions --- .../massivecraft/factions/cmd/CmdPerm.java | 56 ++++++++++++++----- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java index dba70d75..f223dd47 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java @@ -7,6 +7,10 @@ import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Action; import com.massivecraft.factions.zcore.util.TL; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + public class CmdPerm extends FCommand { public CmdPerm() { @@ -42,25 +46,51 @@ public class CmdPerm extends FCommand { return; } - Relation relation = Relation.fromString(argAsString(0)); - Action action = Action.fromString(argAsString(1)); + Set relations = new HashSet<>(); + Set actions = new HashSet<>(); + + boolean allRelations = argAsString(0).equalsIgnoreCase("all"); + boolean allActions = argAsString(1).equalsIgnoreCase("all"); + + if (allRelations) { + relations.addAll(Arrays.asList(Relation.values())); + } else { + Relation relation = Relation.fromString(argAsString(0)); + if (relation == null) { + fme.msg(TL.COMMAND_PERM_INVALID_RELATION); + return; + } + + relations.add(relation); + } + + if (allActions) { + actions.addAll(Arrays.asList(Action.values())); + } else { + Action action = Action.fromString(argAsString(1)); + if (action == null) { + fme.msg(TL.COMMAND_PERM_INVALID_ACTION); + return; + } + + actions.add(action); + } + Access access = Access.fromString(argAsString(2)); - if (relation == null) { - fme.msg(TL.COMMAND_PERM_INVALID_RELATION); - return; - } - if (action == null) { - fme.msg(TL.COMMAND_PERM_INVALID_ACTION); - return; - } + if (access == null) { fme.msg(TL.COMMAND_PERM_INVALID_ACCESS); return; } - fme.getFaction().setPermission(relation, action, access); - fme.msg(TL.COMMAND_PERM_SET, action.getName(), relation.nicename, access.name()); - P.p.log(String.format(TL.COMMAND_PERM_SET.toString(), action.getName(), relation.nicename, access.name()) + " for faction " + fme.getTag()); + for (Relation relation : relations) { + for (Action action : actions) { + fme.getFaction().setPermission(relation, action, access); + } + } + + fme.msg(TL.COMMAND_PERM_SET, argAsString(1), access.name(), argAsString(0)); + P.p.log(String.format(TL.COMMAND_PERM_SET.toString(), argAsString(1), access.name(), argAsString(0)) + " for faction " + fme.getTag()); } @Override