From d433a5461da4bbd86166539a539eb947db68033b Mon Sep 17 00:00:00 2001 From: Luck Date: Tue, 11 Oct 2016 21:12:10 +0100 Subject: [PATCH] Refactor meta commands, working towards #23 --- .../lucko/luckperms/commands/SubCommand.java | 2 +- .../commands/group/GroupMainCommand.java | 12 +- .../group/subcommands/GroupAddTempPrefix.java | 118 -------------- .../group/subcommands/GroupAddTempSuffix.java | 118 -------------- .../group/subcommands/GroupClearMeta.java | 79 --------- .../group/subcommands/GroupRemovePrefix.java | 153 ----------------- .../group/subcommands/GroupRemoveSuffix.java | 153 ----------------- .../subcommands/GroupRemoveTempPrefix.java | 154 ------------------ .../subcommands/GroupRemoveTempSuffix.java | 154 ------------------ .../luckperms/commands/meta/MetaCommands.java | 114 +++++++++++++ .../commands/meta/MetaSubCommand.java | 124 ++++++++++++++ .../subcommands/MetaAddPrefix.java} | 46 +++--- .../subcommands/MetaAddSuffix.java} | 46 +++--- .../subcommands/MetaAddTempPrefix.java} | 46 +++--- .../subcommands/MetaAddTempSuffix.java} | 46 +++--- .../subcommands/MetaClear.java} | 36 ++-- .../subcommands/MetaInfo.java} | 28 ++-- .../subcommands/MetaRemovePrefix.java} | 60 +++---- .../subcommands/MetaRemoveSuffix.java} | 60 +++---- .../subcommands/MetaRemoveTempPrefix.java} | 61 +++---- .../subcommands/MetaRemoveTempSuffix.java} | 61 +++---- .../commands/user/UserMainCommand.java | 12 +- .../user/subcommands/UserAddPrefix.java | 99 ----------- .../user/subcommands/UserAddSuffix.java | 99 ----------- .../user/subcommands/UserChatMeta.java | 93 ----------- .../luckperms/core/PermissionHolder.java | 2 + .../java/me/lucko/luckperms/groups/Group.java | 5 + .../java/me/lucko/luckperms/users/User.java | 5 + 28 files changed, 519 insertions(+), 1467 deletions(-) delete mode 100644 common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupAddTempPrefix.java delete mode 100644 common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupAddTempSuffix.java delete mode 100644 common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupClearMeta.java delete mode 100644 common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemovePrefix.java delete mode 100644 common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemoveSuffix.java delete mode 100644 common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemoveTempPrefix.java delete mode 100644 common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemoveTempSuffix.java create mode 100644 common/src/main/java/me/lucko/luckperms/commands/meta/MetaCommands.java create mode 100644 common/src/main/java/me/lucko/luckperms/commands/meta/MetaSubCommand.java rename common/src/main/java/me/lucko/luckperms/commands/{group/subcommands/GroupAddPrefix.java => meta/subcommands/MetaAddPrefix.java} (67%) rename common/src/main/java/me/lucko/luckperms/commands/{group/subcommands/GroupAddSuffix.java => meta/subcommands/MetaAddSuffix.java} (67%) rename common/src/main/java/me/lucko/luckperms/commands/{user/subcommands/UserAddTempPrefix.java => meta/subcommands/MetaAddTempPrefix.java} (68%) rename common/src/main/java/me/lucko/luckperms/commands/{user/subcommands/UserAddTempSuffix.java => meta/subcommands/MetaAddTempSuffix.java} (68%) rename common/src/main/java/me/lucko/luckperms/commands/{user/subcommands/UserClearMeta.java => meta/subcommands/MetaClear.java} (65%) rename common/src/main/java/me/lucko/luckperms/commands/{group/subcommands/GroupChatMeta.java => meta/subcommands/MetaInfo.java} (75%) rename common/src/main/java/me/lucko/luckperms/commands/{user/subcommands/UserRemovePrefix.java => meta/subcommands/MetaRemovePrefix.java} (72%) rename common/src/main/java/me/lucko/luckperms/commands/{user/subcommands/UserRemoveSuffix.java => meta/subcommands/MetaRemoveSuffix.java} (72%) rename common/src/main/java/me/lucko/luckperms/commands/{user/subcommands/UserRemoveTempPrefix.java => meta/subcommands/MetaRemoveTempPrefix.java} (72%) rename common/src/main/java/me/lucko/luckperms/commands/{user/subcommands/UserRemoveTempSuffix.java => meta/subcommands/MetaRemoveTempSuffix.java} (72%) delete mode 100644 common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddPrefix.java delete mode 100644 common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddSuffix.java delete mode 100644 common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserChatMeta.java diff --git a/common/src/main/java/me/lucko/luckperms/commands/SubCommand.java b/common/src/main/java/me/lucko/luckperms/commands/SubCommand.java index c1790743e..bf52ba412 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/SubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/SubCommand.java @@ -123,7 +123,7 @@ public abstract class SubCommand { * @return true if the sender can use the command */ public boolean isAuthorized(Sender sender) { - return permission.isAuthorized(sender); + return permission == null || permission.isAuthorized(sender); } diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/GroupMainCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/GroupMainCommand.java index bbef412d4..e51535416 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/GroupMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/GroupMainCommand.java @@ -28,6 +28,7 @@ import me.lucko.luckperms.commands.MainCommand; import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.group.subcommands.*; +import me.lucko.luckperms.commands.meta.MetaCommands; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.groups.Group; @@ -51,16 +52,7 @@ public class GroupMainCommand extends MainCommand { .add(new GroupSetTempInherit()) .add(new GroupUnsetTempInherit()) .add(new GroupShowTracks()) - .add(new GroupChatMeta()) - .add(new GroupAddPrefix()) - .add(new GroupAddSuffix()) - .add(new GroupRemovePrefix()) - .add(new GroupRemoveSuffix()) - .add(new GroupAddTempPrefix()) - .add(new GroupAddTempSuffix()) - .add(new GroupRemoveTempPrefix()) - .add(new GroupRemoveTempSuffix()) - .add(new GroupClearMeta()) + .add(new MetaCommands<>()) .add(new GroupBulkChange()) .add(new GroupClear()) .add(new GroupRename()) diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupAddTempPrefix.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupAddTempPrefix.java deleted file mode 100644 index 2cc0f7448..000000000 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupAddTempPrefix.java +++ /dev/null @@ -1,118 +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.commands.group.subcommands; - -import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; -import me.lucko.luckperms.constants.Message; -import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntry; -import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; -import me.lucko.luckperms.groups.Group; -import me.lucko.luckperms.utils.ArgumentChecker; -import me.lucko.luckperms.utils.DateUtil; - -import java.util.List; - -public class GroupAddTempPrefix extends SubCommand { - public GroupAddTempPrefix() { - super("addtempprefix", "Adds a prefix to the group temporarily", Permission.GROUP_ADD_TEMP_PREFIX, Predicate.notInRange(3, 5), - Arg.list( - Arg.create("priority", true, "the priority to add the prefix at"), - Arg.create("prefix", true, "the prefix string"), - Arg.create("duration", true, "the duration until the prefix expires"), - Arg.create("server", false, "the server to add the prefix on"), - Arg.create("world", false, "the world to add the prefix on") - ) - ); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { - final String prefix = args.get(1).replace("{SPACE}", " "); - int priority; - try { - priority = Integer.parseInt(args.get(0)); - } catch (NumberFormatException e) { - Message.META_INVALID_PRIORITY.send(sender, args.get(0)); - return CommandResult.INVALID_ARGS; - } - - 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; - } - - final String node = "prefix." + priority + "." + ArgumentChecker.escapeCharacters(prefix); - - 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) { - group.setPermission(node, true, server, duration); - Message.ADD_TEMP_PREFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(group) - .action("addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server) - .build().submit(plugin, sender); - } else { - final String world = args.get(4).toLowerCase(); - group.setPermission(node, true, server, world, duration); - Message.ADD_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server, world, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(group) - .action("addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world) - .build().submit(plugin, sender); - } - - } else { - group.setPermission(node, true, duration); - Message.ADD_TEMP_PREFIX_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(group) - .action("addtempprefix " + priority + " " + args.get(1) + " " + duration) - .build().submit(plugin, sender); - } - - save(group, sender, plugin); - return CommandResult.SUCCESS; - } catch (ObjectAlreadyHasException e) { - Message.ALREADY_HAS_PREFIX.send(sender, group.getDisplayName()); - return CommandResult.STATE_ERROR; - } - } -} diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupAddTempSuffix.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupAddTempSuffix.java deleted file mode 100644 index 0931321b7..000000000 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupAddTempSuffix.java +++ /dev/null @@ -1,118 +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.commands.group.subcommands; - -import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; -import me.lucko.luckperms.constants.Message; -import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntry; -import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; -import me.lucko.luckperms.groups.Group; -import me.lucko.luckperms.utils.ArgumentChecker; -import me.lucko.luckperms.utils.DateUtil; - -import java.util.List; - -public class GroupAddTempSuffix extends SubCommand { - public GroupAddTempSuffix() { - super("addtempsuffix", "Adds a suffix to the group temporarily", Permission.GROUP_ADD_TEMP_SUFFIX, Predicate.notInRange(3, 5), - Arg.list( - Arg.create("priority", true, "the priority to add the suffix at"), - Arg.create("suffix", true, "the suffix string"), - Arg.create("duration", true, "the duration until the suffix expires"), - Arg.create("server", false, "the server to add the suffix on"), - Arg.create("world", false, "the world to add the suffix on") - ) - ); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { - final String suffix = args.get(1).replace("{SPACE}", " "); - int priority; - try { - priority = Integer.parseInt(args.get(0)); - } catch (NumberFormatException e) { - Message.META_INVALID_PRIORITY.send(sender, args.get(0)); - return CommandResult.INVALID_ARGS; - } - - 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; - } - - final String node = "suffix." + priority + "." + ArgumentChecker.escapeCharacters(suffix); - - 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) { - group.setPermission(node, true, server, duration); - Message.ADD_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(group) - .action("addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server) - .build().submit(plugin, sender); - } else { - final String world = args.get(4).toLowerCase(); - group.setPermission(node, true, server, world, duration); - Message.ADD_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server, world, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(group) - .action("addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world) - .build().submit(plugin, sender); - } - - } else { - group.setPermission(node, true, duration); - Message.ADD_TEMP_SUFFIX_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(group) - .action("addtempsuffix " + priority + " " + args.get(1) + " " + duration) - .build().submit(plugin, sender); - } - - save(group, sender, plugin); - return CommandResult.SUCCESS; - } catch (ObjectAlreadyHasException e) { - Message.ALREADY_HAS_SUFFIX.send(sender, group.getDisplayName()); - return CommandResult.STATE_ERROR; - } - } -} diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupClearMeta.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupClearMeta.java deleted file mode 100644 index f0885ee47..000000000 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupClearMeta.java +++ /dev/null @@ -1,79 +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.commands.group.subcommands; - -import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; -import me.lucko.luckperms.constants.Message; -import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntry; -import me.lucko.luckperms.groups.Group; -import me.lucko.luckperms.utils.ArgumentChecker; - -import java.util.List; -import java.util.stream.Collectors; - -public class GroupClearMeta extends SubCommand { - public GroupClearMeta() { - super("clearmeta", "Clears the groups's meta", Permission.GROUP_CLEARMETA, Predicate.notInRange(0, 2), - Arg.list( - Arg.create("server", false, "the server name to filter by"), - Arg.create("world", false, "the world name to filter by") - ) - ); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { - int before = group.getNodes().size(); - - if (args.size() == 0) { - group.clearMeta(); - } else { - final String server = args.get(0); - if (ArgumentChecker.checkServer(server)) { - Message.SERVER_INVALID_ENTRY.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (args.size() == 2) { - final String world = args.get(1); - group.clearMeta(server, world); - - } else { - group.clearMeta(server); - } - } - - int changed = before - group.getNodes().size(); - if (changed == 1) { - Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, group.getName(), changed); - } else { - Message.META_CLEAR_SUCCESS.send(sender, group.getName(), changed); - } - - LogEntry.build().actor(sender).acted(group).action("clearmeta " + args.stream().collect(Collectors.joining(" "))).build().submit(plugin, sender); - save(group, sender, plugin); - return CommandResult.SUCCESS; - } -} diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemovePrefix.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemovePrefix.java deleted file mode 100644 index ac8ff46bd..000000000 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemovePrefix.java +++ /dev/null @@ -1,153 +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.commands.group.subcommands; - -import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.api.Node; -import me.lucko.luckperms.commands.*; -import me.lucko.luckperms.constants.Message; -import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntry; -import me.lucko.luckperms.exceptions.ObjectLacksException; -import me.lucko.luckperms.groups.Group; -import me.lucko.luckperms.utils.ArgumentChecker; - -import java.util.ArrayList; -import java.util.List; - -public class GroupRemovePrefix extends SubCommand { - public GroupRemovePrefix() { - super("removeprefix", "Removes a prefix from the group", Permission.GROUP_REMOVEPREFIX, Predicate.notInRange(2, 4), - Arg.list( - Arg.create("priority", true, "the priority to remove the prefix at"), - Arg.create("prefix", true, "the prefix string to remove"), - Arg.create("server", false, "the server to remove the prefix on"), - Arg.create("world", false, "the world to remove the prefix on") - ) - ); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { - final String prefix = args.get(1).replace("{SPACE}", " "); - int priority; - try { - priority = Integer.parseInt(args.get(0)); - } catch (NumberFormatException e) { - Message.META_INVALID_PRIORITY.send(sender, args.get(0)); - return CommandResult.INVALID_ARGS; - } - - if (prefix.equalsIgnoreCase("null")) { - String server = null; - String world = null; - - if (args.size() >= 3) { - server = args.get(2).toLowerCase(); - if (ArgumentChecker.checkServer(server)) { - Message.SERVER_INVALID_ENTRY.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (args.size() != 3) { - world = args.get(3).toLowerCase(); - } - } - - List toRemove = new ArrayList<>(); - for (Node node : group.getNodes()) { - if (!node.isPrefix()) continue; - if (node.getPrefix().getKey() != priority) continue; - if (node.isTemporary()) continue; - - if (node.getServer().isPresent()) { - if (server == null) continue; - if (!node.getServer().get().equalsIgnoreCase(server)) continue; - } else { - if (server != null) continue; - } - - if (node.getWorld().isPresent()) { - if (world == null) continue; - if (!node.getWorld().get().equalsIgnoreCase(world)) continue; - } else { - if (world != null) continue; - } - - toRemove.add(node); - } - - toRemove.forEach(n -> { - try { - group.unsetPermission(n); - } catch (ObjectLacksException ignored) {} - }); - - Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); - save(group, sender, plugin); - return CommandResult.SUCCESS; - - } else { - - final String node = "prefix." + priority + "." + ArgumentChecker.escapeCharacters(prefix); - - 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) { - group.unsetPermission(node, server); - Message.REMOVEPREFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server); - LogEntry.build().actor(sender).acted(group) - .action("removeprefix " + priority + " " + args.get(1) + " " + server) - .build().submit(plugin, sender); - } else { - final String world = args.get(3).toLowerCase(); - group.unsetPermission(node, server, world); - Message.REMOVEPREFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server, world); - LogEntry.build().actor(sender).acted(group) - .action("removeprefix " + priority + " " + args.get(1) + " " + server + " " + world) - .build().submit(plugin, sender); - } - - } else { - group.unsetPermission(node); - Message.REMOVEPREFIX_SUCCESS.send(sender, group.getDisplayName(), prefix, priority); - LogEntry.build().actor(sender).acted(group) - .action("removeprefix " + priority + " " + args.get(1)) - .build().submit(plugin, sender); - } - - save(group, sender, plugin); - return CommandResult.SUCCESS; - } catch (ObjectLacksException e) { - Message.DOES_NOT_HAVE_PREFIX.send(sender, group.getDisplayName()); - return CommandResult.STATE_ERROR; - } - } - } -} diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemoveSuffix.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemoveSuffix.java deleted file mode 100644 index 6e0a1a1f6..000000000 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemoveSuffix.java +++ /dev/null @@ -1,153 +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.commands.group.subcommands; - -import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.api.Node; -import me.lucko.luckperms.commands.*; -import me.lucko.luckperms.constants.Message; -import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntry; -import me.lucko.luckperms.exceptions.ObjectLacksException; -import me.lucko.luckperms.groups.Group; -import me.lucko.luckperms.utils.ArgumentChecker; - -import java.util.ArrayList; -import java.util.List; - -public class GroupRemoveSuffix extends SubCommand { - public GroupRemoveSuffix() { - super("removesuffix", "Removes a suffix from the group", Permission.GROUP_REMOVESUFFIX, Predicate.notInRange(2, 4), - Arg.list( - Arg.create("priority", true, "the priority to remove the suffix at"), - Arg.create("suffix", true, "the suffix string to remove"), - Arg.create("server", false, "the server to remove the suffix on"), - Arg.create("world", false, "the world to remove the suffix on") - ) - ); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { - final String suffix = args.get(1).replace("{SPACE}", " "); - int priority; - try { - priority = Integer.parseInt(args.get(0)); - } catch (NumberFormatException e) { - Message.META_INVALID_PRIORITY.send(sender, args.get(0)); - return CommandResult.INVALID_ARGS; - } - - if (suffix.equalsIgnoreCase("null")) { - String server = null; - String world = null; - - if (args.size() >= 3) { - server = args.get(2).toLowerCase(); - if (ArgumentChecker.checkServer(server)) { - Message.SERVER_INVALID_ENTRY.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (args.size() != 3) { - world = args.get(3).toLowerCase(); - } - } - - List toRemove = new ArrayList<>(); - for (Node node : group.getNodes()) { - if (!node.isSuffix()) continue; - if (node.getSuffix().getKey() != priority) continue; - if (node.isTemporary()) continue; - - if (node.getServer().isPresent()) { - if (server == null) continue; - if (!node.getServer().get().equalsIgnoreCase(server)) continue; - } else { - if (server != null) continue; - } - - if (node.getWorld().isPresent()) { - if (world == null) continue; - if (!node.getWorld().get().equalsIgnoreCase(world)) continue; - } else { - if (world != null) continue; - } - - toRemove.add(node); - } - - toRemove.forEach(n -> { - try { - group.unsetPermission(n); - } catch (ObjectLacksException ignored) {} - }); - - Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); - save(group, sender, plugin); - return CommandResult.SUCCESS; - - } else { - - final String node = "suffix." + priority + "." + ArgumentChecker.escapeCharacters(suffix); - - 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) { - group.unsetPermission(node, server); - Message.REMOVESUFFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server); - LogEntry.build().actor(sender).acted(group) - .action("removesuffix " + priority + " " + args.get(1) + " " + server) - .build().submit(plugin, sender); - } else { - final String world = args.get(3).toLowerCase(); - group.unsetPermission(node, server, world); - Message.REMOVESUFFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server, world); - LogEntry.build().actor(sender).acted(group) - .action("removesuffix " + priority + " " + args.get(1) + " " + server + " " + world) - .build().submit(plugin, sender); - } - - } else { - group.unsetPermission(node); - Message.REMOVESUFFIX_SUCCESS.send(sender, group.getDisplayName(), suffix, priority); - LogEntry.build().actor(sender).acted(group) - .action("removesuffix " + priority + " " + args.get(1)) - .build().submit(plugin, sender); - } - - save(group, sender, plugin); - return CommandResult.SUCCESS; - } catch (ObjectLacksException e) { - Message.DOES_NOT_HAVE_SUFFIX.send(sender, group.getDisplayName()); - return CommandResult.STATE_ERROR; - } - } - } -} diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemoveTempPrefix.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemoveTempPrefix.java deleted file mode 100644 index 3d2f713c2..000000000 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemoveTempPrefix.java +++ /dev/null @@ -1,154 +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.commands.group.subcommands; - -import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.api.Node; -import me.lucko.luckperms.commands.*; -import me.lucko.luckperms.constants.Message; -import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntry; -import me.lucko.luckperms.exceptions.ObjectLacksException; -import me.lucko.luckperms.groups.Group; -import me.lucko.luckperms.utils.ArgumentChecker; - -import java.util.ArrayList; -import java.util.List; - -public class GroupRemoveTempPrefix extends SubCommand { - public GroupRemoveTempPrefix() { - super("removetempprefix", "Removes a temporary prefix from the group", Permission.GROUP_REMOVE_TEMP_PREFIX, - Predicate.notInRange(2, 4), - Arg.list( - Arg.create("priority", true, "the priority to remove the prefix at"), - Arg.create("prefix", true, "the prefix string to remove"), - Arg.create("server", false, "the server to remove the prefix on"), - Arg.create("world", false, "the world to remove the prefix on") - ) - ); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { - final String prefix = args.get(1).replace("{SPACE}", " "); - int priority; - try { - priority = Integer.parseInt(args.get(0)); - } catch (NumberFormatException e) { - Message.META_INVALID_PRIORITY.send(sender, args.get(0)); - return CommandResult.INVALID_ARGS; - } - - if (prefix.equalsIgnoreCase("null")) { - String server = null; - String world = null; - - if (args.size() >= 3) { - server = args.get(2).toLowerCase(); - if (ArgumentChecker.checkServer(server)) { - Message.SERVER_INVALID_ENTRY.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (args.size() != 3) { - world = args.get(3).toLowerCase(); - } - } - - List toRemove = new ArrayList<>(); - for (Node node : group.getNodes()) { - if (!node.isPrefix()) continue; - if (node.getPrefix().getKey() != priority) continue; - if (node.isPermanent()) continue; - - if (node.getServer().isPresent()) { - if (server == null) continue; - if (!node.getServer().get().equalsIgnoreCase(server)) continue; - } else { - if (server != null) continue; - } - - if (node.getWorld().isPresent()) { - if (world == null) continue; - if (!node.getWorld().get().equalsIgnoreCase(world)) continue; - } else { - if (world != null) continue; - } - - toRemove.add(node); - } - - toRemove.forEach(n -> { - try { - group.unsetPermission(n); - } catch (ObjectLacksException ignored) {} - }); - - Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); - save(group, sender, plugin); - return CommandResult.SUCCESS; - - } else { - - final String node = "prefix." + priority + "." + ArgumentChecker.escapeCharacters(prefix); - - 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) { - group.unsetPermission(node, server, true); - Message.REMOVE_TEMP_PREFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server); - LogEntry.build().actor(sender).acted(group) - .action("removetempprefix " + priority + " " + args.get(1) + " " + server) - .build().submit(plugin, sender); - } else { - final String world = args.get(3).toLowerCase(); - group.unsetPermission(node, server, world, true); - Message.REMOVE_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server, world); - LogEntry.build().actor(sender).acted(group) - .action("removetempprefix " + priority + " " + args.get(1) + " " + server + " " + world) - .build().submit(plugin, sender); - } - - } else { - group.unsetPermission(node, true); - Message.REMOVE_TEMP_PREFIX_SUCCESS.send(sender, group.getDisplayName(), prefix, priority); - LogEntry.build().actor(sender).acted(group) - .action("removetempprefix " + priority + " " + args.get(1)) - .build().submit(plugin, sender); - } - - save(group, sender, plugin); - return CommandResult.SUCCESS; - } catch (ObjectLacksException e) { - Message.DOES_NOT_HAVE_PREFIX.send(sender, group.getDisplayName()); - return CommandResult.STATE_ERROR; - } - } - } -} diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemoveTempSuffix.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemoveTempSuffix.java deleted file mode 100644 index 235ff4371..000000000 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupRemoveTempSuffix.java +++ /dev/null @@ -1,154 +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.commands.group.subcommands; - -import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.api.Node; -import me.lucko.luckperms.commands.*; -import me.lucko.luckperms.constants.Message; -import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntry; -import me.lucko.luckperms.exceptions.ObjectLacksException; -import me.lucko.luckperms.groups.Group; -import me.lucko.luckperms.utils.ArgumentChecker; - -import java.util.ArrayList; -import java.util.List; - -public class GroupRemoveTempSuffix extends SubCommand { - public GroupRemoveTempSuffix() { - super("removetempsuffix", "Removes a temporary suffix from the group", Permission.GROUP_REMOVE_TEMP_SUFFIX, - Predicate.notInRange(2, 4), - Arg.list( - Arg.create("priority", true, "the priority to remove the suffix at"), - Arg.create("suffix", true, "the suffix string to remove"), - Arg.create("server", false, "the server to remove the suffix on"), - Arg.create("world", false, "the world to remove the suffix on") - ) - ); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { - final String suffix = args.get(1).replace("{SPACE}", " "); - int priority; - try { - priority = Integer.parseInt(args.get(0)); - } catch (NumberFormatException e) { - Message.META_INVALID_PRIORITY.send(sender, args.get(0)); - return CommandResult.INVALID_ARGS; - } - - if (suffix.equalsIgnoreCase("null")) { - String server = null; - String world = null; - - if (args.size() >= 3) { - server = args.get(2).toLowerCase(); - if (ArgumentChecker.checkServer(server)) { - Message.SERVER_INVALID_ENTRY.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (args.size() != 3) { - world = args.get(3).toLowerCase(); - } - } - - List toRemove = new ArrayList<>(); - for (Node node : group.getNodes()) { - if (!node.isSuffix()) continue; - if (node.getSuffix().getKey() != priority) continue; - if (node.isPermanent()) continue; - - if (node.getServer().isPresent()) { - if (server == null) continue; - if (!node.getServer().get().equalsIgnoreCase(server)) continue; - } else { - if (server != null) continue; - } - - if (node.getWorld().isPresent()) { - if (world == null) continue; - if (!node.getWorld().get().equalsIgnoreCase(world)) continue; - } else { - if (world != null) continue; - } - - toRemove.add(node); - } - - toRemove.forEach(n -> { - try { - group.unsetPermission(n); - } catch (ObjectLacksException ignored) {} - }); - - Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); - save(group, sender, plugin); - return CommandResult.SUCCESS; - - } else { - - final String node = "suffix." + priority + "." + ArgumentChecker.escapeCharacters(suffix); - - 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) { - group.unsetPermission(node, server, true); - Message.REMOVE_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server); - LogEntry.build().actor(sender).acted(group) - .action("removetempsuffix " + priority + " " + args.get(1) + " " + server) - .build().submit(plugin, sender); - } else { - final String world = args.get(3).toLowerCase(); - group.unsetPermission(node, server, world, true); - Message.REMOVE_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server, world); - LogEntry.build().actor(sender).acted(group) - .action("removetempsuffix " + priority + " " + args.get(1) + " " + server + " " + world) - .build().submit(plugin, sender); - } - - } else { - group.unsetPermission(node, true); - Message.REMOVE_TEMP_SUFFIX_SUCCESS.send(sender, group.getDisplayName(), suffix, priority); - LogEntry.build().actor(sender).acted(group) - .action("removetempsuffix " + priority + " " + args.get(1)) - .build().submit(plugin, sender); - } - - save(group, sender, plugin); - return CommandResult.SUCCESS; - } catch (ObjectLacksException e) { - Message.DOES_NOT_HAVE_SUFFIX.send(sender, group.getDisplayName()); - return CommandResult.STATE_ERROR; - } - } - } -} diff --git a/common/src/main/java/me/lucko/luckperms/commands/meta/MetaCommands.java b/common/src/main/java/me/lucko/luckperms/commands/meta/MetaCommands.java new file mode 100644 index 000000000..21117c6e6 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/commands/meta/MetaCommands.java @@ -0,0 +1,114 @@ +/* + * 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.commands.meta; + +import com.google.common.collect.ImmutableList; +import me.lucko.luckperms.LuckPermsPlugin; +import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.meta.subcommands.*; +import me.lucko.luckperms.constants.Message; +import me.lucko.luckperms.core.PermissionHolder; +import me.lucko.luckperms.users.User; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +public class MetaCommands extends SubCommand { + private final List subCommands = ImmutableList.builder() + .add(new MetaInfo()) + .add(new MetaAddPrefix()) + .add(new MetaAddSuffix()) + .add(new MetaRemovePrefix()) + .add(new MetaRemoveSuffix()) + .add(new MetaAddTempPrefix()) + .add(new MetaAddTempSuffix()) + .add(new MetaRemoveTempPrefix()) + .add(new MetaRemoveTempSuffix()) + .add(new MetaClear()) + .build(); + + public MetaCommands() { + super("meta", "Edit metadata values", null, Predicate.alwaysFalse(), null); + } + + @Override + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List args, String label) { + boolean user = t instanceof User; + + if (args.size() == 0) { + sendUsageMeta(sender, user, label); + return CommandResult.INVALID_ARGS; + } + + Optional o = subCommands.stream() + .filter(s -> s.getName().equalsIgnoreCase(args.get(0))) + .limit(1) + .findAny(); + + if (!o.isPresent()) { + Message.COMMAND_NOT_RECOGNISED.send(sender); + return CommandResult.INVALID_ARGS; + } + + final MetaSubCommand sub = o.get(); + if (!sub.isAuthorized(sender, user)) { + Message.COMMAND_NO_PERMISSION.send(sender); + return CommandResult.NO_PERMISSION; + } + + List strippedArgs = new ArrayList<>(); + if (args.size() > 1) { + strippedArgs.addAll(args.subList(1, args.size())); + } + + if (sub.getIsArgumentInvalid().test(strippedArgs.size())) { + sub.sendDetailedUsage(sender); + return CommandResult.INVALID_ARGS; + } + + return sub.execute(plugin, sender, t, strippedArgs); + } + + private void sendUsageMeta(Sender sender, boolean user, String label) { + List subs = subCommands.stream() + .filter(s -> s.isAuthorized(sender, user)) + .collect(Collectors.toList()); + + if (subs.size() > 0) { + if (user) { + Util.sendPluginMessage(sender, "&bMeta Sub Commands: &7(" + String.format("/%s user meta ...)", label)); + } else { + Util.sendPluginMessage(sender, "&bMeta Sub Commands: &7(" + String.format("/%s group meta ...)", label)); + } + + for (MetaSubCommand s : subs) { + s.sendUsage(sender); + } + + } else { + Message.COMMAND_NO_PERMISSION.send(sender); + } + } +} diff --git a/common/src/main/java/me/lucko/luckperms/commands/meta/MetaSubCommand.java b/common/src/main/java/me/lucko/luckperms/commands/meta/MetaSubCommand.java new file mode 100644 index 000000000..20a03ee6b --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/commands/meta/MetaSubCommand.java @@ -0,0 +1,124 @@ +/* + * 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.commands.meta; + +import com.google.common.collect.ImmutableList; +import lombok.AllArgsConstructor; +import lombok.Getter; +import me.lucko.luckperms.LuckPermsPlugin; +import me.lucko.luckperms.commands.Arg; +import me.lucko.luckperms.commands.CommandResult; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.Util; +import me.lucko.luckperms.constants.Message; +import me.lucko.luckperms.constants.Permission; +import me.lucko.luckperms.core.PermissionHolder; +import me.lucko.luckperms.groups.Group; +import me.lucko.luckperms.users.User; + +import java.util.List; +import java.util.function.Predicate; + +@Getter +@AllArgsConstructor +public abstract class MetaSubCommand { + /** + * The name of the sub command + */ + private final String name; + + /** + * A brief description of what the sub command does + */ + private final String description; + + /** + * The permission needed to use this command + */ + private final Permission userPermission; + private final Permission groupPermission; + + /** + * Predicate to test if the argument length given is invalid + */ + private final Predicate isArgumentInvalid; + + private final ImmutableList args; + + public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args); + + public void sendUsage(Sender sender) { + String usage = ""; + if (args != null) { + usage += "&3 - &7"; + for (Arg arg : args) { + usage += arg.asPrettyString() + " "; + } + } + + Util.sendPluginMessage(sender, "&3> &a" + getName() + usage); + } + + public void sendDetailedUsage(Sender sender) { + Util.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName()); + Util.sendPluginMessage(sender, "&b> &7" + getDescription()); + if (args != null) { + Util.sendPluginMessage(sender, "&3Arguments:"); + for (Arg arg : args) { + Util.sendPluginMessage(sender, "&b- " + arg.asPrettyString() + "&3 -> &7" + arg.getDescription()); + } + } + } + + public boolean isAuthorized(Sender sender, boolean user) { + return user ? userPermission.isAuthorized(sender) : groupPermission.isAuthorized(sender); + } + + protected static void save(PermissionHolder holder, Sender sender, LuckPermsPlugin plugin) { + if (holder instanceof User) { + User user = ((User) holder); + if (plugin.getDatastore().saveUser(user)) { + Message.USER_SAVE_SUCCESS.send(sender); + } else { + Message.USER_SAVE_ERROR.send(sender); + } + + user.refreshPermissions(); + return; + } + + if (holder instanceof Group) { + Group group = ((Group) holder); + if (plugin.getDatastore().saveGroup(group)) { + Message.GROUP_SAVE_SUCCESS.send(sender); + } else { + Message.GROUP_SAVE_ERROR.send(sender); + } + + plugin.runUpdateTask(); + return; + } + + throw new IllegalArgumentException(); + } +} diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupAddPrefix.java b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaAddPrefix.java similarity index 67% rename from common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupAddPrefix.java rename to common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaAddPrefix.java index abbad5817..41c2c030b 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupAddPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaAddPrefix.java @@ -20,22 +20,26 @@ * SOFTWARE. */ -package me.lucko.luckperms.commands.group.subcommands; +package me.lucko.luckperms.commands.meta.subcommands; import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.Arg; +import me.lucko.luckperms.commands.CommandResult; +import me.lucko.luckperms.commands.Predicate; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.meta.MetaSubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; +import me.lucko.luckperms.core.PermissionHolder; import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; -import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.utils.ArgumentChecker; import java.util.List; -public class GroupAddPrefix extends SubCommand { - public GroupAddPrefix() { - super("addprefix", "Adds a prefix to the group", Permission.GROUP_ADDPREFIX, Predicate.notInRange(2, 4), +public class MetaAddPrefix extends MetaSubCommand { + public MetaAddPrefix() { + super("addprefix", "Adds a prefix", Permission.USER_ADDPREFIX, Permission.GROUP_ADDPREFIX, Predicate.notInRange(2, 4), Arg.list( Arg.create("priority", true, "the priority to add the prefix at"), Arg.create("prefix", true, "the prefix string"), @@ -46,7 +50,7 @@ public class GroupAddPrefix 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) { final String prefix = args.get(1).replace("{SPACE}", " "); int priority; try { @@ -67,32 +71,32 @@ public class GroupAddPrefix extends SubCommand { } if (args.size() == 3) { - group.setPermission(node, true, server); - Message.ADDPREFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server); - LogEntry.build().actor(sender).acted(group) - .action("addprefix " + priority + " " + args.get(1) + " " + server) + holder.setPermission(node, true, server); + Message.ADDPREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server); + LogEntry.build().actor(sender).acted(holder) + .action("meta addprefix " + priority + " " + args.get(1) + " " + server) .build().submit(plugin, sender); } else { final String world = args.get(3).toLowerCase(); - group.setPermission(node, true, server, world); - Message.ADDPREFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server, world); - LogEntry.build().actor(sender).acted(group) - .action("addprefix " + priority + " " + args.get(1) + " " + server + " " + world) + holder.setPermission(node, true, server, world); + Message.ADDPREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, world); + LogEntry.build().actor(sender).acted(holder) + .action("meta addprefix " + priority + " " + args.get(1) + " " + server + " " + world) .build().submit(plugin, sender); } } else { - group.setPermission(node, true); - Message.ADDPREFIX_SUCCESS.send(sender, group.getDisplayName(), prefix, priority); - LogEntry.build().actor(sender).acted(group) - .action("addprefix " + priority + " " + args.get(1)) + holder.setPermission(node, true); + Message.ADDPREFIX_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority); + LogEntry.build().actor(sender).acted(holder) + .action("meta addprefix " + priority + " " + args.get(1)) .build().submit(plugin, sender); } - save(group, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectAlreadyHasException e) { - Message.ALREADY_HAS_PREFIX.send(sender, group.getDisplayName()); + Message.ALREADY_HAS_PREFIX.send(sender, holder.getFriendlyName()); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupAddSuffix.java b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaAddSuffix.java similarity index 67% rename from common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupAddSuffix.java rename to common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaAddSuffix.java index 83033f4d6..296c45681 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupAddSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaAddSuffix.java @@ -20,22 +20,26 @@ * SOFTWARE. */ -package me.lucko.luckperms.commands.group.subcommands; +package me.lucko.luckperms.commands.meta.subcommands; import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.Arg; +import me.lucko.luckperms.commands.CommandResult; +import me.lucko.luckperms.commands.Predicate; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.meta.MetaSubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; +import me.lucko.luckperms.core.PermissionHolder; import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; -import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.utils.ArgumentChecker; import java.util.List; -public class GroupAddSuffix extends SubCommand { - public GroupAddSuffix() { - super("addsuffix", "Adds a suffix to the group", Permission.GROUP_ADDSUFFIX, Predicate.notInRange(2, 4), +public class MetaAddSuffix extends MetaSubCommand { + public MetaAddSuffix() { + super("addsuffix", "Adds a suffix", Permission.USER_ADDSUFFIX, Permission.GROUP_ADDSUFFIX, Predicate.notInRange(2, 4), Arg.list( Arg.create("priority", true, "the priority to add the suffix at"), Arg.create("suffix", true, "the suffix string"), @@ -46,7 +50,7 @@ public class GroupAddSuffix 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) { final String suffix = args.get(1).replace("{SPACE}", " "); int priority; try { @@ -67,32 +71,32 @@ public class GroupAddSuffix extends SubCommand { } if (args.size() == 3) { - group.setPermission(node, true, server); - Message.ADDSUFFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server); - LogEntry.build().actor(sender).acted(group) - .action("addsuffix " + priority + " " + args.get(1) + " " + server) + holder.setPermission(node, true, server); + Message.ADDSUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server); + LogEntry.build().actor(sender).acted(holder) + .action("meta addsuffix " + priority + " " + args.get(1) + " " + server) .build().submit(plugin, sender); } else { final String world = args.get(3).toLowerCase(); - group.setPermission(node, true, server, world); - Message.ADDSUFFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server, world); - LogEntry.build().actor(sender).acted(group) - .action("addsuffix " + priority + " " + args.get(1) + " " + server + " " + world) + holder.setPermission(node, true, server, world); + Message.ADDSUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, world); + LogEntry.build().actor(sender).acted(holder) + .action("meta addsuffix " + priority + " " + args.get(1) + " " + server + " " + world) .build().submit(plugin, sender); } } else { - group.setPermission(node, true); - Message.ADDSUFFIX_SUCCESS.send(sender, group.getDisplayName(), suffix, priority); - LogEntry.build().actor(sender).acted(group) - .action("addsuffix " + priority + " " + args.get(1)) + holder.setPermission(node, true); + Message.ADDSUFFIX_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority); + LogEntry.build().actor(sender).acted(holder) + .action("meta addsuffix " + priority + " " + args.get(1)) .build().submit(plugin, sender); } - save(group, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectAlreadyHasException e) { - Message.ALREADY_HAS_SUFFIX.send(sender, group.getDisplayName()); + Message.ALREADY_HAS_SUFFIX.send(sender, holder.getFriendlyName()); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddTempPrefix.java b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaAddTempPrefix.java similarity index 68% rename from common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddTempPrefix.java rename to common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaAddTempPrefix.java index 6379833d8..2455313a1 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddTempPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaAddTempPrefix.java @@ -20,23 +20,27 @@ * SOFTWARE. */ -package me.lucko.luckperms.commands.user.subcommands; +package me.lucko.luckperms.commands.meta.subcommands; import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.Arg; +import me.lucko.luckperms.commands.CommandResult; +import me.lucko.luckperms.commands.Predicate; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.meta.MetaSubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; +import me.lucko.luckperms.core.PermissionHolder; import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; -import me.lucko.luckperms.users.User; import me.lucko.luckperms.utils.ArgumentChecker; import me.lucko.luckperms.utils.DateUtil; import java.util.List; -public class UserAddTempPrefix extends SubCommand { - public UserAddTempPrefix() { - super("addtempprefix", "Adds a prefix to the user temporarily", Permission.USER_ADD_TEMP_PREFIX, Predicate.notInRange(3, 5), +public class MetaAddTempPrefix extends MetaSubCommand { + public MetaAddTempPrefix() { + super("addtempprefix", "Adds a prefix temporarily", Permission.USER_ADD_TEMP_PREFIX, Permission.GROUP_ADD_TEMP_PREFIX, Predicate.notInRange(3, 5), Arg.list( Arg.create("priority", true, "the priority to add the prefix at"), Arg.create("prefix", true, "the prefix string"), @@ -48,7 +52,7 @@ public class UserAddTempPrefix 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) { final String prefix = args.get(1).replace("{SPACE}", " "); int priority; try { @@ -86,32 +90,32 @@ public class UserAddTempPrefix extends SubCommand { } if (args.size() == 4) { - user.setPermission(node, true, server, duration); - Message.ADD_TEMP_PREFIX_SERVER_SUCCESS.send(sender, user.getName(), prefix, priority, server, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(user) - .action("addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server) + holder.setPermission(node, true, server, duration); + Message.ADD_TEMP_PREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, DateUtil.formatDateDiff(duration)); + LogEntry.build().actor(sender).acted(holder) + .action("meta addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server) .build().submit(plugin, sender); } else { final String world = args.get(4).toLowerCase(); - user.setPermission(node, true, server, world, duration); - Message.ADD_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), prefix, priority, server, world, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(user) - .action("addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world) + holder.setPermission(node, true, server, world, duration); + Message.ADD_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, world, DateUtil.formatDateDiff(duration)); + LogEntry.build().actor(sender).acted(holder) + .action("meta addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world) .build().submit(plugin, sender); } } else { - user.setPermission(node, true, duration); - Message.ADD_TEMP_PREFIX_SUCCESS.send(sender, user.getName(), prefix, priority, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(user) - .action("addtempprefix " + priority + " " + args.get(1) + " " + duration) + holder.setPermission(node, true, duration); + Message.ADD_TEMP_PREFIX_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, DateUtil.formatDateDiff(duration)); + LogEntry.build().actor(sender).acted(holder) + .action("meta addtempprefix " + priority + " " + args.get(1) + " " + duration) .build().submit(plugin, sender); } - save(user, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectAlreadyHasException e) { - Message.ALREADY_HAS_PREFIX.send(sender, user.getName()); + Message.ALREADY_HAS_PREFIX.send(sender, holder.getFriendlyName()); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddTempSuffix.java b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaAddTempSuffix.java similarity index 68% rename from common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddTempSuffix.java rename to common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaAddTempSuffix.java index db32bee33..d5704660e 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddTempSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaAddTempSuffix.java @@ -20,23 +20,27 @@ * SOFTWARE. */ -package me.lucko.luckperms.commands.user.subcommands; +package me.lucko.luckperms.commands.meta.subcommands; import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.Arg; +import me.lucko.luckperms.commands.CommandResult; +import me.lucko.luckperms.commands.Predicate; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.meta.MetaSubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; +import me.lucko.luckperms.core.PermissionHolder; import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; -import me.lucko.luckperms.users.User; import me.lucko.luckperms.utils.ArgumentChecker; import me.lucko.luckperms.utils.DateUtil; import java.util.List; -public class UserAddTempSuffix extends SubCommand { - public UserAddTempSuffix() { - super("addtempsuffix", "Adds a suffix to the user temporarily", Permission.USER_ADD_TEMP_SUFFIX, Predicate.notInRange(3, 5), +public class MetaAddTempSuffix extends MetaSubCommand { + public MetaAddTempSuffix() { + super("addtempsuffix", "Adds a suffix temporarily", Permission.USER_ADD_TEMP_SUFFIX, Permission.GROUP_ADD_TEMP_SUFFIX, Predicate.notInRange(3, 5), Arg.list( Arg.create("priority", true, "the priority to add the suffix at"), Arg.create("suffix", true, "the suffix string"), @@ -48,7 +52,7 @@ public class UserAddTempSuffix 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) { final String suffix = args.get(1).replace("{SPACE}", " "); int priority; try { @@ -86,32 +90,32 @@ public class UserAddTempSuffix extends SubCommand { } if (args.size() == 4) { - user.setPermission(node, true, server, duration); - Message.ADD_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, user.getName(), suffix, priority, server, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(user) - .action("addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server) + holder.setPermission(node, true, server, duration); + Message.ADD_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, DateUtil.formatDateDiff(duration)); + LogEntry.build().actor(sender).acted(holder) + .action("meta addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server) .build().submit(plugin, sender); } else { final String world = args.get(4).toLowerCase(); - user.setPermission(node, true, server, world, duration); - Message.ADD_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), suffix, priority, server, world, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(user) - .action("addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world) + holder.setPermission(node, true, server, world, duration); + Message.ADD_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, world, DateUtil.formatDateDiff(duration)); + LogEntry.build().actor(sender).acted(holder) + .action("meta addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world) .build().submit(plugin, sender); } } else { - user.setPermission(node, true, duration); - Message.ADD_TEMP_SUFFIX_SUCCESS.send(sender, user.getName(), suffix, priority, DateUtil.formatDateDiff(duration)); - LogEntry.build().actor(sender).acted(user) - .action("addtempsuffix " + priority + " " + args.get(1) + " " + duration) + holder.setPermission(node, true, duration); + Message.ADD_TEMP_SUFFIX_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, DateUtil.formatDateDiff(duration)); + LogEntry.build().actor(sender).acted(holder) + .action("meta addtempsuffix " + priority + " " + args.get(1) + " " + duration) .build().submit(plugin, sender); } - save(user, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectAlreadyHasException e) { - Message.ALREADY_HAS_SUFFIX.send(sender, user.getName()); + Message.ALREADY_HAS_SUFFIX.send(sender, holder.getFriendlyName()); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserClearMeta.java b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaClear.java similarity index 65% rename from common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserClearMeta.java rename to common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaClear.java index f12378934..60ec680c5 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserClearMeta.java +++ b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaClear.java @@ -20,22 +20,26 @@ * SOFTWARE. */ -package me.lucko.luckperms.commands.user.subcommands; +package me.lucko.luckperms.commands.meta.subcommands; import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.Arg; +import me.lucko.luckperms.commands.CommandResult; +import me.lucko.luckperms.commands.Predicate; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.meta.MetaSubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; +import me.lucko.luckperms.core.PermissionHolder; import me.lucko.luckperms.data.LogEntry; -import me.lucko.luckperms.users.User; import me.lucko.luckperms.utils.ArgumentChecker; import java.util.List; import java.util.stream.Collectors; -public class UserClearMeta extends SubCommand { - public UserClearMeta() { - super("clearmeta", "Clears the user's meta", Permission.USER_CLEARMETA, Predicate.notInRange(0, 2), +public class MetaClear extends MetaSubCommand { + public MetaClear() { + super("clear", "Clears all chat meta", Permission.USER_CLEARMETA, Permission.GROUP_CLEARMETA, Predicate.notInRange(0, 2), Arg.list( Arg.create("server", false, "the server name to filter by"), Arg.create("world", false, "the world name to filter by") @@ -44,11 +48,11 @@ public class UserClearMeta extends SubCommand { } @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List args, String label) { - int before = user.getNodes().size(); + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args) { + int before = holder.getNodes().size(); if (args.size() == 0) { - user.clearMeta(); + holder.clearMeta(); } else { final String server = args.get(0); if (ArgumentChecker.checkServer(server)) { @@ -58,22 +62,22 @@ public class UserClearMeta extends SubCommand { if (args.size() == 2) { final String world = args.get(1); - user.clearMeta(server, world); + holder.clearMeta(server, world); } else { - user.clearMeta(server); + holder.clearMeta(server); } } - int changed = before - user.getNodes().size(); + int changed = before - holder.getNodes().size(); if (changed == 1) { - Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, user.getName(), changed); + Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), changed); } else { - Message.META_CLEAR_SUCCESS.send(sender, user.getName(), changed); + Message.META_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), changed); } - LogEntry.build().actor(sender).acted(user).action("clearmeta " + args.stream().collect(Collectors.joining(" "))).build().submit(plugin, sender); - save(user, sender, plugin); + LogEntry.build().actor(sender).acted(holder).action("meta clear " + args.stream().collect(Collectors.joining(" "))).build().submit(plugin, sender); + save(holder, sender, plugin); return CommandResult.SUCCESS; } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupChatMeta.java b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaInfo.java similarity index 75% rename from common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupChatMeta.java rename to common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaInfo.java index 3cb59d0c3..b3b3fcb15 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaInfo.java @@ -20,29 +20,33 @@ * SOFTWARE. */ -package me.lucko.luckperms.commands.group.subcommands; +package me.lucko.luckperms.commands.meta.subcommands; import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Node; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.CommandResult; +import me.lucko.luckperms.commands.Predicate; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.Util; +import me.lucko.luckperms.commands.meta.MetaSubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.groups.Group; +import me.lucko.luckperms.core.PermissionHolder; import java.util.*; -public class GroupChatMeta extends SubCommand { - public GroupChatMeta() { - super("chatmeta", "Lists the group's chat meta", Permission.GROUP_CHATMETA, Predicate.alwaysFalse(), null); +public class MetaInfo extends MetaSubCommand { + public MetaInfo() { + super("info", "Shows all chat meta", Permission.USER_CHATMETA, Permission.GROUP_CHATMETA, Predicate.alwaysFalse(), null); } @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) { SortedSet> prefixes = new TreeSet<>(Util.getMetaComparator().reversed()); SortedSet> suffixes = new TreeSet<>(Util.getMetaComparator().reversed()); - for (Node node : group.getAllNodes(null, Contexts.allowAll())) { + for (Node node : holder.getAllNodes(null, Contexts.allowAll())) { if (!node.isSuffix() && !node.isPrefix()) { continue; } @@ -67,18 +71,18 @@ public class GroupChatMeta extends SubCommand { } if (prefixes.isEmpty()) { - Message.CHAT_META_PREFIX_NONE.send(sender, group.getDisplayName()); + Message.CHAT_META_PREFIX_NONE.send(sender, holder.getFriendlyName()); } else { - Message.CHAT_META_PREFIX_HEADER.send(sender, group.getDisplayName()); + Message.CHAT_META_PREFIX_HEADER.send(sender, holder.getFriendlyName()); for (Map.Entry e : prefixes) { Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue()); } } if (suffixes.isEmpty()) { - Message.CHAT_META_SUFFIX_NONE.send(sender, group.getDisplayName()); + Message.CHAT_META_SUFFIX_NONE.send(sender, holder.getFriendlyName()); } else { - Message.CHAT_META_SUFFIX_HEADER.send(sender, group.getDisplayName()); + Message.CHAT_META_SUFFIX_HEADER.send(sender, holder.getFriendlyName()); for (Map.Entry e : suffixes) { Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue()); } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemovePrefix.java b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaRemovePrefix.java similarity index 72% rename from common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemovePrefix.java rename to common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaRemovePrefix.java index fda7fa3bd..55db000b2 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemovePrefix.java +++ b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaRemovePrefix.java @@ -20,35 +20,39 @@ * SOFTWARE. */ -package me.lucko.luckperms.commands.user.subcommands; +package me.lucko.luckperms.commands.meta.subcommands; import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.api.Node; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.Arg; +import me.lucko.luckperms.commands.CommandResult; +import me.lucko.luckperms.commands.Predicate; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.meta.MetaSubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; +import me.lucko.luckperms.core.PermissionHolder; import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectLacksException; -import me.lucko.luckperms.users.User; import me.lucko.luckperms.utils.ArgumentChecker; import java.util.ArrayList; import java.util.List; -public class UserRemovePrefix extends SubCommand { - public UserRemovePrefix() { - super("removeprefix", "Removes a prefix from the user", Permission.USER_REMOVEPREFIX, Predicate.notInRange(2, 4), +public class MetaRemovePrefix extends MetaSubCommand { + public MetaRemovePrefix() { + super("removeprefix", "Removes a prefix", Permission.USER_REMOVEPREFIX, Permission.GROUP_REMOVEPREFIX, Predicate.notInRange(2, 4), Arg.list( - Arg.create("priority", true, "the priority to remove the prefix at"), - Arg.create("prefix", true, "the prefix string to remove"), - Arg.create("server", false, "the server to remove the prefix on"), - Arg.create("world", false, "the world to remove the prefix on") + Arg.create("priority", true, "the priority to add the prefix at"), + Arg.create("prefix", true, "the prefix string"), + Arg.create("server", false, "the server to add the prefix on"), + Arg.create("world", false, "the world to add the prefix on") ) ); } @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) { final String prefix = args.get(1).replace("{SPACE}", " "); int priority; try { @@ -75,7 +79,7 @@ public class UserRemovePrefix extends SubCommand { } List toRemove = new ArrayList<>(); - for (Node node : user.getNodes()) { + for (Node node : holder.getNodes()) { if (!node.isPrefix()) continue; if (node.getPrefix().getKey() != priority) continue; if (node.isTemporary()) continue; @@ -99,12 +103,12 @@ public class UserRemovePrefix extends SubCommand { toRemove.forEach(n -> { try { - user.unsetPermission(n); + holder.unsetPermission(n); } catch (ObjectLacksException ignored) {} }); Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); - save(user, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } else { @@ -120,32 +124,32 @@ public class UserRemovePrefix extends SubCommand { } if (args.size() == 3) { - user.unsetPermission(node, server); - Message.REMOVEPREFIX_SERVER_SUCCESS.send(sender, user.getName(), prefix, priority, server); - LogEntry.build().actor(sender).acted(user) - .action("removeprefix " + priority + " " + args.get(1) + " " + server) + holder.unsetPermission(node, server); + Message.REMOVEPREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server); + LogEntry.build().actor(sender).acted(holder) + .action("meta removeprefix " + priority + " " + args.get(1) + " " + server) .build().submit(plugin, sender); } else { final String world = args.get(3).toLowerCase(); - user.unsetPermission(node, server, world); - Message.REMOVEPREFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), prefix, priority, server, world); - LogEntry.build().actor(sender).acted(user) - .action("removeprefix " + priority + " " + args.get(1) + " " + server + " " + world) + holder.unsetPermission(node, server, world); + Message.REMOVEPREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, world); + LogEntry.build().actor(sender).acted(holder) + .action("meta removeprefix " + priority + " " + args.get(1) + " " + server + " " + world) .build().submit(plugin, sender); } } else { - user.unsetPermission(node); - Message.REMOVEPREFIX_SUCCESS.send(sender, user.getName(), prefix, priority); - LogEntry.build().actor(sender).acted(user) - .action("removeprefix " + priority + " " + args.get(1)) + holder.unsetPermission(node); + Message.REMOVEPREFIX_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority); + LogEntry.build().actor(sender).acted(holder) + .action("meta removeprefix " + priority + " " + args.get(1)) .build().submit(plugin, sender); } - save(user, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectLacksException e) { - Message.DOES_NOT_HAVE_PREFIX.send(sender, user.getName()); + Message.DOES_NOT_HAVE_PREFIX.send(sender, holder.getFriendlyName()); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveSuffix.java b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaRemoveSuffix.java similarity index 72% rename from common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveSuffix.java rename to common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaRemoveSuffix.java index 420316a52..a577299d7 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaRemoveSuffix.java @@ -20,35 +20,39 @@ * SOFTWARE. */ -package me.lucko.luckperms.commands.user.subcommands; +package me.lucko.luckperms.commands.meta.subcommands; import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.api.Node; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.Arg; +import me.lucko.luckperms.commands.CommandResult; +import me.lucko.luckperms.commands.Predicate; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.meta.MetaSubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; +import me.lucko.luckperms.core.PermissionHolder; import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectLacksException; -import me.lucko.luckperms.users.User; import me.lucko.luckperms.utils.ArgumentChecker; import java.util.ArrayList; import java.util.List; -public class UserRemoveSuffix extends SubCommand { - public UserRemoveSuffix() { - super("removesuffix", "Removes a suffix from the user", Permission.USER_REMOVESUFFIX, Predicate.notInRange(2, 4), +public class MetaRemoveSuffix extends MetaSubCommand { + public MetaRemoveSuffix() { + super("removesuffix", "Removes a suffix", Permission.USER_REMOVESUFFIX, Permission.GROUP_REMOVESUFFIX, Predicate.notInRange(2, 4), Arg.list( - Arg.create("priority", true, "the priority to remove the suffix at"), - Arg.create("suffix", true, "the suffix string to remove"), - Arg.create("server", false, "the server to remove the suffix on"), - Arg.create("world", false, "the world to remove the suffix on") + Arg.create("priority", true, "the priority to add the suffix at"), + Arg.create("suffix", true, "the suffix string"), + Arg.create("server", false, "the server to add the suffix on"), + Arg.create("world", false, "the world to add the suffix on") ) ); } @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) { final String suffix = args.get(1).replace("{SPACE}", " "); int priority; try { @@ -75,7 +79,7 @@ public class UserRemoveSuffix extends SubCommand { } List toRemove = new ArrayList<>(); - for (Node node : user.getNodes()) { + for (Node node : holder.getNodes()) { if (!node.isSuffix()) continue; if (node.getSuffix().getKey() != priority) continue; if (node.isTemporary()) continue; @@ -99,12 +103,12 @@ public class UserRemoveSuffix extends SubCommand { toRemove.forEach(n -> { try { - user.unsetPermission(n); + holder.unsetPermission(n); } catch (ObjectLacksException ignored) {} }); Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); - save(user, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } else { @@ -120,32 +124,32 @@ public class UserRemoveSuffix extends SubCommand { } if (args.size() == 3) { - user.unsetPermission(node, server); - Message.REMOVESUFFIX_SERVER_SUCCESS.send(sender, user.getName(), suffix, priority, server); - LogEntry.build().actor(sender).acted(user) - .action("removesuffix " + priority + " " + args.get(1) + " " + server) + holder.unsetPermission(node, server); + Message.REMOVESUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server); + LogEntry.build().actor(sender).acted(holder) + .action("meta removesuffix " + priority + " " + args.get(1) + " " + server) .build().submit(plugin, sender); } else { final String world = args.get(3).toLowerCase(); - user.unsetPermission(node, server, world); - Message.REMOVESUFFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), suffix, priority, server, world); - LogEntry.build().actor(sender).acted(user) - .action("removesuffix " + priority + " " + args.get(1) + " " + server + " " + world) + holder.unsetPermission(node, server, world); + Message.REMOVESUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, world); + LogEntry.build().actor(sender).acted(holder) + .action("meta removesuffix " + priority + " " + args.get(1) + " " + server + " " + world) .build().submit(plugin, sender); } } else { - user.unsetPermission(node); - Message.REMOVESUFFIX_SUCCESS.send(sender, user.getName(), suffix, priority); - LogEntry.build().actor(sender).acted(user) - .action("removesuffix " + priority + " " + args.get(1)) + holder.unsetPermission(node); + Message.REMOVESUFFIX_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority); + LogEntry.build().actor(sender).acted(holder) + .action("meta removesuffix " + priority + " " + args.get(1)) .build().submit(plugin, sender); } - save(user, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectLacksException e) { - Message.DOES_NOT_HAVE_SUFFIX.send(sender, user.getName()); + Message.DOES_NOT_HAVE_SUFFIX.send(sender, holder.getFriendlyName()); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveTempPrefix.java b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaRemoveTempPrefix.java similarity index 72% rename from common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveTempPrefix.java rename to common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaRemoveTempPrefix.java index 733b766aa..972a5ee44 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveTempPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaRemoveTempPrefix.java @@ -20,36 +20,39 @@ * SOFTWARE. */ -package me.lucko.luckperms.commands.user.subcommands; +package me.lucko.luckperms.commands.meta.subcommands; import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.api.Node; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.Arg; +import me.lucko.luckperms.commands.CommandResult; +import me.lucko.luckperms.commands.Predicate; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.meta.MetaSubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; +import me.lucko.luckperms.core.PermissionHolder; import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectLacksException; -import me.lucko.luckperms.users.User; import me.lucko.luckperms.utils.ArgumentChecker; import java.util.ArrayList; import java.util.List; -public class UserRemoveTempPrefix extends SubCommand { - public UserRemoveTempPrefix() { - super("removetempprefix", "Removes the temporary prefix from a user", Permission.USER_REMOVE_TEMP_PREFIX, - Predicate.notInRange(2, 4), +public class MetaRemoveTempPrefix extends MetaSubCommand { + public MetaRemoveTempPrefix() { + super("removetempprefix", "Removes a temporary prefix", Permission.USER_REMOVE_TEMP_PREFIX, Permission.GROUP_REMOVE_TEMP_PREFIX, Predicate.notInRange(2, 4), Arg.list( - Arg.create("priority", true, "the priority to remove the prefix at"), - Arg.create("prefix", true, "the prefix string to remove"), - Arg.create("server", false, "the server to remove the prefix on"), - Arg.create("world", false, "the world to remove the prefix on") + Arg.create("priority", true, "the priority to add the prefix at"), + Arg.create("prefix", true, "the prefix string"), + Arg.create("server", false, "the server to add the prefix on"), + Arg.create("world", false, "the world to add the prefix on") ) ); } @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) { final String prefix = args.get(1).replace("{SPACE}", " "); int priority; try { @@ -76,7 +79,7 @@ public class UserRemoveTempPrefix extends SubCommand { } List toRemove = new ArrayList<>(); - for (Node node : user.getNodes()) { + for (Node node : holder.getNodes()) { if (!node.isPrefix()) continue; if (node.getPrefix().getKey() != priority) continue; if (node.isPermanent()) continue; @@ -100,12 +103,12 @@ public class UserRemoveTempPrefix extends SubCommand { toRemove.forEach(n -> { try { - user.unsetPermission(n); + holder.unsetPermission(n); } catch (ObjectLacksException ignored) {} }); Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); - save(user, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } else { @@ -121,32 +124,32 @@ public class UserRemoveTempPrefix extends SubCommand { } if (args.size() == 3) { - user.unsetPermission(node, server, true); - Message.REMOVE_TEMP_PREFIX_SERVER_SUCCESS.send(sender, user.getName(), prefix, priority, server); - LogEntry.build().actor(sender).acted(user) - .action("removetempprefix " + priority + " " + args.get(1) + " " + server) + holder.unsetPermission(node, server, true); + Message.REMOVE_TEMP_PREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server); + LogEntry.build().actor(sender).acted(holder) + .action("meta removetempprefix " + priority + " " + args.get(1) + " " + server) .build().submit(plugin, sender); } else { final String world = args.get(3).toLowerCase(); - user.unsetPermission(node, server, world, true); - Message.REMOVE_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), prefix, priority, server, world); - LogEntry.build().actor(sender).acted(user) - .action("removetempprefix " + priority + " " + args.get(1) + " " + server + " " + world) + holder.unsetPermission(node, server, world, true); + Message.REMOVE_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, world); + LogEntry.build().actor(sender).acted(holder) + .action("meta removetempprefix " + priority + " " + args.get(1) + " " + server + " " + world) .build().submit(plugin, sender); } } else { - user.unsetPermission(node, true); - Message.REMOVE_TEMP_PREFIX_SUCCESS.send(sender, user.getName(), prefix, priority); - LogEntry.build().actor(sender).acted(user) - .action("removetempprefix " + priority + " " + args.get(1)) + holder.unsetPermission(node, true); + Message.REMOVE_TEMP_PREFIX_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority); + LogEntry.build().actor(sender).acted(holder) + .action("meta removetempprefix " + priority + " " + args.get(1)) .build().submit(plugin, sender); } - save(user, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectLacksException e) { - Message.DOES_NOT_HAVE_PREFIX.send(sender, user.getName()); + Message.DOES_NOT_HAVE_PREFIX.send(sender, holder.getFriendlyName()); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveTempSuffix.java b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaRemoveTempSuffix.java similarity index 72% rename from common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveTempSuffix.java rename to common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaRemoveTempSuffix.java index 2ed753a84..3b8525d48 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveTempSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/commands/meta/subcommands/MetaRemoveTempSuffix.java @@ -20,36 +20,39 @@ * SOFTWARE. */ -package me.lucko.luckperms.commands.user.subcommands; +package me.lucko.luckperms.commands.meta.subcommands; import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.api.Node; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.Arg; +import me.lucko.luckperms.commands.CommandResult; +import me.lucko.luckperms.commands.Predicate; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.meta.MetaSubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; +import me.lucko.luckperms.core.PermissionHolder; import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectLacksException; -import me.lucko.luckperms.users.User; import me.lucko.luckperms.utils.ArgumentChecker; import java.util.ArrayList; import java.util.List; -public class UserRemoveTempSuffix extends SubCommand { - public UserRemoveTempSuffix() { - super("removetempsuffix", "Removes the temporary suffix from a user", Permission.USER_REMOVE_TEMP_SUFFIX, - Predicate.notInRange(2, 4), +public class MetaRemoveTempSuffix extends MetaSubCommand { + public MetaRemoveTempSuffix() { + super("removetempsuffix", "Removes a temporary suffix", Permission.USER_REMOVE_TEMP_SUFFIX, Permission.GROUP_REMOVE_TEMP_SUFFIX, Predicate.notInRange(2, 4), Arg.list( - Arg.create("priority", true, "the priority to remove the suffix at"), - Arg.create("suffix", true, "the suffix string to remove"), - Arg.create("server", false, "the server to remove the suffix on"), - Arg.create("world", false, "the world to remove the suffix on") + Arg.create("priority", true, "the priority to add the suffix at"), + Arg.create("suffix", true, "the suffix string"), + Arg.create("server", false, "the server to add the suffix on"), + Arg.create("world", false, "the world to add the suffix on") ) ); } @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) { final String suffix = args.get(1).replace("{SPACE}", " "); int priority; try { @@ -76,7 +79,7 @@ public class UserRemoveTempSuffix extends SubCommand { } List toRemove = new ArrayList<>(); - for (Node node : user.getNodes()) { + for (Node node : holder.getNodes()) { if (!node.isSuffix()) continue; if (node.getSuffix().getKey() != priority) continue; if (node.isPermanent()) continue; @@ -100,12 +103,12 @@ public class UserRemoveTempSuffix extends SubCommand { toRemove.forEach(n -> { try { - user.unsetPermission(n); + holder.unsetPermission(n); } catch (ObjectLacksException ignored) {} }); Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); - save(user, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } else { @@ -121,32 +124,32 @@ public class UserRemoveTempSuffix extends SubCommand { } if (args.size() == 3) { - user.unsetPermission(node, server, true); - Message.REMOVE_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, user.getName(), suffix, priority, server); - LogEntry.build().actor(sender).acted(user) - .action("removetempsuffix " + priority + " " + args.get(1) + " " + server) + holder.unsetPermission(node, server, true); + Message.REMOVE_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server); + LogEntry.build().actor(sender).acted(holder) + .action("meta removetempsuffix " + priority + " " + args.get(1) + " " + server) .build().submit(plugin, sender); } else { final String world = args.get(3).toLowerCase(); - user.unsetPermission(node, server, world, true); - Message.REMOVE_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), suffix, priority, server, world); - LogEntry.build().actor(sender).acted(user) - .action("removetempsuffix " + priority + " " + args.get(1) + " " + server + " " + world) + holder.unsetPermission(node, server, world, true); + Message.REMOVE_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, world); + LogEntry.build().actor(sender).acted(holder) + .action("meta removetempsuffix " + priority + " " + args.get(1) + " " + server + " " + world) .build().submit(plugin, sender); } } else { - user.unsetPermission(node, true); - Message.REMOVE_TEMP_SUFFIX_SUCCESS.send(sender, user.getName(), suffix, priority); - LogEntry.build().actor(sender).acted(user) - .action("removetempsuffix " + priority + " " + args.get(1)) + holder.unsetPermission(node, true); + Message.REMOVE_TEMP_SUFFIX_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority); + LogEntry.build().actor(sender).acted(holder) + .action("meta removetempsuffix " + priority + " " + args.get(1)) .build().submit(plugin, sender); } - save(user, sender, plugin); + save(holder, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectLacksException e) { - Message.DOES_NOT_HAVE_SUFFIX.send(sender, user.getName()); + Message.DOES_NOT_HAVE_SUFFIX.send(sender, holder.getFriendlyName()); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/UserMainCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/UserMainCommand.java index b7f3d5f48..dbfa38707 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/UserMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/UserMainCommand.java @@ -28,6 +28,7 @@ import me.lucko.luckperms.commands.MainCommand; import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.Util; +import me.lucko.luckperms.commands.meta.MetaCommands; import me.lucko.luckperms.commands.user.subcommands.*; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Patterns; @@ -58,16 +59,7 @@ public class UserMainCommand extends MainCommand { .add(new UserPromote()) .add(new UserDemote()) .add(new UserShowPos()) - .add(new UserChatMeta()) - .add(new UserAddPrefix()) - .add(new UserAddSuffix()) - .add(new UserRemovePrefix()) - .add(new UserRemoveSuffix()) - .add(new UserAddTempPrefix()) - .add(new UserAddTempSuffix()) - .add(new UserRemoveTempPrefix()) - .add(new UserRemoveTempSuffix()) - .add(new UserClearMeta()) + .add(new MetaCommands<>()) .add(new UserBulkChange()) .add(new UserClear()) .build() diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddPrefix.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddPrefix.java deleted file mode 100644 index 562f30ee9..000000000 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddPrefix.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.commands.user.subcommands; - -import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; -import me.lucko.luckperms.constants.Message; -import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntry; -import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; -import me.lucko.luckperms.users.User; -import me.lucko.luckperms.utils.ArgumentChecker; - -import java.util.List; - -public class UserAddPrefix extends SubCommand { - public UserAddPrefix() { - super("addprefix", "Adds a prefix to the user", Permission.USER_ADDPREFIX, Predicate.notInRange(2, 4), - Arg.list( - Arg.create("priority", true, "the priority to add the prefix at"), - Arg.create("prefix", true, "the prefix string"), - Arg.create("server", false, "the server to add the prefix on"), - Arg.create("world", false, "the world to add the prefix on") - ) - ); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List args, String label) { - final String prefix = args.get(1).replace("{SPACE}", " "); - int priority; - try { - priority = Integer.parseInt(args.get(0)); - } catch (NumberFormatException e) { - Message.META_INVALID_PRIORITY.send(sender, args.get(0)); - return CommandResult.INVALID_ARGS; - } - - final String node = "prefix." + priority + "." + ArgumentChecker.escapeCharacters(prefix); - - 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, true, server); - Message.ADDPREFIX_SERVER_SUCCESS.send(sender, user.getName(), prefix, priority, server); - LogEntry.build().actor(sender).acted(user) - .action("addprefix " + priority + " " + args.get(1) + " " + server) - .build().submit(plugin, sender); - } else { - final String world = args.get(3).toLowerCase(); - user.setPermission(node, true, server, world); - Message.ADDPREFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), prefix, priority, server, world); - LogEntry.build().actor(sender).acted(user) - .action("addprefix " + priority + " " + args.get(1) + " " + server + " " + world) - .build().submit(plugin, sender); - } - - } else { - user.setPermission(node, true); - Message.ADDPREFIX_SUCCESS.send(sender, user.getName(), prefix, priority); - LogEntry.build().actor(sender).acted(user) - .action("addprefix " + priority + " " + args.get(1)) - .build().submit(plugin, sender); - } - - save(user, sender, plugin); - return CommandResult.SUCCESS; - } catch (ObjectAlreadyHasException e) { - Message.ALREADY_HAS_PREFIX.send(sender, user.getName()); - return CommandResult.STATE_ERROR; - } - } -} diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddSuffix.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddSuffix.java deleted file mode 100644 index d543e8664..000000000 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddSuffix.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.commands.user.subcommands; - -import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; -import me.lucko.luckperms.constants.Message; -import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntry; -import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; -import me.lucko.luckperms.users.User; -import me.lucko.luckperms.utils.ArgumentChecker; - -import java.util.List; - -public class UserAddSuffix extends SubCommand { - public UserAddSuffix() { - super("addsuffix", "Adds a suffix to the user", Permission.USER_ADDSUFFIX, Predicate.notInRange(2, 4), - Arg.list( - Arg.create("priority", true, "the priority to add the suffix at"), - Arg.create("suffix", true, "the suffix string"), - Arg.create("server", false, "the server to add the suffix on"), - Arg.create("world", false, "the world to add the suffix on") - ) - ); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List args, String label) { - final String suffix = args.get(1).replace("{SPACE}", " "); - int priority; - try { - priority = Integer.parseInt(args.get(0)); - } catch (NumberFormatException e) { - Message.META_INVALID_PRIORITY.send(sender, args.get(0)); - return CommandResult.INVALID_ARGS; - } - - final String node = "suffix." + priority + "." + ArgumentChecker.escapeCharacters(suffix); - - 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, true, server); - Message.ADDSUFFIX_SERVER_SUCCESS.send(sender, user.getName(), suffix, priority, server); - LogEntry.build().actor(sender).acted(user) - .action("addsuffix " + priority + " " + args.get(1) + " " + server) - .build().submit(plugin, sender); - } else { - final String world = args.get(3).toLowerCase(); - user.setPermission(node, true, server, world); - Message.ADDSUFFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), suffix, priority, server, world); - LogEntry.build().actor(sender).acted(user) - .action("addsuffix " + priority + " " + args.get(1) + " " + server + " " + world) - .build().submit(plugin, sender); - } - - } else { - user.setPermission(node, true); - Message.ADDSUFFIX_SUCCESS.send(sender, user.getName(), suffix, priority); - LogEntry.build().actor(sender).acted(user) - .action("addsuffix " + priority + " " + args.get(1)) - .build().submit(plugin, sender); - } - - save(user, sender, plugin); - return CommandResult.SUCCESS; - } catch (ObjectAlreadyHasException e) { - Message.ALREADY_HAS_SUFFIX.send(sender, user.getName()); - return CommandResult.STATE_ERROR; - } - } -} diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserChatMeta.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserChatMeta.java deleted file mode 100644 index d47a70d02..000000000 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserChatMeta.java +++ /dev/null @@ -1,93 +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.commands.user.subcommands; - -import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.api.Contexts; -import me.lucko.luckperms.api.Node; -import me.lucko.luckperms.commands.*; -import me.lucko.luckperms.constants.Message; -import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.users.User; - -import java.util.AbstractMap.SimpleEntry; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; -import java.util.TreeSet; - -public class UserChatMeta extends SubCommand { - public UserChatMeta() { - super("chatmeta", "Lists the user's chat meta", Permission.USER_CHATMETA, Predicate.alwaysFalse(), null); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List args, String label) { - SortedSet> prefixes = new TreeSet<>(Util.getMetaComparator().reversed()); - SortedSet> suffixes = new TreeSet<>(Util.getMetaComparator().reversed()); - - for (Node node : user.getAllNodes(null, Contexts.allowAll())) { - if (!node.isSuffix() && !node.isPrefix()) { - continue; - } - - StringBuilder sb = new StringBuilder(); - if (node.isServerSpecific()) { - if (node.isWorldSpecific()) { - sb.append("&6W=").append(node.getWorld().get()).append(" "); - } - sb.append("&6S=").append(node.getServer().get()).append(" "); - } - - if (node.isPrefix()) { - sb.append(node.getPrefix().getValue()); - prefixes.add(new SimpleEntry<>(node.getPrefix().getKey(), sb.toString())); - } - - if (node.isSuffix()) { - sb.append(node.getSuffix().getValue()); - suffixes.add(new SimpleEntry<>(node.getSuffix().getKey(), sb.toString())); - } - } - - if (prefixes.isEmpty()) { - Message.CHAT_META_PREFIX_NONE.send(sender, user.getName()); - } else { - Message.CHAT_META_PREFIX_HEADER.send(sender, user.getName()); - for (Map.Entry e : prefixes) { - Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue()); - } - } - - if (suffixes.isEmpty()) { - Message.CHAT_META_SUFFIX_NONE.send(sender, user.getName()); - } else { - Message.CHAT_META_SUFFIX_HEADER.send(sender, user.getName()); - for (Map.Entry e : suffixes) { - Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue()); - } - } - - return CommandResult.SUCCESS; - } -} diff --git a/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java index c7d8d31ed..e5af7dea5 100644 --- a/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java @@ -81,6 +81,8 @@ public abstract class PermissionHolder { @Getter private final Lock ioLock = new ReentrantLock(); + public abstract String getFriendlyName(); + private void invalidateCache(boolean enduring) { if (enduring) { enduringCache.invalidate(); diff --git a/common/src/main/java/me/lucko/luckperms/groups/Group.java b/common/src/main/java/me/lucko/luckperms/groups/Group.java index e1dcdc930..28aa3d60c 100644 --- a/common/src/main/java/me/lucko/luckperms/groups/Group.java +++ b/common/src/main/java/me/lucko/luckperms/groups/Group.java @@ -63,6 +63,11 @@ public class Group extends PermissionHolder implements Identifiable { return dn.equals(name) ? name : name + " (" + dn + ")"; } + @Override + public String getFriendlyName() { + return getDisplayName(); + } + /** * check to see if a group inherits a group * @param group The group to check membership of diff --git a/common/src/main/java/me/lucko/luckperms/users/User.java b/common/src/main/java/me/lucko/luckperms/users/User.java index 33a8ceb84..7545dfbeb 100644 --- a/common/src/main/java/me/lucko/luckperms/users/User.java +++ b/common/src/main/java/me/lucko/luckperms/users/User.java @@ -79,6 +79,11 @@ public abstract class User extends PermissionHolder implements Identifiable