From a034030ba51a5b1afcfa2d1eebf74907f5db1f7d Mon Sep 17 00:00:00 2001 From: Trent Hensler Date: Sun, 11 Feb 2018 17:38:04 -0800 Subject: [PATCH] Fix setting perms. Annoyingly setting them to und by default now --- .../massivecraft/factions/cmd/CmdPerm.java | 29 ++++++++++++++----- .../factions/zcore/persist/MemoryFaction.java | 4 +++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java index 4ba08d2b..6874f262 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java @@ -5,6 +5,7 @@ import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.fperms.Access; +import com.massivecraft.factions.zcore.fperms.Permissable; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; @@ -47,22 +48,23 @@ public class CmdPerm extends FCommand { return; } - Set relations = new HashSet<>(); + Set permissables = new HashSet<>(); Set permissableActions = new HashSet<>(); boolean allRelations = argAsString(0).equalsIgnoreCase("all"); boolean allActions = argAsString(1).equalsIgnoreCase("all"); if (allRelations) { - relations.addAll(Arrays.asList(Relation.values())); + permissables.addAll(myFaction.getPermissions().keySet()); } else { - Relation relation = Relation.fromString(argAsString(0)); - if (relation == null) { + Permissable permissable = getPermissable(argAsString(0)); + + if (permissable == null) { fme.msg(TL.COMMAND_PERM_INVALID_RELATION); return; } - relations.add(relation); + permissables.add(permissable); } if (allActions) { @@ -84,9 +86,9 @@ public class CmdPerm extends FCommand { return; } - for (Relation relation : relations) { + for (Permissable permissable : permissables) { for (PermissableAction permissableAction : permissableActions) { - fme.getFaction().setPermission(relation, permissableAction, access); + fme.getFaction().setPermission(permissable, permissableAction, access); } } @@ -94,6 +96,19 @@ public class CmdPerm extends FCommand { P.p.log(String.format(TL.COMMAND_PERM_SET.toString(), argAsString(1), access.name(), argAsString(0)) + " for faction " + fme.getTag()); } + private Permissable getPermissable(String name) { + try { + return Relation.valueOf(name.toUpperCase()); + } catch (Exception e) { + } + try { + return Role.valueOf(name.toUpperCase()); + } catch (Exception e) { + } + + return null; + } + private List getLines() { List lines = new ArrayList<>(); diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java index dcbfdcc2..7993dcfa 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -366,6 +366,10 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { return Access.UNDEFINED; } + public Map> getAccessMap() { + return Collections.unmodifiableMap(permissions); + } + public void setPermission(Permissable permissable, PermissableAction permissableAction, Access access) { Map accessMap = permissions.get(permissable); if (accessMap == null) {