2018-01-04 10:36:51 +01:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.P;
|
|
|
|
import com.massivecraft.factions.struct.Permission;
|
|
|
|
import com.massivecraft.factions.struct.Relation;
|
2018-02-06 04:46:53 +01:00
|
|
|
import com.massivecraft.factions.struct.Role;
|
2018-01-04 10:36:51 +01:00
|
|
|
import com.massivecraft.factions.zcore.fperms.Access;
|
2018-02-12 02:38:04 +01:00
|
|
|
import com.massivecraft.factions.zcore.fperms.Permissable;
|
2018-02-03 21:49:04 +01:00
|
|
|
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
2018-03-02 22:53:01 +01:00
|
|
|
import com.massivecraft.factions.zcore.fperms.gui.PermissableActionGUI;
|
|
|
|
import com.massivecraft.factions.zcore.fperms.gui.PermissableRelationGUI;
|
2018-01-04 10:36:51 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
|
|
|
|
2018-03-02 22:57:36 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
2018-01-05 08:16:24 +01:00
|
|
|
|
2018-01-04 10:36:51 +01:00
|
|
|
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;
|
2018-02-06 04:46:53 +01:00
|
|
|
this.disableOnLock = true;
|
2018-01-04 10:36:51 +01:00
|
|
|
|
|
|
|
senderMustBePlayer = true;
|
|
|
|
senderMustBeMember = true;
|
|
|
|
senderMustBeModerator = false;
|
2018-03-06 20:46:55 +01:00
|
|
|
senderMustBeAdmin = true;
|
2018-01-04 10:36:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform() {
|
2018-02-06 04:46:53 +01:00
|
|
|
if (args.size() == 0) {
|
2018-03-03 04:07:34 +01:00
|
|
|
PermissableRelationGUI gui = new PermissableRelationGUI(fme);
|
|
|
|
gui.build();
|
|
|
|
|
|
|
|
me.openInventory(gui.getInventory());
|
2018-03-02 22:53:01 +01:00
|
|
|
return;
|
|
|
|
} else if (args.size() == 1 && getPermissable(argAsString(0)) != null) {
|
2018-03-03 04:07:34 +01:00
|
|
|
PermissableActionGUI gui = new PermissableActionGUI(fme, getPermissable(argAsString(0)));
|
|
|
|
gui.build();
|
|
|
|
|
|
|
|
me.openInventory(gui.getInventory());
|
2018-01-04 10:36:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If not opening GUI, then setting the permission manually.
|
|
|
|
if (args.size() != 3) {
|
|
|
|
fme.msg(TL.COMMAND_PERM_DESCRIPTION);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-12 02:38:04 +01:00
|
|
|
Set<Permissable> permissables = 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) {
|
2018-02-12 02:38:04 +01:00
|
|
|
permissables.addAll(myFaction.getPermissions().keySet());
|
2018-01-05 08:16:24 +01:00
|
|
|
} else {
|
2018-02-12 02:38:04 +01:00
|
|
|
Permissable permissable = getPermissable(argAsString(0));
|
|
|
|
|
|
|
|
if (permissable == null) {
|
2018-01-05 08:16:24 +01:00
|
|
|
fme.msg(TL.COMMAND_PERM_INVALID_RELATION);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-12 02:38:04 +01:00
|
|
|
permissables.add(permissable);
|
2018-01-04 10:36:51 +01:00
|
|
|
}
|
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-04 10:36:51 +01:00
|
|
|
}
|
2018-01-05 08:16:24 +01:00
|
|
|
|
|
|
|
Access access = Access.fromString(argAsString(2));
|
|
|
|
|
2018-01-04 10:36:51 +01:00
|
|
|
if (access == null) {
|
|
|
|
fme.msg(TL.COMMAND_PERM_INVALID_ACCESS);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-12 02:38:04 +01:00
|
|
|
for (Permissable permissable : permissables) {
|
2018-02-03 21:49:04 +01:00
|
|
|
for (PermissableAction permissableAction : permissableActions) {
|
2018-02-12 02:38:04 +01:00
|
|
|
fme.getFaction().setPermission(permissable, 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());
|
2018-01-04 10:36:51 +01:00
|
|
|
}
|
2018-02-12 02:38:04 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2018-01-04 10:36:51 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_PERM_DESCRIPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|