Command to view your permissions
This commit is contained in:
parent
41bdc25441
commit
79410d91f1
@ -147,6 +147,8 @@ public interface Faction extends EconomyParticipator {
|
||||
|
||||
public void resetPerms();
|
||||
|
||||
public Map<Permissable, Map<PermissableAction, Access>> getPermissions();
|
||||
|
||||
// -------------------------------
|
||||
// Relation and relation colors
|
||||
// -------------------------------
|
||||
|
@ -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<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
|
||||
public TL getUsageTranslation() {
|
||||
return TL.COMMAND_PERM_DESCRIPTION;
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
return this.defaultRole;
|
||||
}
|
||||
|
@ -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"),
|
||||
|
Loading…
Reference in New Issue
Block a user