Introduced Brigadier Command System. More Formatting Coming in next commit.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
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;
|
||||
@@ -27,46 +28,43 @@ public class CmdPerm extends FCommand {
|
||||
this.optionalArgs.put("action", "action");
|
||||
this.optionalArgs.put("access", "access");
|
||||
|
||||
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = true;
|
||||
|
||||
this.requirements = new CommandRequirements.Builder(Permission.PERMISSIONS)
|
||||
.playerOnly()
|
||||
.memberOnly()
|
||||
.withRole(Role.LEADER)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
if (args.size() == 0) {
|
||||
new PermissableRelationFrame(fme.getFaction()).buildGUI(fme);
|
||||
public void perform(CommandContext context) {
|
||||
|
||||
if (context.args.size() == 0) {
|
||||
new PermissableRelationFrame(context.faction).buildGUI(context.fPlayer);
|
||||
return;
|
||||
} else if (args.size() == 1 && getPermissable(argAsString(0)) != null) {
|
||||
new PermissableActionFrame(fme.getFaction()).buildGUI(fme, getPermissable(argAsString(0)));
|
||||
} else if (context.args.size() == 1 && getPermissable(context.argAsString(0)) != null) {
|
||||
new PermissableActionFrame(context.faction).buildGUI(context.fPlayer, getPermissable(context.argAsString(0)));
|
||||
return;
|
||||
}
|
||||
|
||||
// If not opening GUI, then setting the permission manually.
|
||||
if (args.size() != 3) {
|
||||
fme.msg(TL.COMMAND_PERM_DESCRIPTION);
|
||||
if (context.args.size() != 3) {
|
||||
context.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");
|
||||
boolean allRelations = context.argAsString(0).equalsIgnoreCase("all");
|
||||
boolean allActions = context.argAsString(1).equalsIgnoreCase("all");
|
||||
|
||||
if (allRelations) {
|
||||
permissables.addAll(myFaction.getPermissions().keySet());
|
||||
permissables.addAll(context.faction.getPermissions().keySet());
|
||||
} else {
|
||||
Permissable permissable = getPermissable(argAsString(0));
|
||||
Permissable permissable = getPermissable(context.argAsString(0));
|
||||
|
||||
if (permissable == null) {
|
||||
fme.msg(TL.COMMAND_PERM_INVALID_RELATION);
|
||||
context.msg(TL.COMMAND_PERM_INVALID_RELATION);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -76,29 +74,30 @@ public class CmdPerm extends FCommand {
|
||||
if (allActions) {
|
||||
permissableActions.addAll(Arrays.asList(PermissableAction.values()));
|
||||
} else {
|
||||
PermissableAction permissableAction = PermissableAction.fromString(argAsString(1));
|
||||
PermissableAction permissableAction = PermissableAction.fromString(context.argAsString(1));
|
||||
if (permissableAction == null) {
|
||||
fme.msg(TL.COMMAND_PERM_INVALID_ACTION);
|
||||
context.msg(TL.COMMAND_PERM_INVALID_ACTION);
|
||||
return;
|
||||
}
|
||||
|
||||
permissableActions.add(permissableAction);
|
||||
}
|
||||
|
||||
Access access = Access.fromString(argAsString(2));
|
||||
Access access = Access.fromString(context.argAsString(2));
|
||||
|
||||
if (access == null) {
|
||||
fme.msg(TL.COMMAND_PERM_INVALID_ACCESS);
|
||||
context.msg(TL.COMMAND_PERM_INVALID_ACCESS);
|
||||
return;
|
||||
}
|
||||
|
||||
for (Permissable permissable : permissables) {
|
||||
for (PermissableAction permissableAction : permissableActions) {
|
||||
fme.getFaction().setPermission(permissable, permissableAction, access);
|
||||
context.faction.setPermission(permissable, permissableAction, access);
|
||||
}
|
||||
}
|
||||
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());
|
||||
|
||||
context.msg(TL.COMMAND_PERM_SET, context.argAsString(1), access.name(), context.argAsString(0));
|
||||
FactionsPlugin.getInstance().log(String.format(TL.COMMAND_PERM_SET.toString(), context.argAsString(1), access.name(), context.argAsString(0)) + " for faction " + context.fPlayer.getTag());
|
||||
}
|
||||
|
||||
private Permissable getPermissable(String name) {
|
||||
|
||||
Reference in New Issue
Block a user