From 79410d91f18e531197bec2ce7ca45570b5817603 Mon Sep 17 00:00:00 2001 From: Trent Hensler Date: Mon, 5 Feb 2018 20:46:53 -0700 Subject: [PATCH] Command to view your permissions --- .../com/massivecraft/factions/Faction.java | 2 + .../massivecraft/factions/cmd/CmdPerm.java | 44 ++++++++++++++++--- .../factions/zcore/fperms/Access.java | 18 ++++++-- .../factions/zcore/persist/MemoryFaction.java | 8 ++++ .../massivecraft/factions/zcore/util/TL.java | 3 +- 5 files changed, 65 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index 8db62774..d10c6fd0 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -147,6 +147,8 @@ public interface Faction extends EconomyParticipator { public void resetPerms(); + public Map> getPermissions(); + // ------------------------------- // Relation and relation colors // ------------------------------- diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java index ecb5a4e4..cb450fd5 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java @@ -1,15 +1,16 @@ package com.massivecraft.factions.cmd; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.Factions; import com.massivecraft.factions.P; 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.PermissableAction; import com.massivecraft.factions.zcore.util.TL; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; +import java.util.*; public class CmdPerm extends FCommand { @@ -25,7 +26,7 @@ public class CmdPerm extends FCommand { this.optionalArgs.put("access", "access"); this.permission = Permission.PERMISSIONS.node; - this.disableOnLock = false; + this.disableOnLock = true; senderMustBePlayer = true; senderMustBeMember = true; @@ -35,8 +36,10 @@ public class CmdPerm extends FCommand { @Override public void perform() { - if (optionalArgs.size() == 0) { - // TODO: Open the GUI. + if (args.size() == 0) { + for (String s : getLines()) { + msg(s); + } return; } @@ -93,6 +96,35 @@ 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 List getLines() { + List lines = new ArrayList<>(); + + lines.add(TL.COMMAND_PERM_TOP.toString()); + + for (PermissableAction action : PermissableAction.values()) { + StringBuilder sb = new StringBuilder(); + sb.append(action.getName()).append(" "); + + // Roles except admin + for (Role role : Role.values()) { + if (role != Role.ADMIN) { + sb.append(myFaction.getAccess(role, action).getName()).append(" "); + } + } + + // Relations except Member + for (Relation relation : Relation.values()) { + if (relation != Relation.MEMBER) { + sb.append(myFaction.getAccess(relation, action).getName()).append(" "); + } + } + + lines.add(sb.toString().trim()); + } + + return lines; + } + @Override public TL getUsageTranslation() { return TL.COMMAND_PERM_DESCRIPTION; diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/Access.java b/src/main/java/com/massivecraft/factions/zcore/fperms/Access.java index 8c1d38ab..62e5b652 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/Access.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/Access.java @@ -1,9 +1,17 @@ package com.massivecraft.factions.zcore.fperms; +import org.bukkit.ChatColor; + public enum Access { - ALLOW, - DENY, - UNDEFINED; + ALLOW("&aALLOW"), + DENY("&4DENY"), + UNDEFINED("&7UND"); + + private String name; + + Access(String name) { + this.name = name; + } /** * Case insensitive check for access. @@ -21,6 +29,10 @@ public enum Access { return null; } + public String getName() { + return ChatColor.translateAlternateColorCodes('&', this.name); + } + @Override public String toString() { 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 63070825..17fe61c3 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -399,6 +399,14 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { } } + /** + * Read only map of Permissions. + * @return + */ + public Map> getPermissions() { + return Collections.unmodifiableMap(permissions); + } + public Role getDefaultRole() { return this.defaultRole; } diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index 1ffe18a0..05cc9178 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -364,11 +364,12 @@ public enum TL { COMMAND_PEACEFUL_GRANT("granted peaceful status to"), COMMAND_PEACEFUL_REVOKE("removed peaceful status from"), - COMMAND_PERM_DESCRIPTION("Edit or list your Faction's permissions."), + COMMAND_PERM_DESCRIPTION("&6Edit or list your Faction's permissions."), COMMAND_PERM_INVALID_RELATION("Invalid relation defined. Try something like 'ally'"), COMMAND_PERM_INVALID_ACCESS("Invalid access defined. Try something like 'allow'"), COMMAND_PERM_INVALID_ACTION("Invalid action defined. Try something like 'build'"), COMMAND_PERM_SET("Set permission %1$s to %2$s for relation %3$s"), + COMMAND_PERM_TOP("RCT MEM OFF ALLY TRUCE NEUT ENEMY"), COMMAND_PERMANENT_DESCRIPTION("Toggles a faction's permanence"), //TODO: Real word? COMMAND_PERMANENT_GRANT("added permanent status to"),