From f1d670dc4602ae93e00ea261695ce99ebe91e062 Mon Sep 17 00:00:00 2001 From: Luck Date: Fri, 14 Oct 2016 19:55:22 +0100 Subject: [PATCH] refactor permission commands --- .../permission/CommandPermission.java} | 32 ++--- .../permission/PermissionInfo.java} | 22 +-- .../permission/PermissionSet.java} | 50 ++++--- .../permission/PermissionSetTemp.java} | 50 ++++--- .../permission/PermissionUnset.java} | 48 ++++--- .../permission/PermissionUnsetTemp.java} | 48 ++++--- .../commands/group/GroupMainCommand.java | 7 +- .../subcommands/GroupUnSetPermission.java | 99 ------------- .../common/commands/user/UserMainCommand.java | 37 +++-- .../user/subcommands/UserSetPermission.java | 113 --------------- .../subcommands/UserSetTempPermission.java | 133 ------------------ .../subcommands/UserUnsetTempPermission.java | 100 ------------- .../luckperms/common/constants/Message.java | 9 +- 13 files changed, 156 insertions(+), 592 deletions(-) rename common/src/main/java/me/lucko/luckperms/common/commands/{user/subcommands/UserListNodes.java => generic/permission/CommandPermission.java} (55%) rename common/src/main/java/me/lucko/luckperms/common/commands/{group/subcommands/GroupListNodes.java => generic/permission/PermissionInfo.java} (60%) rename common/src/main/java/me/lucko/luckperms/common/commands/{group/subcommands/GroupSetPermission.java => generic/permission/PermissionSet.java} (68%) rename common/src/main/java/me/lucko/luckperms/common/commands/{group/subcommands/GroupSetTempPermission.java => generic/permission/PermissionSetTemp.java} (71%) rename common/src/main/java/me/lucko/luckperms/common/commands/{user/subcommands/UserUnSetPermission.java => generic/permission/PermissionUnset.java} (66%) rename common/src/main/java/me/lucko/luckperms/common/commands/{group/subcommands/GroupUnsetTempPermission.java => generic/permission/PermissionUnsetTemp.java} (67%) delete mode 100644 common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupUnSetPermission.java delete mode 100644 common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserSetPermission.java delete mode 100644 common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserSetTempPermission.java delete mode 100644 common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserUnsetTempPermission.java diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserListNodes.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java similarity index 55% rename from common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserListNodes.java rename to common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java index 39f49477..40985485 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserListNodes.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java @@ -20,25 +20,21 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.commands.user.subcommands; +package me.lucko.luckperms.common.commands.generic.permission; -import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.constants.Message; -import me.lucko.luckperms.common.constants.Permission; -import me.lucko.luckperms.common.users.User; +import com.google.common.collect.ImmutableList; +import me.lucko.luckperms.common.commands.generic.SecondaryMainCommand; +import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.core.PermissionHolder; -import java.util.List; - -public class UserListNodes extends SubCommand { - public UserListNodes() { - super("listnodes", "Lists the permission nodes the user has", Permission.USER_LISTNODES, Predicate.alwaysFalse(), null); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List args, String label) { - Message.LISTNODES.send(sender, user.getName(), Util.permNodesToString(user.getPermissions(false))); - Message.LISTNODES_TEMP.send(sender, user.getName(), Util.tempNodesToString(user.getPermissions(false))); - return CommandResult.SUCCESS; +public class CommandPermission extends SecondaryMainCommand { + public CommandPermission(boolean user) { + super("Permission", "Edit permissions", user, ImmutableList.builder() + .add(new PermissionInfo()) + .add(new PermissionSet()) + .add(new PermissionUnset()) + .add(new PermissionSetTemp()) + .add(new PermissionUnsetTemp()) + .build()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupListNodes.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java similarity index 60% rename from common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupListNodes.java rename to common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java index 3e0d09d5..da618543 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupListNodes.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java @@ -20,25 +20,29 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.commands.group.subcommands; +package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.commands.*; +import me.lucko.luckperms.common.commands.CommandResult; +import me.lucko.luckperms.common.commands.Predicate; +import me.lucko.luckperms.common.commands.Sender; +import me.lucko.luckperms.common.commands.Util; +import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; -import me.lucko.luckperms.common.groups.Group; +import me.lucko.luckperms.common.core.PermissionHolder; import java.util.List; -public class GroupListNodes extends SubCommand { - public GroupListNodes() { - super("listnodes", "Lists the permission nodes the group has", Permission.GROUP_LISTNODES, Predicate.alwaysFalse(), null); +public class PermissionInfo extends SecondarySubCommand { + public PermissionInfo() { + super("info", "Lists the permission nodes the object has", Permission.USER_LISTNODES, Permission.GROUP_LISTNODES, Predicate.alwaysFalse(), null); } @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { - Message.LISTNODES.send(sender, group.getDisplayName(), Util.permNodesToString(group.getPermissions(false))); - Message.LISTNODES_TEMP.send(sender, group.getDisplayName(), Util.tempNodesToString(group.getPermissions(false))); + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args) { + Message.LISTNODES.send(sender, holder.getFriendlyName(), Util.permNodesToString(holder.getPermissions(false))); + Message.LISTNODES_TEMP.send(sender, holder.getFriendlyName(), Util.tempNodesToString(holder.getPermissions(false))); return CommandResult.SUCCESS; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupSetPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java similarity index 68% rename from common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupSetPermission.java rename to common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java index cbc05bea..f22a2a2a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupSetPermission.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java @@ -20,22 +20,28 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.commands.group.subcommands; +package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.commands.*; +import me.lucko.luckperms.common.commands.Arg; +import me.lucko.luckperms.common.commands.CommandResult; +import me.lucko.luckperms.common.commands.Predicate; +import me.lucko.luckperms.common.commands.Sender; +import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; +import me.lucko.luckperms.common.core.PermissionHolder; import me.lucko.luckperms.common.data.LogEntry; -import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import java.util.List; -public class GroupSetPermission extends SubCommand { - public GroupSetPermission() { - super("set", "Sets a permission for the group", Permission.GROUP_SETPERMISSION, Predicate.notInRange(2, 4), +import static me.lucko.luckperms.common.commands.SubCommand.getBoolTabComplete; + +public class PermissionSet extends SecondarySubCommand { + public PermissionSet() { + super("set", "Sets a permission for the object", Permission.USER_SETPERMISSION, Permission.GROUP_SETPERMISSION, Predicate.notInRange(2, 4), Arg.list( Arg.create("node", true, "the permission node to set"), Arg.create("true|false", true, "the value of the node"), @@ -46,7 +52,7 @@ public class GroupSetPermission extends SubCommand { } @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args) { String node = args.get(0).replace("{SPACE}", " "); String bool = args.get(1).toLowerCase(); @@ -56,7 +62,7 @@ public class GroupSetPermission extends SubCommand { } if (node.toLowerCase().startsWith("group.")) { - Message.GROUP_USE_INHERIT.send(sender); + Message.USE_INHERIT_COMMAND.send(sender); return CommandResult.INVALID_ARGS; } @@ -76,32 +82,32 @@ public class GroupSetPermission extends SubCommand { } if (args.size() == 3) { - group.setPermission(node, b, server); - Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, group.getDisplayName(), server); - LogEntry.build().actor(sender).acted(group) - .action("set " + node + " " + b + " " + server) + holder.setPermission(node, b, server); + Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), server); + LogEntry.build().actor(sender).acted(holder) + .action("permission set " + node + " " + b + " " + server) .build().submit(plugin, sender); } else { final String world = args.get(3).toLowerCase(); - group.setPermission(node, b, server, world); - Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, bool, group.getDisplayName(), server, world); - LogEntry.build().actor(sender).acted(group) - .action("set " + node + " " + b + " " + server + " " + world) + holder.setPermission(node, b, server, world); + Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), server, world); + LogEntry.build().actor(sender).acted(holder) + .action("permission set " + node + " " + b + " " + server + " " + world) .build().submit(plugin, sender); } } else { - group.setPermission(node, b); - Message.SETPERMISSION_SUCCESS.send(sender, node, bool, group.getDisplayName()); - LogEntry.build().actor(sender).acted(group) - .action("set " + node + " " + b) + holder.setPermission(node, b); + Message.SETPERMISSION_SUCCESS.send(sender, node, bool, holder.getFriendlyName()); + LogEntry.build().actor(sender).acted(holder) + .action("permission set " + node + " " + b) .build().submit(plugin, sender); } - save(group, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectAlreadyHasException e) { - Message.ALREADY_HASPERMISSION.send(sender, group.getDisplayName()); + Message.ALREADY_HASPERMISSION.send(sender, holder.getFriendlyName()); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupSetTempPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java similarity index 71% rename from common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupSetTempPermission.java rename to common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java index 21e060a8..b6692ec5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupSetTempPermission.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java @@ -20,23 +20,29 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.commands.group.subcommands; +package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.commands.*; +import me.lucko.luckperms.common.commands.Arg; +import me.lucko.luckperms.common.commands.CommandResult; +import me.lucko.luckperms.common.commands.Predicate; +import me.lucko.luckperms.common.commands.Sender; +import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; +import me.lucko.luckperms.common.core.PermissionHolder; import me.lucko.luckperms.common.data.LogEntry; -import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.common.utils.DateUtil; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import java.util.List; -public class GroupSetTempPermission extends SubCommand { - public GroupSetTempPermission() { - super("settemp", "Sets a permission for the group temporarily", Permission.GROUP_SET_TEMP_PERMISSION, +import static me.lucko.luckperms.common.commands.SubCommand.getBoolTabComplete; + +public class PermissionSetTemp extends SecondarySubCommand { + public PermissionSetTemp() { + super("settemp", "Sets a permission for the object temporarily", Permission.USER_SET_TEMP_PERMISSION, Permission.GROUP_SET_TEMP_PERMISSION, Predicate.notInRange(3, 5), Arg.list( Arg.create("node", true, "the permission node to set"), @@ -49,7 +55,7 @@ public class GroupSetTempPermission extends SubCommand { } @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args) { String node = args.get(0).replace("{SPACE}", " "); String bool = args.get(1).toLowerCase(); @@ -59,7 +65,7 @@ public class GroupSetTempPermission extends SubCommand { } if (node.toLowerCase().startsWith("group.")) { - Message.GROUP_USE_INHERIT.send(sender); + Message.USE_INHERIT_COMMAND.send(sender); return CommandResult.INVALID_ARGS; } @@ -96,34 +102,34 @@ public class GroupSetTempPermission extends SubCommand { } if (args.size() == 4) { - group.setPermission(node, b, server, duration); - Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, group.getDisplayName(), server, + holder.setPermission(node, b, server, duration); + Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), server, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(group) - .action("settemp " + node + " " + b + " " + duration + " " + server) + LogEntry.build().actor(sender).acted(holder) + .action("permission settemp " + node + " " + b + " " + duration + " " + server) .build().submit(plugin, sender); } else { final String world = args.get(4).toLowerCase(); - group.setPermission(node, b, server, world, duration); - Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, bool, group.getDisplayName(), server, + holder.setPermission(node, b, server, world, duration); + Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), server, world, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(group) - .action("settemp " + node + " " + b + " " + duration + " " + server + " " + world) + LogEntry.build().actor(sender).acted(holder) + .action("permission settemp " + node + " " + b + " " + duration + " " + server + " " + world) .build().submit(plugin, sender); } } else { - group.setPermission(node, b, duration); - Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, group.getDisplayName(), DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(group) - .action("settemp " + node + " " + b + " " + duration) + holder.setPermission(node, b, duration); + Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), DateUtil.formatDateDiff(duration)); + LogEntry.build().actor(sender).acted(holder) + .action("permission settemp " + node + " " + b + " " + duration) .build().submit(plugin, sender); } - save(group, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectAlreadyHasException e) { - Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, group.getDisplayName()); + Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, holder.getFriendlyName()); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserUnSetPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java similarity index 66% rename from common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserUnSetPermission.java rename to common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java index 3c8fd1de..c68c00cd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserUnSetPermission.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java @@ -20,22 +20,26 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.commands.user.subcommands; +package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.commands.*; +import me.lucko.luckperms.common.commands.Arg; +import me.lucko.luckperms.common.commands.CommandResult; +import me.lucko.luckperms.common.commands.Predicate; +import me.lucko.luckperms.common.commands.Sender; +import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; +import me.lucko.luckperms.common.core.PermissionHolder; import me.lucko.luckperms.common.data.LogEntry; -import me.lucko.luckperms.common.users.User; import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.List; -public class UserUnSetPermission extends SubCommand { - public UserUnSetPermission() { - super("unset", "Unsets a permission for the user", Permission.USER_UNSETPERMISSION, Predicate.notInRange(1, 3), +public class PermissionUnset extends SecondarySubCommand { + public PermissionUnset() { + super("unset", "Unsets a permission for the object", Permission.USER_UNSETPERMISSION, Permission.GROUP_UNSETPERMISSION, Predicate.notInRange(1, 3), Arg.list( Arg.create("node", true, "the permission node to unset"), Arg.create("server", false, "the server to remove the permission node on"), @@ -45,7 +49,7 @@ public class UserUnSetPermission extends SubCommand { } @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args) { String node = args.get(0).replace("{SPACE}", " "); if (ArgumentChecker.checkNode(node)) { @@ -54,7 +58,7 @@ public class UserUnSetPermission extends SubCommand { } if (node.toLowerCase().startsWith("group.")) { - Message.USER_USE_REMOVEGROUP.send(sender); + Message.USE_UNINHERIT_COMMAND.send(sender); return CommandResult.INVALID_ARGS; } @@ -67,32 +71,32 @@ public class UserUnSetPermission extends SubCommand { } if (args.size() == 2) { - user.unsetPermission(node, server); - Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, user.getName(), server); - LogEntry.build().actor(sender).acted(user) - .action("unset " + node + " " + server) + holder.unsetPermission(node, server); + Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, holder.getFriendlyName(), server); + LogEntry.build().actor(sender).acted(holder) + .action("permission unset " + node + " " + server) .build().submit(plugin, sender); } else { final String world = args.get(2).toLowerCase(); - user.unsetPermission(node, server, world); - Message.UNSETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, user.getName(), server, world); - LogEntry.build().actor(sender).acted(user) - .action("unset " + node + " " + server + " " + world) + holder.unsetPermission(node, server, world); + Message.UNSETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, holder.getFriendlyName(), server, world); + LogEntry.build().actor(sender).acted(holder) + .action("permission unset " + node + " " + server + " " + world) .build().submit(plugin, sender); } } else { - user.unsetPermission(node); - Message.UNSETPERMISSION_SUCCESS.send(sender, node, user.getName()); - LogEntry.build().actor(sender).acted(user) - .action("unset " + node) + holder.unsetPermission(node); + Message.UNSETPERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName()); + LogEntry.build().actor(sender).acted(holder) + .action("permission unset " + node) .build().submit(plugin, sender); } - save(user, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectLacksException e) { - Message.DOES_NOT_HAVEPERMISSION.send(sender, user.getName()); + Message.DOES_NOT_HAVEPERMISSION.send(sender, holder.getFriendlyName()); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupUnsetTempPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java similarity index 67% rename from common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupUnsetTempPermission.java rename to common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java index 35b762c9..b76bd440 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupUnsetTempPermission.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java @@ -20,22 +20,26 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.commands.group.subcommands; +package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.commands.*; +import me.lucko.luckperms.common.commands.Arg; +import me.lucko.luckperms.common.commands.CommandResult; +import me.lucko.luckperms.common.commands.Predicate; +import me.lucko.luckperms.common.commands.Sender; +import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; +import me.lucko.luckperms.common.core.PermissionHolder; import me.lucko.luckperms.common.data.LogEntry; -import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.List; -public class GroupUnsetTempPermission extends SubCommand { - public GroupUnsetTempPermission() { - super("unsettemp", "Unsets a temporary permission for the group", Permission.GROUP_UNSET_TEMP_PERMISSION, +public class PermissionUnsetTemp extends SecondarySubCommand { + public PermissionUnsetTemp() { + super("unsettemp", "Unsets a temporary permission for the object", Permission.USER_UNSET_TEMP_PERMISSION, Permission.GROUP_UNSET_TEMP_PERMISSION, Predicate.notInRange(1, 3), Arg.list( Arg.create("node", true, "the permission node to unset"), @@ -46,7 +50,7 @@ public class GroupUnsetTempPermission extends SubCommand { } @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args) { String node = args.get(0).replace("{SPACE}", " "); if (ArgumentChecker.checkNode(node)) { @@ -55,7 +59,7 @@ public class GroupUnsetTempPermission extends SubCommand { } if (node.toLowerCase().startsWith("group.")) { - Message.GROUP_USE_UNINHERIT.send(sender); + Message.USE_UNINHERIT_COMMAND.send(sender); return CommandResult.INVALID_ARGS; } @@ -68,32 +72,32 @@ public class GroupUnsetTempPermission extends SubCommand { } if (args.size() == 2) { - group.unsetPermission(node, server); - Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, group.getDisplayName(), server); - LogEntry.build().actor(sender).acted(group) - .action("unsettemp " + node + " " + server) + holder.unsetPermission(node, server); + Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, holder.getFriendlyName(), server); + LogEntry.build().actor(sender).acted(holder) + .action("permission unsettemp " + node + " " + server) .build().submit(plugin, sender); } else { final String world = args.get(2).toLowerCase(); - group.unsetPermission(node, server, world); - Message.UNSET_TEMP_PERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, group.getDisplayName(), server, world); - LogEntry.build().actor(sender).acted(group) - .action("unsettemp " + node + " " + server + " " + world) + holder.unsetPermission(node, server, world); + Message.UNSET_TEMP_PERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, holder.getFriendlyName(), server, world); + LogEntry.build().actor(sender).acted(holder) + .action("permission unsettemp " + node + " " + server + " " + world) .build().submit(plugin, sender); } } else { - group.unsetPermission(node, true); - Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, group.getDisplayName()); - LogEntry.build().actor(sender).acted(group) - .action("unsettemp " + node) + holder.unsetPermission(node, true); + Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName()); + LogEntry.build().actor(sender).acted(holder) + .action("permission unsettemp " + node) .build().submit(plugin, sender); } - save(group, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectLacksException e) { - Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, group.getDisplayName()); + Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, holder.getFriendlyName()); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java index 0276d984..0826206e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java @@ -28,6 +28,7 @@ import me.lucko.luckperms.common.commands.MainCommand; import me.lucko.luckperms.common.commands.Sender; import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.generic.parent.CommandParent; +import me.lucko.luckperms.common.commands.generic.permission.CommandPermission; import me.lucko.luckperms.common.commands.group.subcommands.*; import me.lucko.luckperms.common.commands.generic.meta.CommandMeta; import me.lucko.luckperms.common.constants.Message; @@ -40,15 +41,11 @@ public class GroupMainCommand extends MainCommand { public GroupMainCommand() { super("Group", "/%s group ", 2, ImmutableList.>builder() .add(new GroupInfo()) + .add(new CommandPermission<>(false)) .add(new CommandParent<>(false)) .add(new CommandMeta<>(false)) - .add(new GroupListNodes()) .add(new GroupHasPerm()) .add(new GroupInheritsPerm()) - .add(new GroupSetPermission()) - .add(new GroupUnSetPermission()) - .add(new GroupSetTempPermission()) - .add(new GroupUnsetTempPermission()) .add(new GroupShowTracks()) .add(new GroupBulkChange()) .add(new GroupClear()) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupUnSetPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupUnSetPermission.java deleted file mode 100644 index a70de0e1..00000000 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/subcommands/GroupUnSetPermission.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2016 Lucko (Luck) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.common.commands.group.subcommands; - -import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.constants.Message; -import me.lucko.luckperms.common.constants.Permission; -import me.lucko.luckperms.common.data.LogEntry; -import me.lucko.luckperms.common.groups.Group; -import me.lucko.luckperms.common.utils.ArgumentChecker; -import me.lucko.luckperms.exceptions.ObjectLacksException; - -import java.util.List; - -public class GroupUnSetPermission extends SubCommand { - public GroupUnSetPermission() { - super("unset", "Unsets a permission for the group", Permission.GROUP_UNSETPERMISSION, Predicate.notInRange(1, 3), - Arg.list( - Arg.create("node", true, "the permission node to unset"), - Arg.create("server", false, "the server to remove the permission node on"), - Arg.create("world", false, "the world to remove the permission node on") - ) - ); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { - String node = args.get(0).replace("{SPACE}", " "); - - if (ArgumentChecker.checkNode(node)) { - sendDetailedUsage(sender); - return CommandResult.INVALID_ARGS; - } - - if (node.toLowerCase().startsWith("group.")) { - Message.GROUP_USE_UNINHERIT.send(sender); - return CommandResult.INVALID_ARGS; - } - - try { - if (args.size() >= 2) { - final String server = args.get(1).toLowerCase(); - if (ArgumentChecker.checkServer(server)) { - Message.SERVER_INVALID_ENTRY.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (args.size() == 2) { - group.unsetPermission(node, server); - Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, group.getDisplayName(), server); - LogEntry.build().actor(sender).acted(group) - .action("unset " + node + " " + server) - .build().submit(plugin, sender); - } else { - final String world = args.get(2).toLowerCase(); - group.unsetPermission(node, server, world); - Message.UNSETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, group.getDisplayName(), server, world); - LogEntry.build().actor(sender).acted(group) - .action("unset " + node + " " + server + " " + world) - .build().submit(plugin, sender); - } - - } else { - group.unsetPermission(node); - Message.UNSETPERMISSION_SUCCESS.send(sender, node, group.getDisplayName()); - LogEntry.build().actor(sender).acted(group) - .action("unset " + node) - .build().submit(plugin, sender); - } - - save(group, sender, plugin); - return CommandResult.SUCCESS; - } catch (ObjectLacksException e) { - Message.DOES_NOT_HAVEPERMISSION.send(sender, group.getDisplayName()); - return CommandResult.STATE_ERROR; - } - } -} diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java index aec19004..c8026624 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java @@ -30,6 +30,7 @@ import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.Util; import me.lucko.luckperms.common.commands.generic.meta.CommandMeta; import me.lucko.luckperms.common.commands.generic.parent.CommandParent; +import me.lucko.luckperms.common.commands.generic.permission.CommandPermission; import me.lucko.luckperms.common.commands.user.subcommands.*; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Patterns; @@ -41,25 +42,21 @@ import java.util.UUID; public class UserMainCommand extends MainCommand { public UserMainCommand() { super("User", "/%s user ", 2, ImmutableList.>builder() - .add(new UserInfo()) - .add(new CommandParent<>(true)) - .add(new CommandMeta<>(true)) - .add(new UserGetUUID()) - .add(new UserListNodes()) - .add(new UserHasPerm()) - .add(new UserInheritsPerm()) - .add(new UserSetPermission()) - .add(new UserUnSetPermission()) - .add(new UserSetTempPermission()) - .add(new UserUnsetTempPermission()) - .add(new UserSetPrimaryGroup()) - .add(new UserShowTracks()) - .add(new UserPromote()) - .add(new UserDemote()) - .add(new UserShowPos()) - .add(new UserBulkChange()) - .add(new UserClear()) - .build() + .add(new UserInfo()) + .add(new CommandPermission<>(true)) + .add(new CommandParent<>(true)) + .add(new CommandMeta<>(true)) + .add(new UserGetUUID()) + .add(new UserHasPerm()) + .add(new UserInheritsPerm()) + .add(new UserSetPrimaryGroup()) + .add(new UserShowTracks()) + .add(new UserPromote()) + .add(new UserDemote()) + .add(new UserShowPos()) + .add(new UserBulkChange()) + .add(new UserClear()) + .build() ); } @@ -108,4 +105,4 @@ public class UserMainCommand extends MainCommand { protected List getObjects(LuckPermsPlugin plugin) { return plugin.getPlayerList(); } -} +} \ No newline at end of file diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserSetPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserSetPermission.java deleted file mode 100644 index fb9bb240..00000000 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserSetPermission.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2016 Lucko (Luck) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.common.commands.user.subcommands; - -import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.constants.Message; -import me.lucko.luckperms.common.constants.Permission; -import me.lucko.luckperms.common.data.LogEntry; -import me.lucko.luckperms.common.users.User; -import me.lucko.luckperms.common.utils.ArgumentChecker; -import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; - -import java.util.List; - -public class UserSetPermission extends SubCommand { - public UserSetPermission() { - super("set", "Sets a permission for the user", Permission.USER_SETPERMISSION, Predicate.notInRange(2, 4), - Arg.list( - Arg.create("node", true, "the permission node to set"), - Arg.create("true|false", true, "the value of the node"), - Arg.create("server", false, "the server to add the permission node on"), - Arg.create("world", false, "the world to add the permission node on") - ) - ); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List args, String label) { - String node = args.get(0).replace("{SPACE}", " "); - String bool = args.get(1).toLowerCase(); - - if (ArgumentChecker.checkNode(node)) { - sendDetailedUsage(sender); - return CommandResult.INVALID_ARGS; - } - - if (node.toLowerCase().startsWith("group.")) { - Message.USER_USE_ADDGROUP.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) { - sendDetailedUsage(sender); - return CommandResult.INVALID_ARGS; - } - - boolean b = Boolean.parseBoolean(bool); - - try { - if (args.size() >= 3) { - final String server = args.get(2).toLowerCase(); - if (ArgumentChecker.checkServer(server)) { - Message.SERVER_INVALID_ENTRY.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (args.size() == 3) { - user.setPermission(node, b, server); - Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, user.getName(), server); - LogEntry.build().actor(sender).acted(user) - .action("set " + node + " " + b + " " + server) - .build().submit(plugin, sender); - } else { - final String world = args.get(3).toLowerCase(); - user.setPermission(node, b, server, world); - Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, bool, user.getName(), server, world); - LogEntry.build().actor(sender).acted(user) - .action("set " + node + " " + b + " " + server + " " + world) - .build().submit(plugin, sender); - } - - } else { - user.setPermission(node, b); - Message.SETPERMISSION_SUCCESS.send(sender, node, bool, user.getName()); - LogEntry.build().actor(sender).acted(user) - .action("set " + node + " " + b) - .build().submit(plugin, sender); - } - - save(user, sender, plugin); - return CommandResult.SUCCESS; - } catch (ObjectAlreadyHasException e) { - Message.ALREADY_HASPERMISSION.send(sender, user.getName()); - return CommandResult.STATE_ERROR; - } - } - - @Override - public List onTabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return getBoolTabComplete(args); - } -} diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserSetTempPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserSetTempPermission.java deleted file mode 100644 index fb054500..00000000 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserSetTempPermission.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2016 Lucko (Luck) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.common.commands.user.subcommands; - -import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.constants.Message; -import me.lucko.luckperms.common.constants.Permission; -import me.lucko.luckperms.common.data.LogEntry; -import me.lucko.luckperms.common.users.User; -import me.lucko.luckperms.common.utils.ArgumentChecker; -import me.lucko.luckperms.common.utils.DateUtil; -import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; - -import java.util.List; - -public class UserSetTempPermission extends SubCommand { - public UserSetTempPermission() { - super("settemp", "Sets a permission for the user temporarily", Permission.USER_SET_TEMP_PERMISSION, - Predicate.notInRange(3, 5), - Arg.list( - Arg.create("node", true, "the permission node to set"), - Arg.create("true|false", true, "the value of the node"), - Arg.create("duration", true, "the duration until the permission node expires"), - Arg.create("server", false, "the server to add the permission node on"), - Arg.create("world", false, "the world to add the permission node on") - ) - ); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List args, String label) { - String node = args.get(0).replace("{SPACE}", " "); - String bool = args.get(1).toLowerCase(); - - if (ArgumentChecker.checkNode(node)) { - sendDetailedUsage(sender); - return CommandResult.INVALID_ARGS; - } - - if (node.toLowerCase().startsWith("group.")) { - Message.USER_USE_ADDGROUP.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) { - sendDetailedUsage(sender); - return CommandResult.INVALID_ARGS; - } - - boolean b = Boolean.parseBoolean(bool); - - long duration; - try { - duration = Long.parseLong(args.get(2)); - } catch (NumberFormatException e) { - try { - duration = DateUtil.parseDateDiff(args.get(2), true); - } catch (DateUtil.IllegalDateException e1) { - Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2)); - return CommandResult.INVALID_ARGS; - } - } - - if (DateUtil.shouldExpire(duration)) { - Message.PAST_DATE_ERROR.send(sender); - return CommandResult.INVALID_ARGS; - } - - try { - if (args.size() >= 4) { - final String server = args.get(3).toLowerCase(); - if (ArgumentChecker.checkServer(server)) { - Message.SERVER_INVALID_ENTRY.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (args.size() == 4) { - user.setPermission(node, b, server, duration); - Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, user.getName(), server, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(user) - .action("settemp " + node + " " + b + " " + duration + " " + server) - .build().submit(plugin, sender); - } else { - final String world = args.get(4).toLowerCase(); - user.setPermission(node, b, server, world, duration); - Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, bool, user.getName(), server, world, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(user) - .action("settemp " + node + " " + b + " " + duration + " " + server + " " + world) - .build().submit(plugin, sender); - } - - } else { - user.setPermission(node, b, duration); - Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, user.getName(), DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(user) - .action("settemp " + node + " " + b + " " + duration) - .build().submit(plugin, sender); - } - - save(user, sender, plugin); - return CommandResult.SUCCESS; - } catch (ObjectAlreadyHasException e) { - Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, user.getName()); - return CommandResult.STATE_ERROR; - } - } - - @Override - public List onTabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return getBoolTabComplete(args); - } -} diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserUnsetTempPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserUnsetTempPermission.java deleted file mode 100644 index 0c2862aa..00000000 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserUnsetTempPermission.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2016 Lucko (Luck) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.common.commands.user.subcommands; - -import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.constants.Message; -import me.lucko.luckperms.common.constants.Permission; -import me.lucko.luckperms.common.data.LogEntry; -import me.lucko.luckperms.common.users.User; -import me.lucko.luckperms.common.utils.ArgumentChecker; -import me.lucko.luckperms.exceptions.ObjectLacksException; - -import java.util.List; - -public class UserUnsetTempPermission extends SubCommand { - public UserUnsetTempPermission() { - super("unsettemp", "Unsets a temporary permission for the user", Permission.USER_UNSET_TEMP_PERMISSION, - Predicate.notInRange(1, 3), - Arg.list( - Arg.create("node", true, "the permission node to unset"), - Arg.create("server", false, "the server to remove the permission node on"), - Arg.create("world", false, "the world to remove the permission node on") - ) - ); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List args, String label) { - String node = args.get(0).replace("{SPACE}", " "); - - if (ArgumentChecker.checkNode(node)) { - sendDetailedUsage(sender); - return CommandResult.INVALID_ARGS; - } - - if (node.toLowerCase().startsWith("group.")) { - Message.USER_USE_REMOVEGROUP.send(sender); - return CommandResult.INVALID_ARGS; - } - - try { - if (args.size() >= 2) { - final String server = args.get(1).toLowerCase(); - if (ArgumentChecker.checkServer(server)) { - Message.SERVER_INVALID_ENTRY.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (args.size() == 2) { - user.unsetPermission(node, server, true); - Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, user.getName(), server); - LogEntry.build().actor(sender).acted(user) - .action("unsettemp " + node + " " + server) - .build().submit(plugin, sender); - } else { - final String world = args.get(2).toLowerCase(); - user.unsetPermission(node, server, world, true); - Message.UNSET_TEMP_PERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, user.getName(), server, world); - LogEntry.build().actor(sender).acted(user) - .action("unsettemp " + node + " " + server + " " + world) - .build().submit(plugin, sender); - } - - } else { - user.unsetPermission(node, true); - Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, user.getName()); - LogEntry.build().actor(sender).acted(user) - .action("unsettemp " + node) - .build().submit(plugin, sender); - } - - save(user, sender, plugin); - return CommandResult.SUCCESS; - } catch (ObjectLacksException e) { - Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, user.getName()); - return CommandResult.STATE_ERROR; - } - } -} diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java index 8e5a8fa2..7e892a1d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java @@ -73,17 +73,12 @@ public enum Message { /* * Command Syntax */ - USER_USE_ADDGROUP("Use the addgroup command instead of specifying the node.", true), - USER_USE_REMOVEGROUP("Use the removegroup command instead of specifying the node.", true), USER_INVALID_ENTRY("&d{0}&c is not a valid username/uuid.", true), - - GROUP_USE_INHERIT("Use the setinherit command instead of specifying the node.", true), - GROUP_USE_UNINHERIT("Use the unsetinherit command instead of specifying the node.", true), GROUP_INVALID_ENTRY("Group names can only contain alphanumeric characters.", true), - TRACK_INVALID_ENTRY("Track names can only contain alphanumeric characters.", true), - SERVER_INVALID_ENTRY("Server names can only contain alphanumeric characters.", true), + USE_INHERIT_COMMAND("Use the 'parent add' command instead of specifying the node.", true), + USE_UNINHERIT_COMMAND("Use the 'parent remove' command instead of specifying the node.", true), /*