Saber-Factions/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java

102 lines
3.1 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.zcore.fperms.Access;
2018-02-03 21:49:04 +01:00
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
2018-01-05 08:16:24 +01:00
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class CmdPerm extends FCommand {
public CmdPerm() {
super();
this.aliases.add("perm");
this.aliases.add("perms");
this.aliases.add("permission");
this.aliases.add("permissions");
this.optionalArgs.put("relation", "relation");
this.optionalArgs.put("action", "action");
this.optionalArgs.put("access", "access");
2018-01-05 08:01:52 +01:00
this.permission = Permission.PERMISSIONS.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
if (optionalArgs.size() == 0) {
// TODO: Open the GUI.
return;
}
// If not opening GUI, then setting the permission manually.
if (args.size() != 3) {
fme.msg(TL.COMMAND_PERM_DESCRIPTION);
return;
}
2018-01-05 08:16:24 +01:00
Set<Relation> relations = new HashSet<>();
2018-02-03 21:49:04 +01:00
Set<PermissableAction> permissableActions = new HashSet<>();
2018-01-05 08:16:24 +01:00
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);
}
2018-01-05 08:16:24 +01:00
if (allActions) {
2018-02-03 21:49:04 +01:00
permissableActions.addAll(Arrays.asList(PermissableAction.values()));
2018-01-05 08:16:24 +01:00
} else {
2018-02-03 21:49:04 +01:00
PermissableAction permissableAction = PermissableAction.fromString(argAsString(1));
if (permissableAction == null) {
2018-01-05 08:16:24 +01:00
fme.msg(TL.COMMAND_PERM_INVALID_ACTION);
return;
}
2018-02-03 21:49:04 +01:00
permissableActions.add(permissableAction);
}
2018-01-05 08:16:24 +01:00
Access access = Access.fromString(argAsString(2));
if (access == null) {
fme.msg(TL.COMMAND_PERM_INVALID_ACCESS);
return;
}
2018-01-05 08:16:24 +01:00
for (Relation relation : relations) {
2018-02-03 21:49:04 +01:00
for (PermissableAction permissableAction : permissableActions) {
fme.getFaction().setPermission(relation, permissableAction, access);
2018-01-05 08:16:24 +01:00
}
}
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
public TL getUsageTranslation() {
return TL.COMMAND_PERM_DESCRIPTION;
}
}