Command to view your permissions

This commit is contained in:
Trent Hensler 2018-02-05 20:46:53 -07:00
parent 41bdc25441
commit 79410d91f1
5 changed files with 65 additions and 10 deletions

View File

@ -147,6 +147,8 @@ public interface Faction extends EconomyParticipator {
public void resetPerms(); public void resetPerms();
public Map<Permissable, Map<PermissableAction, Access>> getPermissions();
// ------------------------------- // -------------------------------
// Relation and relation colors // Relation and relation colors
// ------------------------------- // -------------------------------

View File

@ -1,15 +1,16 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation; 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.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import java.util.Arrays; import java.util.*;
import java.util.HashSet;
import java.util.Set;
public class CmdPerm extends FCommand { public class CmdPerm extends FCommand {
@ -25,7 +26,7 @@ public class CmdPerm extends FCommand {
this.optionalArgs.put("access", "access"); this.optionalArgs.put("access", "access");
this.permission = Permission.PERMISSIONS.node; this.permission = Permission.PERMISSIONS.node;
this.disableOnLock = false; this.disableOnLock = true;
senderMustBePlayer = true; senderMustBePlayer = true;
senderMustBeMember = true; senderMustBeMember = true;
@ -35,8 +36,10 @@ public class CmdPerm extends FCommand {
@Override @Override
public void perform() { public void perform() {
if (optionalArgs.size() == 0) { if (args.size() == 0) {
// TODO: Open the GUI. for (String s : getLines()) {
msg(s);
}
return; 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()); P.p.log(String.format(TL.COMMAND_PERM_SET.toString(), argAsString(1), access.name(), argAsString(0)) + " for faction " + fme.getTag());
} }
private List<String> getLines() {
List<String> 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 @Override
public TL getUsageTranslation() { public TL getUsageTranslation() {
return TL.COMMAND_PERM_DESCRIPTION; return TL.COMMAND_PERM_DESCRIPTION;

View File

@ -1,9 +1,17 @@
package com.massivecraft.factions.zcore.fperms; package com.massivecraft.factions.zcore.fperms;
import org.bukkit.ChatColor;
public enum Access { public enum Access {
ALLOW, ALLOW("&aALLOW"),
DENY, DENY("&4DENY"),
UNDEFINED; UNDEFINED("&7UND");
private String name;
Access(String name) {
this.name = name;
}
/** /**
* Case insensitive check for access. * Case insensitive check for access.
@ -21,6 +29,10 @@ public enum Access {
return null; return null;
} }
public String getName() {
return ChatColor.translateAlternateColorCodes('&', this.name);
}
@Override @Override
public String toString() { public String toString() {

View File

@ -399,6 +399,14 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
} }
} }
/**
* Read only map of Permissions.
* @return
*/
public Map<Permissable, Map<PermissableAction, Access>> getPermissions() {
return Collections.unmodifiableMap(permissions);
}
public Role getDefaultRole() { public Role getDefaultRole() {
return this.defaultRole; return this.defaultRole;
} }

View File

@ -364,11 +364,12 @@ public enum TL {
COMMAND_PEACEFUL_GRANT("granted peaceful status to"), COMMAND_PEACEFUL_GRANT("granted peaceful status to"),
COMMAND_PEACEFUL_REVOKE("removed peaceful status from"), 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_RELATION("Invalid relation defined. Try something like 'ally'"),
COMMAND_PERM_INVALID_ACCESS("Invalid access defined. Try something like 'allow'"), COMMAND_PERM_INVALID_ACCESS("Invalid access defined. Try something like 'allow'"),
COMMAND_PERM_INVALID_ACTION("Invalid action defined. Try something like 'build'"), 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_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_DESCRIPTION("Toggles a faction's permanence"), //TODO: Real word?
COMMAND_PERMANENT_GRANT("added permanent status to"), COMMAND_PERMANENT_GRANT("added permanent status to"),