2018-01-04 10:36:51 +01:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
2019-08-02 23:01:33 +02:00
|
|
|
import com.massivecraft.factions.P;
|
2018-01-04 10:36:51 +01:00
|
|
|
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;
|
2019-08-05 14:05:22 +02:00
|
|
|
import com.massivecraft.factions.zcore.fperms.gui.PermissableActionFrame;
|
|
|
|
import com.massivecraft.factions.zcore.fperms.gui.PermissableRelationFrame;
|
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 {
|
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
|
|
this.disableOnLock = true;
|
|
|
|
|
|
|
|
senderMustBePlayer = true;
|
|
|
|
senderMustBeMember = true;
|
|
|
|
senderMustBeModerator = false;
|
|
|
|
senderMustBeColeader = false;
|
|
|
|
senderMustBeAdmin = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform() {
|
|
|
|
if (args.size() == 0) {
|
2019-08-05 14:05:22 +02:00
|
|
|
new PermissableRelationFrame(fme.getFaction()).buildGUI(fme);
|
2019-03-03 04:51:21 +01:00
|
|
|
return;
|
|
|
|
} else if (args.size() == 1 && getPermissable(argAsString(0)) != null) {
|
2019-08-05 14:05:22 +02:00
|
|
|
new PermissableActionFrame(fme.getFaction()).buildGUI(fme, getPermissable(argAsString(0)));
|
2019-03-03 04:51:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If not opening GUI, then setting the permission manually.
|
|
|
|
if (args.size() != 3) {
|
|
|
|
fme.msg(TL.COMMAND_PERM_DESCRIPTION);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Set<Permissable> permissables = new HashSet<>();
|
|
|
|
Set<PermissableAction> permissableActions = new HashSet<>();
|
|
|
|
|
|
|
|
boolean allRelations = argAsString(0).equalsIgnoreCase("all");
|
|
|
|
boolean allActions = argAsString(1).equalsIgnoreCase("all");
|
|
|
|
|
|
|
|
if (allRelations) {
|
|
|
|
permissables.addAll(myFaction.getPermissions().keySet());
|
|
|
|
} else {
|
|
|
|
Permissable permissable = getPermissable(argAsString(0));
|
|
|
|
|
|
|
|
if (permissable == null) {
|
|
|
|
fme.msg(TL.COMMAND_PERM_INVALID_RELATION);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
permissables.add(permissable);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allActions) {
|
|
|
|
permissableActions.addAll(Arrays.asList(PermissableAction.values()));
|
|
|
|
} else {
|
|
|
|
PermissableAction permissableAction = PermissableAction.fromString(argAsString(1));
|
|
|
|
if (permissableAction == null) {
|
|
|
|
fme.msg(TL.COMMAND_PERM_INVALID_ACTION);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
permissableActions.add(permissableAction);
|
|
|
|
}
|
|
|
|
|
|
|
|
Access access = Access.fromString(argAsString(2));
|
|
|
|
|
|
|
|
if (access == null) {
|
|
|
|
fme.msg(TL.COMMAND_PERM_INVALID_ACCESS);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Permissable permissable : permissables) {
|
|
|
|
for (PermissableAction permissableAction : permissableActions) {
|
|
|
|
fme.getFaction().setPermission(permissable, permissableAction, access);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fme.msg(TL.COMMAND_PERM_SET, argAsString(1), access.name(), argAsString(0));
|
2019-08-02 23:01:33 +02:00
|
|
|
P.p.log(String.format(TL.COMMAND_PERM_SET.toString(), argAsString(1), access.name(), argAsString(0)) + " for faction " + fme.getTag());
|
2019-03-03 04:51:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private Permissable getPermissable(String name) {
|
|
|
|
if (Role.fromString(name.toUpperCase()) != null) {
|
|
|
|
return Role.fromString(name.toUpperCase());
|
|
|
|
} else if (Relation.fromString(name.toUpperCase()) != null) {
|
|
|
|
return Relation.fromString(name.toUpperCase());
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_PERM_DESCRIPTION;
|
|
|
|
}
|
2018-01-04 10:36:51 +01:00
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
}
|