diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/BaseCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/BaseCommand.java new file mode 100644 index 000000000..9a57cb641 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/commands/BaseCommand.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.lucko.luckperms.common.commands; + +import me.lucko.luckperms.common.constants.Permission; + +import java.util.List; +import java.util.function.Predicate; + +public abstract class BaseCommand extends Command { + + public BaseCommand(String name, String description, Permission permission, Predicate argumentCheck, List args, List> children) { + super(name, description, permission, argumentCheck, args, children); + } + + public abstract String getUsage(); + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/Command.java b/common/src/main/java/me/lucko/luckperms/common/commands/Command.java new file mode 100644 index 000000000..20f82e9fa --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/commands/Command.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.lucko.luckperms.common.commands; + +import com.google.common.collect.ImmutableList; +import lombok.Getter; +import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.constants.Permission; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.function.Predicate; + +public abstract class Command { + + @Getter + private final String name; + + @Getter + private final String description; + + // Could be null + private final Permission permission; + + @Getter + private final Predicate argumentCheck; + + // Could be null + private final List args; + + // Could be null + private final List> children; + + public Command(String name, String description, Permission permission, Predicate argumentCheck, List args, List> children) { + this.name = name; + this.description = description; + this.permission = permission; + this.argumentCheck = argumentCheck; + this.args = args == null ? null : ImmutableList.copyOf(args); + this.children = children == null ? null : ImmutableList.copyOf(children); + } + + public Command(String name, String description, Permission permission, Predicate argumentCheck, List args) { + this(name, description, permission, argumentCheck, args, null); + } + + public Command(String name, String description, Predicate argumentCheck) { + this(name, description, null, argumentCheck, null, null); + } + + public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List args, String label) throws CommandException; + + public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { + return Collections.emptyList(); + } + + public abstract void sendUsage(Sender sender, String label); + public abstract void sendDetailedUsage(Sender sender, String label); + + public boolean isAuthorized(Sender sender) { + return permission == null || permission.isAuthorized(sender); + } + + public Optional getPermission() { + return Optional.ofNullable(permission); + } + + public Optional> getArgs() { + return Optional.ofNullable(args); + } + + public Optional>> getChildren() { + return Optional.ofNullable(children); + } + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java b/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java index f95ed35b4..a8e517d35 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java @@ -40,6 +40,7 @@ import me.lucko.luckperms.common.commands.track.ListTracks; import me.lucko.luckperms.common.commands.track.TrackMainCommand; import me.lucko.luckperms.common.commands.user.UserMainCommand; import me.lucko.luckperms.common.commands.usersbulkedit.UsersBulkEditMainCommand; +import me.lucko.luckperms.common.constants.Message; import java.util.ArrayList; import java.util.Collections; @@ -53,7 +54,7 @@ public class CommandManager { private final LuckPermsPlugin plugin; @Getter - private final List mainCommands = ImmutableList.builder() + private final List mainCommands = ImmutableList.builder() .add(new UserMainCommand()) .add(new GroupMainCommand()) .add(new TrackMainCommand()) @@ -76,7 +77,6 @@ public class CommandManager { .add(new ListTracks()) .build(); - /** * Generic on command method to be called from the command executor object of the platform * Unlike {@link #onCommand(Sender, String, List)}, this method is called in a new thread @@ -99,13 +99,14 @@ public class CommandManager { * @param args the arguments provided * @return if the command was successful */ + @SuppressWarnings("unchecked") public CommandResult onCommand(Sender sender, String label, List args) { if (args.size() == 0) { sendCommandUsage(sender, label); return CommandResult.INVALID_ARGS; } - Optional o = mainCommands.stream() + Optional o = mainCommands.stream() .filter(m -> m.getName().equalsIgnoreCase(args.get(0))) .limit(1) .findAny(); @@ -115,35 +116,70 @@ public class CommandManager { return CommandResult.INVALID_ARGS; } - final MainCommand main = o.get(); + final Command main = o.get(); if (!main.isAuthorized(sender)) { sendCommandUsage(sender, label); return CommandResult.NO_PERMISSION; } - if (main.getRequiredArgsLength() == 0) { - try { - return main.execute(plugin, sender, null, label); - } catch (Exception e) { - e.printStackTrace(); - return CommandResult.FAILURE; - } - } + List arguments = new ArrayList<>(args); + handleRewrites(arguments); + arguments.remove(0); // remove the first command part. - if (args.size() == 1) { + if (main.getArgumentCheck().test(arguments.size())) { main.sendUsage(sender, label); return CommandResult.INVALID_ARGS; } - List arguments = new ArrayList<>(args); - handleRewrites(arguments); - + CommandResult result; try { - return main.execute(plugin, sender, arguments.subList(1, arguments.size()), label); + result = main.execute(plugin, sender, null, arguments, label); + } catch (CommandException e) { + result = handleException(e, sender, label, main); } catch (Exception e) { e.printStackTrace(); - return CommandResult.FAILURE; + result = CommandResult.FAILURE; } + + return result; + } + + public static CommandResult handleException(CommandException e, Sender sender, String label, Command command) { + if (e instanceof ArgumentUtils.ArgumentException) { + if (e instanceof ArgumentUtils.DetailedUsageException) { + command.sendDetailedUsage(sender, label); + return CommandResult.INVALID_ARGS; + } + + if (e instanceof ArgumentUtils.UseInheritException) { + Message.USE_INHERIT_COMMAND.send(sender); + return CommandResult.INVALID_ARGS; + } + + if (e instanceof ArgumentUtils.InvalidServerException) { + Message.SERVER_INVALID_ENTRY.send(sender); + return CommandResult.INVALID_ARGS; + } + + if (e instanceof ArgumentUtils.PastDateException) { + Message.PAST_DATE_ERROR.send(sender); + return CommandResult.INVALID_ARGS; + } + + if (e instanceof ArgumentUtils.InvalidDateException) { + Message.ILLEGAL_DATE_ERROR.send(sender, ((ArgumentUtils.InvalidDateException) e).getInvalidDate()); + return CommandResult.INVALID_ARGS; + } + + if (e instanceof ArgumentUtils.InvalidPriorityException) { + Message.META_INVALID_PRIORITY.send(sender, ((ArgumentUtils.InvalidPriorityException) e).getInvalidPriority()); + return CommandResult.INVALID_ARGS; + } + } + + // Not something we can catch. + e.printStackTrace(); + return CommandResult.FAILURE; } /** @@ -154,7 +190,7 @@ public class CommandManager { */ @SuppressWarnings("unchecked") public List onTabComplete(Sender sender, List args) { - final List mains = mainCommands.stream() + final List mains = mainCommands.stream() .filter(m -> m.isAuthorized(sender)) .collect(Collectors.toList()); @@ -171,7 +207,7 @@ public class CommandManager { .collect(Collectors.toList()); } - Optional o = mains.stream() + Optional o = mains.stream() .filter(m -> m.getName().equalsIgnoreCase(args.get(0))) .limit(1) .findAny(); @@ -180,7 +216,7 @@ public class CommandManager { return Collections.emptyList(); } - return o.get().onTabComplete(sender, args.subList(1, args.size()), plugin); + return o.get().tabComplete(plugin, sender, args.subList(1, args.size())); } private void sendCommandUsage(Sender sender, String label) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/MainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/MainCommand.java index 4be2822cc..0ecb4ec1f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/MainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/MainCommand.java @@ -22,11 +22,11 @@ package me.lucko.luckperms.common.commands; -import com.google.common.collect.ImmutableList; -import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NonNull; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.constants.Message; +import me.lucko.luckperms.common.utils.Predicates; import java.util.ArrayList; import java.util.Collections; @@ -34,50 +34,27 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -@Getter -@AllArgsConstructor -public abstract class MainCommand { +public abstract class MainCommand extends BaseCommand { - /** - * The name of the main command - */ - private final String name; - - /** - * The command usage - */ - private final String usage; - - /** - * How many arguments are required for the command to run - */ - private final int requiredArgsLength; - - /** - * A list of the sub commands under this main command - */ @Getter - private final List> subCommands; + private final String usage; + private final int minArgs; // equals 1 if the command doesn't take a mid argument, e.g. /lp user sub-command.... - MainCommand(String name, String usage, int requiredArgsLength) { - this(name, usage, requiredArgsLength, ImmutableList.of()); + public MainCommand(String name, String description, String usage, int minArgs, @NonNull List> children) { + super(name, description, null, Predicates.alwaysFalse(), null, children); + this.usage = usage; + this.minArgs = minArgs; } - /** - * Called when this main command is ran - * @param plugin a link to the main plugin instance - * @param sender the sender to executed the command - * @param args the stripped arguments given - * @param label the command label used - */ - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { - if (args.size() < requiredArgsLength) { + @Override + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List args, String label) throws CommandException { + if (args.size() < minArgs) { sendUsage(sender, label); return CommandResult.INVALID_ARGS; } - Optional> o = getSubCommands().stream() - .filter(s -> s.getName().equalsIgnoreCase(args.get(requiredArgsLength - 1))) + Optional> o = getSubCommands().stream() + .filter(s -> s.getName().equalsIgnoreCase(args.get(minArgs - 1))) .limit(1) .findAny(); @@ -86,19 +63,19 @@ public abstract class MainCommand { return CommandResult.INVALID_ARGS; } - final SubCommand sub = o.get(); + final Command sub = o.get(); if (!sub.isAuthorized(sender)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; } List strippedArgs = new ArrayList<>(); - if (args.size() > requiredArgsLength) { - strippedArgs.addAll(args.subList(requiredArgsLength, args.size())); + if (args.size() > minArgs) { + strippedArgs.addAll(args.subList(minArgs, args.size())); } - if (sub.getIsArgumentInvalid().test(strippedArgs.size())) { - sub.sendDetailedUsage(sender); + if (sub.getArgumentCheck().test(strippedArgs.size())) { + sub.sendDetailedUsage(sender, label); return CommandResult.INVALID_ARGS; } @@ -106,11 +83,13 @@ public abstract class MainCommand { T t = getTarget(name, plugin, sender); if (t != null) { CommandResult result; + try { result = sub.execute(plugin, sender, t, strippedArgs, label); } catch (CommandException e) { - result = handleException(e, sender, sub); + result = CommandManager.handleException(e, sender, label, sub); } + cleanup(t, plugin); return result; } @@ -118,99 +97,9 @@ public abstract class MainCommand { return CommandResult.LOADING_ERROR; } - private static CommandResult handleException(CommandException e, Sender sender, SubCommand command) { - if (e instanceof ArgumentUtils.ArgumentException) { - if (e instanceof ArgumentUtils.DetailedUsageException) { - command.sendDetailedUsage(sender); - return CommandResult.INVALID_ARGS; - } - - if (e instanceof ArgumentUtils.UseInheritException) { - Message.USE_INHERIT_COMMAND.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (e instanceof ArgumentUtils.InvalidServerException) { - Message.SERVER_INVALID_ENTRY.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (e instanceof ArgumentUtils.PastDateException) { - Message.PAST_DATE_ERROR.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (e instanceof ArgumentUtils.InvalidDateException) { - Message.ILLEGAL_DATE_ERROR.send(sender, ((ArgumentUtils.InvalidDateException) e).getInvalidDate()); - return CommandResult.INVALID_ARGS; - } - - if (e instanceof ArgumentUtils.InvalidPriorityException) { - Message.META_INVALID_PRIORITY.send(sender, ((ArgumentUtils.InvalidPriorityException) e).getInvalidPriority()); - return CommandResult.INVALID_ARGS; - } - } - - // Not something we can catch. - e.printStackTrace(); - return CommandResult.FAILURE; - } - - /** - * Gets the object the command is acting upon, and runs the callback if successful - * @param target the name of the object to be looked up - * @param plugin a link to the main plugin instance - * @param sender the user who send the command (used to send error messages if the lookup was unsuccessful) - */ - protected abstract T getTarget(String target, LuckPermsPlugin plugin, Sender sender); - - protected abstract void cleanup(T t, LuckPermsPlugin plugin); - - /** - * Get a list of {@link T} objects for tab completion - * @param plugin a link to the main plugin instance - * @return a list of strings - */ - protected abstract List getObjects(LuckPermsPlugin plugin); - - /** - * Send the command usage to a sender - * @param sender the sender to send the usage to - * @param label the command label used - */ - protected void sendUsage(Sender sender, String label) { - if (getSubCommands().isEmpty()) { - Util.sendPluginMessage(sender, "&3> &a" + String.format(getUsage(), label)); - return; - } - - List subs = getSubCommands().stream() - .filter(s -> s.isAuthorized(sender)) - .collect(Collectors.toList()); - - if (subs.size() > 0) { - Util.sendPluginMessage(sender, "&b" + getName() + " Sub Commands: &7(" + String.format(getUsage(), label) + " ...)"); - - for (SubCommand s : subs) { - s.sendUsage(sender); - } - - } else { - Message.COMMAND_NO_PERMISSION.send(sender); - } - } - - /** - * If a sender has permission to use this command - * @param sender the sender trying to use the command - * @return true if the sender can use the command - */ - protected boolean isAuthorized(Sender sender) { - return getSubCommands().stream().filter(sc -> sc.isAuthorized(sender)).count() != 0; - } - - protected List onTabComplete(Sender sender, List args, LuckPermsPlugin plugin) { - final List objects = getObjects(plugin); + @Override + public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { + final List objects = getTargets(plugin); if (args.size() <= 1) { if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) { @@ -222,7 +111,7 @@ public abstract class MainCommand { .collect(Collectors.toList()); } - final List> subs = getSubCommands().stream() + final List> subs = getSubCommands().stream() .filter(s -> s.isAuthorized(sender)) .collect(Collectors.toList()); @@ -239,7 +128,7 @@ public abstract class MainCommand { .collect(Collectors.toList()); } - Optional> o = subs.stream() + Optional> o = subs.stream() .filter(s -> s.getName().equalsIgnoreCase(args.get(1))) .limit(1) .findAny(); @@ -248,6 +137,56 @@ public abstract class MainCommand { return Collections.emptyList(); } - return o.get().onTabComplete(plugin, sender, args.subList(2, args.size())); + return o.get().tabComplete(plugin, sender, args.subList(2, args.size())); + } + + protected abstract List getTargets(LuckPermsPlugin plugin); + protected abstract T getTarget(String target, LuckPermsPlugin plugin, Sender sender); + protected abstract void cleanup(T t, LuckPermsPlugin plugin); + + @Override + public void sendUsage(Sender sender, String label) { + /* + if (getSubCommands().isEmpty()) { + Util.sendPluginMessage(sender, "&3> &a" + String.format(getUsage(), label)); + return; + */ + + List subs = getSubCommands().stream() + .filter(s -> s.isAuthorized(sender)) + .collect(Collectors.toList()); + + if (subs.size() > 0) { + Util.sendPluginMessage(sender, "&b" + getName() + " Sub Commands: &7(" + String.format(usage, label) + " ...)"); + + for (Command s : subs) { + s.sendUsage(sender, label); + } + + } else { + Message.COMMAND_NO_PERMISSION.send(sender); + } + } + + @Override + public void sendDetailedUsage(Sender sender, String label) { + + } + + @Override + public boolean isAuthorized(Sender sender) { + return getSubCommands().stream().filter(sc -> sc.isAuthorized(sender)).count() != 0; + } + + @Deprecated + @Override + public Optional>> getChildren() { + return super.getChildren(); + } + + + @SuppressWarnings("deprecation") + public List> getSubCommands() { + return getChildren().get(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/SingleCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/SingleCommand.java new file mode 100644 index 000000000..3d542dd42 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/commands/SingleCommand.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.lucko.luckperms.common.commands; + +import lombok.Getter; +import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.constants.Permission; + +import java.util.List; +import java.util.function.Predicate; + +public abstract class SingleCommand extends BaseCommand { + + @Getter + private final String usage; + + public SingleCommand(String name, String description, String usage, Permission permission, Predicate argumentCheck, List args) { + super(name, description, permission, argumentCheck, args, null); + this.usage = usage; + } + + @Override + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List args, String label) throws CommandException { + return execute(plugin, sender, args, label); + } + + public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) throws CommandException; + + @Override + public void sendUsage(Sender sender, String label) { + String usage = ""; + if (getArgs().isPresent()) { + usage += "&3 - &7"; + for (Arg arg : getArgs().get()) { + usage += arg.asPrettyString() + " "; + } + } + + Util.sendPluginMessage(sender, "&3> &a" + getName().toLowerCase() + usage); + } + + @Override + public void sendDetailedUsage(Sender sender, String label) { + Util.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName()); + Util.sendPluginMessage(sender, "&b> &7" + getDescription()); + if (getArgs().isPresent()) { + Util.sendPluginMessage(sender, "&3Arguments:"); + for (Arg arg : getArgs().get()) { + Util.sendPluginMessage(sender, "&b- " + arg.asPrettyString() + "&3 -> &7" + arg.getDescription()); + } + } + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/SingleMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/SingleMainCommand.java deleted file mode 100644 index c8a0fce6e..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/commands/SingleMainCommand.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2016 Lucko (Luck) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.common.commands; - -import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.constants.Permission; - -import java.util.Collections; -import java.util.List; - -/** - * An extension of {@link MainCommand} for implementations without any subcommands - */ -public class SingleMainCommand extends MainCommand { - private final Permission permission; - - public SingleMainCommand(String name, String usage, int requiredArgsLength, Permission permission) { - super(name, usage, requiredArgsLength); - this.permission = permission; - } - - @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { - // Do nothing, allow the implementation to override this - return null; - } - - @Override - protected Object getTarget(String target, LuckPermsPlugin plugin, Sender sender) { - return null; - } - - @Override - protected void cleanup(Object o, LuckPermsPlugin plugin) { - // Do nothing - } - - @Override - protected List getObjects(LuckPermsPlugin plugin) { - return Collections.emptyList(); - } - - @Override - protected List onTabComplete(Sender sender, List args, LuckPermsPlugin plugin) { - return Collections.emptyList(); - } - - @Override - public List> getSubCommands() { - return Collections.emptyList(); - } - - @Override - protected boolean isAuthorized(Sender sender) { - return permission.isAuthorized(sender); - } -} diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java index 854f38719..d61e5967e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java @@ -22,8 +22,6 @@ package me.lucko.luckperms.common.commands; -import com.google.common.collect.ImmutableList; -import lombok.AllArgsConstructor; import lombok.Getter; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.constants.Message; @@ -43,62 +41,22 @@ import java.util.stream.Collectors; * Abstract SubCommand class */ @Getter -@AllArgsConstructor -public abstract class SubCommand { +public abstract class SubCommand extends Command { - /** - * 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 permission; - - /** - * Predicate to test if the argument length given is invalid - */ - private final Predicate isArgumentInvalid; - - private final ImmutableList args; - - /** - * Called when this sub command is ran - * @param plugin a link to the main plugin instance - * @param sender the sender to executed the command - * @param t the object the command is operating on - * @param args the stripped arguments given - * @param label the command label used - */ - public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List args, String label) throws CommandException; - - /** - * Returns a list of suggestions, which are empty by default. Sub classes that give tab complete suggestions override - * this method to give their own list. - * @param plugin the plugin instance - * @param sender who is tab completing - * @param args the arguments so far - * @return a list of suggestions - */ - public List onTabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return Collections.emptyList(); + public SubCommand(String name, String description, Permission permission, Predicate argumentCheck, List args) { + super(name, description, permission, argumentCheck, args); } /** * Send the command usage to a sender * @param sender the sender to send the usage to */ - public void sendUsage(Sender sender) { + @Override + public void sendUsage(Sender sender, String label) { String usage = ""; - if (args != null) { + if (getArgs().isPresent()) { usage += "&3 - &7"; - for (Arg arg : args) { + for (Arg arg : getArgs().get()) { usage += arg.asPrettyString() + " "; } } @@ -106,30 +64,22 @@ public abstract class SubCommand { Util.sendPluginMessage(sender, "&3> &a" + getName().toLowerCase() + usage); } - public void sendDetailedUsage(Sender sender) { + @Override + public void sendDetailedUsage(Sender sender, String label) { Util.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName()); Util.sendPluginMessage(sender, "&b> &7" + getDescription()); - if (args != null) { + if (getArgs().isPresent()) { Util.sendPluginMessage(sender, "&3Arguments:"); - for (Arg arg : args) { + for (Arg arg : getArgs().get()) { Util.sendPluginMessage(sender, "&b- " + arg.asPrettyString() + "&3 -> &7" + arg.getDescription()); } } } - /** - * If a sender has permission to use this command - * @param sender the sender trying to use the command - * @return true if the sender can use the command - */ - public boolean isAuthorized(Sender sender) { - return permission.isAuthorized(sender); - } - /* * ---------------------------------------------------------------------------------- - * Utility methods used by #onTabComplete and #execute implementations in sub classes + * Utility methods used by #tabComplete and #execute implementations in sub classes * ---------------------------------------------------------------------------------- */ diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/SecondaryMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/SharedMainCommand.java similarity index 88% rename from common/src/main/java/me/lucko/luckperms/common/commands/generic/SecondaryMainCommand.java rename to common/src/main/java/me/lucko/luckperms/common/commands/generic/SharedMainCommand.java index 8038cf6de..994c9529c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/SecondaryMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/SharedMainCommand.java @@ -34,11 +34,11 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -public class SecondaryMainCommand extends SubCommand { +public class SharedMainCommand extends SubCommand { private boolean user; - private final List secondaryCommands; + private final List secondaryCommands; - public SecondaryMainCommand(String name, String description, boolean user, List secondaryCommands) { + public SharedMainCommand(String name, String description, boolean user, List secondaryCommands) { super(name, description, null, Predicates.alwaysFalse(), null); this.secondaryCommands = secondaryCommands; this.user = user; @@ -51,7 +51,7 @@ public class SecondaryMainCommand extends SubCommand return CommandResult.INVALID_ARGS; } - Optional o = secondaryCommands.stream() + Optional o = secondaryCommands.stream() .filter(s -> s.getName().equalsIgnoreCase(args.get(0))) .limit(1) .findAny(); @@ -61,7 +61,7 @@ public class SecondaryMainCommand extends SubCommand return CommandResult.INVALID_ARGS; } - final SecondarySubCommand sub = o.get(); + final SharedSubCommand sub = o.get(); if (!sub.isAuthorized(sender, user)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; @@ -86,7 +86,7 @@ public class SecondaryMainCommand extends SubCommand return result; } - private static CommandResult handleException(CommandException e, Sender sender, SecondarySubCommand command) { + private static CommandResult handleException(CommandException e, Sender sender, SharedSubCommand command) { if (e instanceof ArgumentUtils.ArgumentException) { if (e instanceof ArgumentUtils.DetailedUsageException) { command.sendDetailedUsage(sender); @@ -125,8 +125,8 @@ public class SecondaryMainCommand extends SubCommand } @Override - public List onTabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - final List subs = secondaryCommands.stream() + public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { + final List subs = secondaryCommands.stream() .filter(s -> s.isAuthorized(sender, user)) .collect(Collectors.toList()); @@ -143,7 +143,7 @@ public class SecondaryMainCommand extends SubCommand .collect(Collectors.toList()); } - Optional o = subs.stream() + Optional o = subs.stream() .filter(s -> s.getName().equalsIgnoreCase(args.get(0))) .limit(1) .findAny(); @@ -157,7 +157,7 @@ public class SecondaryMainCommand extends SubCommand @Override public boolean isAuthorized(Sender sender) { - for (SecondarySubCommand subCommand : secondaryCommands) { + for (SharedSubCommand subCommand : secondaryCommands) { if (subCommand.isAuthorized(sender, user)) { return true; } @@ -166,7 +166,7 @@ public class SecondaryMainCommand extends SubCommand } private void sendUsageDetailed(Sender sender, boolean user, String label) { - List subs = secondaryCommands.stream() + List subs = secondaryCommands.stream() .filter(s -> s.isAuthorized(sender, user)) .collect(Collectors.toList()); @@ -177,7 +177,7 @@ public class SecondaryMainCommand extends SubCommand Util.sendPluginMessage(sender, "&b" + getName() + " Sub Commands: &7(" + String.format("/%s group " + getName().toLowerCase() + " ...)", label)); } - for (SecondarySubCommand s : subs) { + for (SharedSubCommand s : subs) { s.sendUsage(sender); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/SecondarySubCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/SharedSubCommand.java similarity index 98% rename from common/src/main/java/me/lucko/luckperms/common/commands/generic/SecondarySubCommand.java rename to common/src/main/java/me/lucko/luckperms/common/commands/generic/SharedSubCommand.java index c167209d0..325b64b03 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/SecondarySubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/SharedSubCommand.java @@ -38,7 +38,7 @@ import java.util.function.Predicate; @Getter @AllArgsConstructor -public abstract class SecondarySubCommand { +public abstract class SharedSubCommand { /** * The name of the sub command diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java index fce7fc149..1e208b726 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java @@ -23,13 +23,13 @@ package me.lucko.luckperms.common.commands.generic.meta; import com.google.common.collect.ImmutableList; -import me.lucko.luckperms.common.commands.generic.SecondaryMainCommand; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedMainCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.core.PermissionHolder; -public class CommandMeta extends SecondaryMainCommand { +public class CommandMeta extends SharedMainCommand { public CommandMeta(boolean user) { - super("Meta", "Edit metadata values", user, ImmutableList.builder() + super("Meta", "Edit metadata values", user, ImmutableList.builder() .add(new MetaInfo()) .add(new MetaSet()) .add(new MetaUnset()) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java index e76a74b39..61651d6fa 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java @@ -25,7 +25,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -36,7 +36,7 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import java.util.List; import java.util.stream.Collectors; -public class MetaAddPrefix extends SecondarySubCommand { +public class MetaAddPrefix extends SharedSubCommand { public MetaAddPrefix() { super("addprefix", "Adds a prefix", Permission.USER_META_ADDPREFIX, Permission.GROUP_META_ADDPREFIX, Predicates.notInRange(2, 4), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java index 9af77e213..b860e1e64 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java @@ -25,7 +25,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -36,7 +36,7 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import java.util.List; import java.util.stream.Collectors; -public class MetaAddSuffix extends SecondarySubCommand { +public class MetaAddSuffix extends SharedSubCommand { public MetaAddSuffix() { super("addsuffix", "Adds a suffix", Permission.USER_META_ADDSUFFIX, Permission.GROUP_META_ADDSUFFIX, Predicates.notInRange(2, 4), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java index 40f04910f..b93fe16e6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java @@ -25,7 +25,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -37,7 +37,7 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import java.util.List; import java.util.stream.Collectors; -public class MetaAddTempPrefix extends SecondarySubCommand { +public class MetaAddTempPrefix extends SharedSubCommand { public MetaAddTempPrefix() { super("addtempprefix", "Adds a prefix temporarily", Permission.USER_META_ADDTEMP_PREFIX, Permission.GROUP_META_ADDTEMP_PREFIX, Predicates.notInRange(3, 5), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java index 431b638fb..d6594e6fb 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java @@ -25,7 +25,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -37,7 +37,7 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import java.util.List; import java.util.stream.Collectors; -public class MetaAddTempSuffix extends SecondarySubCommand { +public class MetaAddTempSuffix extends SharedSubCommand { public MetaAddTempSuffix() { super("addtempsuffix", "Adds a suffix temporarily", Permission.USER_META_ADDTEMP_SUFFIX, Permission.GROUP_META_ADDTEMP_SUFFIX, Predicates.notInRange(3, 5), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java index adb0193b0..58c972097 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java @@ -24,7 +24,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -34,7 +34,7 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; import java.util.stream.Collectors; -public class MetaClear extends SecondarySubCommand { +public class MetaClear extends SharedSubCommand { public MetaClear() { super("clear", "Clears all chat meta", Permission.USER_META_CLEAR, Permission.GROUP_META_CLEAR, Predicates.notInRange(0, 2), Arg.list( diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java index 708354a1c..ed6dfa561 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java @@ -29,7 +29,7 @@ import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; import me.lucko.luckperms.common.commands.Util; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -37,7 +37,7 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.*; -public class MetaInfo extends SecondarySubCommand { +public class MetaInfo extends SharedSubCommand { public MetaInfo() { super("info", "Shows all chat meta", Permission.USER_META_INFO, Permission.GROUP_META_INFO, Predicates.alwaysFalse(), null); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java index 8eb9b8b39..3b2f9b08f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java @@ -26,7 +26,7 @@ import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -38,7 +38,7 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -public class MetaRemovePrefix extends SecondarySubCommand { +public class MetaRemovePrefix extends SharedSubCommand { public MetaRemovePrefix() { super("removeprefix", "Removes a prefix", Permission.USER_META_REMOVEPREFIX, Permission.GROUP_META_REMOVEPREFIX, Predicates.notInRange(2, 4), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java index 606d2dedc..06f72db64 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java @@ -26,7 +26,7 @@ import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -38,7 +38,7 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -public class MetaRemoveSuffix extends SecondarySubCommand { +public class MetaRemoveSuffix extends SharedSubCommand { public MetaRemoveSuffix() { super("removesuffix", "Removes a suffix", Permission.USER_META_REMOVESUFFIX, Permission.GROUP_META_REMOVESUFFIX, Predicates.notInRange(2, 4), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java index 92b1a5434..9be508c27 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java @@ -26,7 +26,7 @@ import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -38,7 +38,7 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -public class MetaRemoveTempPrefix extends SecondarySubCommand { +public class MetaRemoveTempPrefix extends SharedSubCommand { public MetaRemoveTempPrefix() { super("removetempprefix", "Removes a temporary prefix", Permission.USER_META_REMOVETEMP_PREFIX, Permission.GROUP_META_REMOVETEMP_PREFIX, Predicates.notInRange(2, 4), Arg.list( diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java index 1708dbfe4..a90f467b2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java @@ -26,7 +26,7 @@ import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -38,7 +38,7 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -public class MetaRemoveTempSuffix extends SecondarySubCommand { +public class MetaRemoveTempSuffix extends SharedSubCommand { public MetaRemoveTempSuffix() { super("removetempsuffix", "Removes a temporary suffix", Permission.USER_META_REMOVETEMP_SUFFIX, Permission.GROUP_META_REMOVETEMP_SUFFIX, Predicates.notInRange(2, 4), Arg.list( diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java index b5a287c4d..598900fed 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java @@ -26,7 +26,7 @@ import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.NodeBuilder; @@ -38,7 +38,7 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import java.util.List; import java.util.stream.Collectors; -public class MetaSet extends SecondarySubCommand { +public class MetaSet extends SharedSubCommand { public MetaSet() { super("set", "Sets a meta value", Permission.USER_META_SET, Permission.GROUP_META_SET, Predicates.notInRange(2, 4), Arg.list( diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java index 5bfb9981b..0eb2d67e5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java @@ -26,7 +26,7 @@ import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.NodeBuilder; @@ -39,7 +39,7 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import java.util.List; import java.util.stream.Collectors; -public class MetaSetTemp extends SecondarySubCommand { +public class MetaSetTemp extends SharedSubCommand { public MetaSetTemp() { super("settemp", "Sets a meta value temporarily", Permission.USER_META_SETTEMP, Permission.GROUP_META_SETTEMP, Predicates.notInRange(3, 5), Arg.list( diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java index a26015617..71c92977d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java @@ -25,7 +25,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -35,7 +35,7 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; import java.util.stream.Collectors; -public class MetaUnset extends SecondarySubCommand { +public class MetaUnset extends SharedSubCommand { public MetaUnset() { super("unset", "Unsets a meta value", Permission.USER_META_UNSET, Permission.GROUP_META_UNSET, Predicates.notInRange(1, 3), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java index 57f188d9a..7f20ccffc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java @@ -25,7 +25,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -35,7 +35,7 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; import java.util.stream.Collectors; -public class MetaUnsetTemp extends SecondarySubCommand { +public class MetaUnsetTemp extends SharedSubCommand { public MetaUnsetTemp() { super("unsettemp", "Unsets a temporary meta value", Permission.USER_META_UNSETTEMP, Permission.GROUP_META_UNSETTEMP, Predicates.notInRange(1, 3), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java index abe9dcfe8..2f63a996e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java @@ -23,13 +23,13 @@ package me.lucko.luckperms.common.commands.generic.parent; import com.google.common.collect.ImmutableList; -import me.lucko.luckperms.common.commands.generic.SecondaryMainCommand; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedMainCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.core.PermissionHolder; -public class CommandParent extends SecondaryMainCommand { +public class CommandParent extends SharedMainCommand { public CommandParent(boolean user) { - super("Parent", "Edit inheritances", user, ImmutableList.builder() + super("Parent", "Edit inheritances", user, ImmutableList.builder() .add(new ParentInfo()) .add(new ParentSet()) .add(new ParentAdd()) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java index a443fc668..60e51381e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java @@ -24,7 +24,7 @@ package me.lucko.luckperms.common.commands.generic.parent; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -38,7 +38,7 @@ import java.util.stream.Collectors; import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete; -public class ParentAdd extends SecondarySubCommand { +public class ParentAdd extends SharedSubCommand { public ParentAdd() { super("add", "Sets another group for the object to inherit permissions from", Permission.USER_PARENT_ADD, Permission.GROUP_PARENT_ADD, Predicates.notInRange(1, 3), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java index c04c180ad..5719b1161 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java @@ -24,7 +24,7 @@ package me.lucko.luckperms.common.commands.generic.parent; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -39,7 +39,7 @@ import java.util.stream.Collectors; import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete; -public class ParentAddTemp extends SecondarySubCommand { +public class ParentAddTemp extends SharedSubCommand { public ParentAddTemp() { super("addtemp", "Sets another group for the object to inherit permissions from temporarily", Permission.USER_PARENT_ADDTEMP, Permission.GROUP_PARENT_ADDTEMP, Predicates.notInRange(2, 4), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java index 89b87bf5d..b3222d151 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java @@ -27,7 +27,7 @@ import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; import me.lucko.luckperms.common.commands.Util; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -35,7 +35,7 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -public class ParentInfo extends SecondarySubCommand { +public class ParentInfo extends SharedSubCommand { public ParentInfo() { super("info", "Lists the groups that this object inherits from", Permission.USER_PARENT_INFO, Permission.GROUP_PARENT_INFO, Predicates.alwaysFalse(), null); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java index ddd4557ab..466df1b4c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java @@ -24,7 +24,7 @@ package me.lucko.luckperms.common.commands.generic.parent; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -38,7 +38,7 @@ import java.util.stream.Collectors; import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete; -public class ParentRemove extends SecondarySubCommand { +public class ParentRemove extends SharedSubCommand { public ParentRemove() { super("remove", "Removes a previously set inheritance rule", Permission.USER_PARENT_REMOVE, Permission.GROUP_PARENT_REMOVE, Predicates.notInRange(1, 3), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java index b9ec01235..01c8fe983 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java @@ -24,7 +24,7 @@ package me.lucko.luckperms.common.commands.generic.parent; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -37,7 +37,7 @@ import java.util.stream.Collectors; import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete; -public class ParentRemoveTemp extends SecondarySubCommand { +public class ParentRemoveTemp extends SharedSubCommand { public ParentRemoveTemp() { super("removetemp", "Removes a previously set temporary inheritance rule", Permission.USER_PARENT_REMOVETEMP, Permission.GROUP_PARENT_REMOVETEMP, Predicates.notInRange(1, 3), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java index bc9f17aed..60fbf197b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java @@ -24,7 +24,7 @@ package me.lucko.luckperms.common.commands.generic.parent; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -39,7 +39,7 @@ import java.util.stream.Collectors; import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete; -public class ParentSet extends SecondarySubCommand { +public class ParentSet extends SharedSubCommand { public ParentSet() { super("set", "Removes all other groups the object inherits already and adds them to the one given", Permission.USER_PARENT_SET, Permission.GROUP_PARENT_SET, Predicates.notInRange(1, 3), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java index a1a081393..3aed0904e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java @@ -23,13 +23,13 @@ package me.lucko.luckperms.common.commands.generic.permission; import com.google.common.collect.ImmutableList; -import me.lucko.luckperms.common.commands.generic.SecondaryMainCommand; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedMainCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.core.PermissionHolder; -public class CommandPermission extends SecondaryMainCommand { +public class CommandPermission extends SharedMainCommand { public CommandPermission(boolean user) { - super("Permission", "Edit permissions", user, ImmutableList.builder() + super("Permission", "Edit permissions", user, ImmutableList.builder() .add(new PermissionInfo()) .add(new PermissionSet()) .add(new PermissionUnset()) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java index d6aa945f5..9908b3c7e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java @@ -24,7 +24,7 @@ package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.NodeBuilder; import me.lucko.luckperms.common.core.PermissionHolder; @@ -32,7 +32,7 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -public class PermissionCheck extends SecondarySubCommand { +public class PermissionCheck extends SharedSubCommand { public PermissionCheck() { super("check", "Checks to see if the object has a certain permission node", Permission.USER_PERM_CHECK, Permission.GROUP_PERM_CHECK, Predicates.notInRange(1, 3), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java index 05627648a..52aecb006 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java @@ -24,7 +24,7 @@ package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.InheritanceInfo; import me.lucko.luckperms.common.core.NodeBuilder; @@ -33,7 +33,7 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -public class PermissionCheckInherits extends SecondarySubCommand { +public class PermissionCheckInherits extends SharedSubCommand { public PermissionCheckInherits() { super("checkinherits", "Checks to see if the object inherits a certain permission node", Permission.USER_PERM_CHECK_INHERITS, Permission.GROUP_PERM_CHECK_INHERITS, Predicates.notInRange(1, 3), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java index 2417ea380..1f43d68f5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java @@ -27,7 +27,7 @@ import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; import me.lucko.luckperms.common.commands.Util; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -35,7 +35,7 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -public class PermissionInfo extends SecondarySubCommand { +public class PermissionInfo extends SharedSubCommand { public PermissionInfo() { super("info", "Lists the permission nodes the object has", Permission.USER_PERM_INFO, Permission.GROUP_PERM_INFO, Predicates.alwaysFalse(), null); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java index 0e6e4dad6..6b341beb6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java @@ -24,7 +24,7 @@ package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -37,7 +37,7 @@ import java.util.stream.Collectors; import static me.lucko.luckperms.common.commands.SubCommand.getBoolTabComplete; -public class PermissionSet extends SecondarySubCommand { +public class PermissionSet extends SharedSubCommand { public PermissionSet() { super("set", "Sets a permission for the object", Permission.USER_PERM_SET, Permission.GROUP_PERM_SET, Predicates.notInRange(2, 4), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java index 21812aa9d..f02d50cdd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java @@ -24,7 +24,7 @@ package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -38,7 +38,7 @@ import java.util.stream.Collectors; import static me.lucko.luckperms.common.commands.SubCommand.getBoolTabComplete; -public class PermissionSetTemp extends SecondarySubCommand { +public class PermissionSetTemp extends SharedSubCommand { public PermissionSetTemp() { super("settemp", "Sets a permission for the object temporarily", Permission.USER_PERM_SETTEMP, Permission.GROUP_PERM_SETTEMP, Predicates.notInRange(3, 5), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java index 9b8e06d43..a00d53cf5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java @@ -24,7 +24,7 @@ package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -35,7 +35,7 @@ import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.List; import java.util.stream.Collectors; -public class PermissionUnset extends SecondarySubCommand { +public class PermissionUnset extends SharedSubCommand { public PermissionUnset() { super("unset", "Unsets a permission for the object", Permission.USER_PERM_UNSET, Permission.GROUP_PERM_UNSET, Predicates.notInRange(1, 3), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java index f8c24d5f6..8e23311ab 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java @@ -24,7 +24,7 @@ package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; -import me.lucko.luckperms.common.commands.generic.SecondarySubCommand; +import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.PermissionHolder; @@ -35,7 +35,7 @@ import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.List; import java.util.stream.Collectors; -public class PermissionUnsetTemp extends SecondarySubCommand { +public class PermissionUnsetTemp extends SharedSubCommand { public PermissionUnsetTemp() { super("unsettemp", "Unsets a temporary permission for the object", Permission.USER_PERM_UNSETTEMP, Permission.GROUP_PERM_UNSETTEMP, Predicates.notInRange(1, 3), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/CreateGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/CreateGroup.java index 9fc0ea66f..47675ad60 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/CreateGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/CreateGroup.java @@ -23,23 +23,29 @@ package me.lucko.luckperms.common.commands.group; import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SingleMainCommand; +import me.lucko.luckperms.common.commands.SingleCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.utils.ArgumentChecker; +import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -public class CreateGroup extends SingleMainCommand { +public class CreateGroup extends SingleCommand { public CreateGroup() { - super("CreateGroup", "/%s creategroup ", 1, Permission.CREATE_GROUP); + super("CreateGroup", "Create a new group", "/%s creategroup ", Permission.CREATE_GROUP, Predicates.not(1), + Arg.list( + Arg.create("name", true, "the name of the group") + ) + ); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { if (args.size() == 0) { sendUsage(sender, label); return CommandResult.INVALID_ARGS; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java index cb2f82f0f..d6d274978 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java @@ -23,26 +23,32 @@ package me.lucko.luckperms.common.commands.group; import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SingleMainCommand; +import me.lucko.luckperms.common.commands.SingleCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.groups.Group; +import me.lucko.luckperms.common.utils.Predicates; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -public class DeleteGroup extends SingleMainCommand { +public class DeleteGroup extends SingleCommand { public DeleteGroup() { - super("DeleteGroup", "/%s deletegroup ", 1, Permission.DELETE_GROUP); + super("DeleteGroup", "Delete a group", "/%s deletegroup ", Permission.DELETE_GROUP, Predicates.not(1), + Arg.list( + Arg.create("name", true, "the name of the group") + ) + ); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { if (args.size() == 0) { sendUsage(sender, label); return CommandResult.INVALID_ARGS; @@ -78,7 +84,7 @@ public class DeleteGroup extends SingleMainCommand { } @Override - protected List onTabComplete(Sender sender, List args, LuckPermsPlugin plugin) { + public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { final List groups = new ArrayList<>(plugin.getGroupManager().getAll().keySet()); if (args.size() <= 1) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java index 4f3d75c24..d723e8b8c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java @@ -24,9 +24,9 @@ package me.lucko.luckperms.common.commands.group; import com.google.common.collect.ImmutableList; import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.commands.Command; import me.lucko.luckperms.common.commands.MainCommand; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.generic.meta.CommandMeta; import me.lucko.luckperms.common.commands.generic.other.HolderShowTracks; import me.lucko.luckperms.common.commands.generic.parent.CommandParent; @@ -40,17 +40,17 @@ import java.util.List; public class GroupMainCommand extends MainCommand { public GroupMainCommand() { - super("Group", "/%s group ", 2, ImmutableList.>builder() - .add(new GroupInfo()) - .add(new CommandPermission<>(false)) - .add(new CommandParent<>(false)) - .add(new CommandMeta<>(false)) - .add(new HolderShowTracks<>(false)) - .add(new GroupBulkChange()) - .add(new GroupClear()) - .add(new GroupRename()) - .add(new GroupClone()) - .build() + super("Group", "Group commands", "/%s group ", 2, ImmutableList.>builder() + .add(new GroupInfo()) + .add(new CommandPermission<>(false)) + .add(new CommandParent<>(false)) + .add(new CommandMeta<>(false)) + .add(new HolderShowTracks<>(false)) + .add(new GroupBulkChange()) + .add(new GroupClear()) + .add(new GroupRename()) + .add(new GroupClone()) + .build() ); } @@ -76,7 +76,7 @@ public class GroupMainCommand extends MainCommand { } @Override - protected List getObjects(LuckPermsPlugin plugin) { + protected List getTargets(LuckPermsPlugin plugin) { return new ArrayList<>(plugin.getGroupManager().getAll().keySet()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java index 591a65d7d..6c4603285 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java @@ -25,23 +25,24 @@ package me.lucko.luckperms.common.commands.group; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SingleMainCommand; +import me.lucko.luckperms.common.commands.SingleCommand; import me.lucko.luckperms.common.commands.Util; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.groups.Group; +import me.lucko.luckperms.common.utils.Predicates; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -public class ListGroups extends SingleMainCommand { +public class ListGroups extends SingleCommand { public ListGroups() { - super("ListGroups", "/%s listgroups", 0, Permission.LIST_GROUPS); + super("ListGroups", "List all groups on the platform", "/%s listgroups", Permission.LIST_GROUPS, Predicates.alwaysFalse(), null); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { if (!plugin.getDatastore().loadAllGroups().getUnchecked()) { Message.GROUPS_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java index 33ad42f89..46dd8c19f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java @@ -24,9 +24,9 @@ package me.lucko.luckperms.common.commands.log; import com.google.common.collect.ImmutableList; import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.commands.Command; import me.lucko.luckperms.common.commands.MainCommand; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.log.subcommands.*; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.data.Log; @@ -38,15 +38,15 @@ import java.util.stream.Collectors; public class LogMainCommand extends MainCommand { public LogMainCommand() { - super("Log", "/%s log", 1, ImmutableList.>builder() - .add(new LogRecent()) - .add(new LogSearch()) - .add(new LogNotify()) - .add(new LogExport()) - .add(new LogUserHistory()) - .add(new LogGroupHistory()) - .add(new LogTrackHistory()) - .build() + super("Log", "Log commands", "/%s log", 1, ImmutableList.>builder() + .add(new LogRecent()) + .add(new LogSearch()) + .add(new LogNotify()) + .add(new LogExport()) + .add(new LogUserHistory()) + .add(new LogGroupHistory()) + .add(new LogTrackHistory()) + .build() ); } @@ -67,13 +67,13 @@ public class LogMainCommand extends MainCommand { } @Override - protected List getObjects(LuckPermsPlugin plugin) { + protected List getTargets(LuckPermsPlugin plugin) { return null; } @Override - protected List onTabComplete(Sender sender, List args, LuckPermsPlugin plugin) { - final List> subs = getSubCommands().stream() + public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { + final List> subs = getSubCommands().stream() .filter(s -> s.isAuthorized(sender)) .collect(Collectors.toList()); @@ -90,7 +90,7 @@ public class LogMainCommand extends MainCommand { .collect(Collectors.toList()); } - Optional> o = subs.stream() + Optional> o = subs.stream() .filter(s -> s.getName().equalsIgnoreCase(args.get(0))) .limit(1) .findAny(); @@ -99,6 +99,6 @@ public class LogMainCommand extends MainCommand { return Collections.emptyList(); } - return o.get().onTabComplete(plugin, sender, args.subList(1, args.size())); + return o.get().tabComplete(plugin, sender, args.subList(1, args.size())); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationMainCommand.java index d5efd556d..bd3aea4bc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationMainCommand.java @@ -22,98 +22,91 @@ package me.lucko.luckperms.common.commands.migration; +import com.google.common.collect.ImmutableList; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.commands.CommandResult; -import me.lucko.luckperms.common.commands.MainCommand; -import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SubCommand; +import me.lucko.luckperms.common.commands.*; import me.lucko.luckperms.common.constants.Constants; import me.lucko.luckperms.common.constants.Message; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; public class MigrationMainCommand extends MainCommand { - private final List> subCommands = new ArrayList<>(); - public MigrationMainCommand() { - super("Migration", "/%s migration", 1, null); + super("Migration", "Migration commands", "/%s migration", 1, ImmutableList.copyOf(getAvailableCommands())); + } + + private static List> getAvailableCommands() { + List> l = new ArrayList<>(); try { Class.forName("org.anjocaido.groupmanager.GroupManager"); - subCommands.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationGroupManager").newInstance()); + l.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationGroupManager").newInstance()); } catch (Throwable ignored) {} try { Class.forName("ru.tehkode.permissions.bukkit.PermissionsEx"); - subCommands.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationPermissionsEx").newInstance()); + l.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationPermissionsEx").newInstance()); } catch (Throwable ignored) {} try { Class.forName("com.github.cheesesoftware.PowerfulPermsAPI.PowerfulPermsPlugin"); - subCommands.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationPowerfulPerms").newInstance()); + l.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationPowerfulPerms").newInstance()); } catch (Throwable ignored) {} try { Class.forName("org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService"); - subCommands.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationZPermissions").newInstance()); + l.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationZPermissions").newInstance()); } catch (Throwable ignored) {} try { Class.forName("net.alpenblock.bungeeperms.BungeePerms"); - subCommands.add((SubCommand) Class.forName("me.lucko.luckperms.bungee.migration.MigrationBungeePerms").newInstance()); + l.add((SubCommand) Class.forName("me.lucko.luckperms.bungee.migration.MigrationBungeePerms").newInstance()); } catch (Throwable ignored) {} try { Class.forName("de.bananaco.bpermissions.api.WorldManager"); - subCommands.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationBPermissions").newInstance()); + l.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationBPermissions").newInstance()); } catch (Throwable ignored) {} try { Class.forName("ninja.leaping.permissionsex.sponge.PermissionsExPlugin"); - subCommands.add((SubCommand) Class.forName("me.lucko.luckperms.sponge.migration.MigrationPermissionsEx").newInstance()); + l.add((SubCommand) Class.forName("me.lucko.luckperms.sponge.migration.MigrationPermissionsEx").newInstance()); } catch (Throwable ignored) {} + + return l.stream().collect(Collectors.toList()); } @Override - public List> getSubCommands() { - return subCommands; - } - - @Override - protected boolean isAuthorized(Sender sender) { + public boolean isAuthorized(Sender sender) { return sender.getUuid().equals(Constants.getConsoleUUID()); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List args, String label) throws CommandException { if (!sender.getUuid().equals(Constants.getConsoleUUID())) { Message.MIGRATION_NOT_CONSOLE.send(sender); return CommandResult.NO_PERMISSION; } - return super.execute(plugin, sender, args, label); + return super.execute(plugin, sender, v, args, label); } @Override - protected Object getTarget(String target, LuckPermsPlugin plugin, Sender sender) { - return new Object(); - } - - @Override - protected void cleanup(Object object, LuckPermsPlugin plugin) { - - } - - @Override - protected List getObjects(LuckPermsPlugin plugin) { + protected List getTargets(LuckPermsPlugin plugin) { return Collections.emptyList(); } @Override - protected List onTabComplete(Sender sender, List args, LuckPermsPlugin plugin) { - return Collections.emptyList(); + protected Void getTarget(String target, LuckPermsPlugin plugin, Sender sender) { + return null; + } + + @Override + protected void cleanup(Object o, LuckPermsPlugin plugin) { + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/DebugCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/DebugCommand.java index f21d88264..2a8d39f2b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/DebugCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/DebugCommand.java @@ -25,19 +25,20 @@ package me.lucko.luckperms.common.commands.misc; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SingleMainCommand; +import me.lucko.luckperms.common.commands.SingleCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; +import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -public class DebugCommand extends SingleMainCommand { +public class DebugCommand extends SingleCommand { public DebugCommand() { - super("Debug", "/%s debug", 0, Permission.DEBUG); + super("Debug", "Print debugging output", "/%s debug", Permission.DEBUG, Predicates.alwaysFalse(), null); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { plugin.getLog().info(sender.getName() + " used the debug command."); Message.DEBUG.send(sender, plugin.getPlayerCount(), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java index 767b93094..5e991477c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java @@ -25,9 +25,10 @@ package me.lucko.luckperms.common.commands.misc; import me.lucko.luckperms.api.Logger; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SingleMainCommand; +import me.lucko.luckperms.common.commands.SingleCommand; import me.lucko.luckperms.common.constants.Constants; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; @@ -35,6 +36,7 @@ import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.storage.Datastore; import me.lucko.luckperms.common.tracks.Track; import me.lucko.luckperms.common.users.User; +import me.lucko.luckperms.common.utils.Predicates; import java.io.BufferedWriter; import java.io.File; @@ -45,13 +47,17 @@ import java.util.List; import java.util.Set; import java.util.UUID; -public class ExportCommand extends SingleMainCommand { +public class ExportCommand extends SingleCommand { public ExportCommand() { - super("Export", "/%s export ", 1, Permission.MIGRATION); + super("Export", "Export data to a file", "/%s export ", Permission.MIGRATION, Predicates.not(1), + Arg.list( + Arg.create("file", true, "the file to export to") + ) + ); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { final Logger log = plugin.getLog(); if (!sender.getUuid().equals(Constants.getConsoleUUID())) { @@ -164,7 +170,7 @@ public class ExportCommand extends SingleMainCommand { } @Override - protected boolean isAuthorized(Sender sender) { + public boolean isAuthorized(Sender sender) { return sender.getUuid().equals(Constants.getConsoleUUID()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ImportCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ImportCommand.java index b9fc67c10..17c50638a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ImportCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ImportCommand.java @@ -23,12 +23,14 @@ package me.lucko.luckperms.common.commands.misc; import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SingleMainCommand; +import me.lucko.luckperms.common.commands.SingleCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.data.Importer; +import me.lucko.luckperms.common.utils.Predicates; import java.io.File; import java.io.IOException; @@ -36,13 +38,17 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.util.List; -public class ImportCommand extends SingleMainCommand { +public class ImportCommand extends SingleCommand { public ImportCommand() { - super("Import", "/%s import ", 1, Permission.IMPORT); + super("Import", "Import data from a file", "/%s import ", Permission.IMPORT, Predicates.not(1), + Arg.list( + Arg.create("file", true, "the file to import from") + ) + ); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { if (args.size() == 0) { sendUsage(sender, label); return CommandResult.INVALID_ARGS; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java index e0009a21d..3723ecde0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java @@ -25,22 +25,23 @@ package me.lucko.luckperms.common.commands.misc; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SingleMainCommand; +import me.lucko.luckperms.common.commands.SingleCommand; import me.lucko.luckperms.common.config.LPConfiguration; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; +import me.lucko.luckperms.common.utils.Predicates; import java.util.List; import static me.lucko.luckperms.common.commands.Util.formatBoolean; -public class InfoCommand extends SingleMainCommand { +public class InfoCommand extends SingleCommand { public InfoCommand() { - super("Info", "/%s info", 0, Permission.INFO); + super("Info", "Print general plugin info", "/%s info", Permission.INFO, Predicates.alwaysFalse(), null); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { final LPConfiguration c = plugin.getConfiguration(); Message.INFO.send(sender, plugin.getVersion(), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java index 580ea9c6a..4840f0973 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java @@ -25,19 +25,21 @@ package me.lucko.luckperms.common.commands.misc; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SingleMainCommand; +import me.lucko.luckperms.common.commands.SingleCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; +import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -public class NetworkSyncCommand extends SingleMainCommand { +public class NetworkSyncCommand extends SingleCommand { public NetworkSyncCommand() { - super("NetworkSync", "/%s networksync", 0, Permission.SYNC); + super("NetworkSync", "Sync changes with the storage and request that all other servers on the network do the same", + "/%s networksync", Permission.SYNC, Predicates.alwaysFalse(), null); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { Message.UPDATE_TASK_REQUEST.send(sender); plugin.getUpdateTaskBuffer().request().getUnchecked(); Message.UPDATE_TASK_COMPLETE_NETWORK.send(sender); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/QueueCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/QueueCommand.java index fe3314ff3..931c649c4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/QueueCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/QueueCommand.java @@ -23,22 +23,24 @@ package me.lucko.luckperms.common.commands.misc; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.commands.CommandResult; -import me.lucko.luckperms.common.commands.ConsecutiveExecutor; -import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SingleMainCommand; +import me.lucko.luckperms.common.commands.*; import me.lucko.luckperms.common.constants.Constants; import me.lucko.luckperms.common.constants.Permission; +import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -public class QueueCommand extends SingleMainCommand { +public class QueueCommand extends SingleCommand { public QueueCommand() { - super("QueueCommand", "/%s queuecommand ", 1, Permission.MIGRATION); + super("QueueCommand", "Queue a command for execution", "/%s queuecommand ", Permission.MIGRATION, Predicates.not(1), + Arg.list( + Arg.create("command args...", true, "the command's arguments") + ) + ); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { if (args.get(0).equalsIgnoreCase(getName())) { // Prevent infinite loops return CommandResult.FAILURE; @@ -49,7 +51,7 @@ public class QueueCommand extends SingleMainCommand { } @Override - protected boolean isAuthorized(Sender sender) { + public boolean isAuthorized(Sender sender) { return sender.getUuid().equals(Constants.getConsoleUUID()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/SyncCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/SyncCommand.java index 1442d3851..8d3ad284a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/SyncCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/SyncCommand.java @@ -25,19 +25,20 @@ package me.lucko.luckperms.common.commands.misc; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SingleMainCommand; +import me.lucko.luckperms.common.commands.SingleCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; +import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -public class SyncCommand extends SingleMainCommand { +public class SyncCommand extends SingleCommand { public SyncCommand() { - super("Sync", "/%s sync", 0, Permission.SYNC); + super("Sync", "Sync changes with the storage", "/%s sync", Permission.SYNC, Predicates.alwaysFalse(), null); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { Message.UPDATE_TASK_REQUEST.send(sender); plugin.getUpdateTaskBuffer().request().getUnchecked(); Message.UPDATE_TASK_COMPLETE.send(sender); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/VerboseCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/VerboseCommand.java index f58cf5972..a21937630 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/VerboseCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/VerboseCommand.java @@ -23,23 +23,30 @@ package me.lucko.luckperms.common.commands.misc; import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SingleMainCommand; +import me.lucko.luckperms.common.commands.SingleCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; +import me.lucko.luckperms.common.utils.Predicates; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -public class VerboseCommand extends SingleMainCommand { +public class VerboseCommand extends SingleCommand { public VerboseCommand() { - super("Verbose", "/%s verbose [filters...]", 1, Permission.VERBOSE); + super("Verbose", "Enable verbose permission check output", "/%s verbose [filters...]", Permission.VERBOSE, Predicates.is(0), + Arg.list( + Arg.create("true|false", true, "whether to enable the feature"), + Arg.create("filters...", false, "the name of the user / start of the node to filter by") + ) + ); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { if (args.isEmpty()) { sendUsage(sender, label); return CommandResult.INVALID_ARGS; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java index 59734a2f1..347c0b511 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java @@ -23,23 +23,29 @@ package me.lucko.luckperms.common.commands.track; import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SingleMainCommand; +import me.lucko.luckperms.common.commands.SingleCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.utils.ArgumentChecker; +import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -public class CreateTrack extends SingleMainCommand { +public class CreateTrack extends SingleCommand { public CreateTrack() { - super("CreateTrack", "/%s createtrack ", 1, Permission.CREATE_TRACK); + super("CreateTrack", "Create a new track", "/%s createtrack ", Permission.CREATE_TRACK, Predicates.not(1), + Arg.list( + Arg.create("name", true, "the name of the track") + ) + ); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { if (args.size() == 0) { sendUsage(sender, label); return CommandResult.INVALID_ARGS; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java index 9265f58fb..a494bb738 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java @@ -23,26 +23,32 @@ package me.lucko.luckperms.common.commands.track; import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SingleMainCommand; +import me.lucko.luckperms.common.commands.SingleCommand; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.tracks.Track; +import me.lucko.luckperms.common.utils.Predicates; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -public class DeleteTrack extends SingleMainCommand { +public class DeleteTrack extends SingleCommand { public DeleteTrack() { - super("DeleteTrack", "/%s deletetrack ", 1, Permission.DELETE_TRACK); + super("DeleteTrack", "Delete a track", "/%s deletetrack ", Permission.DELETE_TRACK, Predicates.not(1), + Arg.list( + Arg.create("name", true, "the name of the track") + ) + ); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { if (args.size() == 0) { sendUsage(sender, label); return CommandResult.INVALID_ARGS; @@ -72,7 +78,7 @@ public class DeleteTrack extends SingleMainCommand { } @Override - protected List onTabComplete(Sender sender, List args, LuckPermsPlugin plugin) { + public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { final List tracks = new ArrayList<>(plugin.getTrackManager().getAll().keySet()); if (args.size() <= 1) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/ListTracks.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/ListTracks.java index 1405d5c69..064273edf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/ListTracks.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/ListTracks.java @@ -25,21 +25,22 @@ package me.lucko.luckperms.common.commands.track; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SingleMainCommand; +import me.lucko.luckperms.common.commands.SingleCommand; import me.lucko.luckperms.common.commands.Util; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; +import me.lucko.luckperms.common.utils.Predicates; import java.util.ArrayList; import java.util.List; -public class ListTracks extends SingleMainCommand { +public class ListTracks extends SingleCommand { public ListTracks() { - super("ListTracks", "/%s listtracks", 0, Permission.LIST_TRACKS); + super("ListTracks", "List all tracks on the platform", "/%s listtracks", Permission.LIST_TRACKS, Predicates.alwaysFalse(), null); } @Override - protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { if (!plugin.getDatastore().loadAllTracks().getUnchecked()) { Message.TRACKS_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java index 27d8e8116..756320496 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java @@ -24,9 +24,9 @@ package me.lucko.luckperms.common.commands.track; import com.google.common.collect.ImmutableList; import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.commands.Command; import me.lucko.luckperms.common.commands.MainCommand; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.track.subcommands.*; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.tracks.Track; @@ -36,15 +36,15 @@ import java.util.List; public class TrackMainCommand extends MainCommand { public TrackMainCommand() { - super("Track", "/%s track ", 2, ImmutableList.>builder() - .add(new TrackInfo()) - .add(new TrackAppend()) - .add(new TrackInsert()) - .add(new TrackRemove()) - .add(new TrackClear()) - .add(new TrackRename()) - .add(new TrackClone()) - .build() + super("Track", "Track commands", "/%s track ", 2, ImmutableList.>builder() + .add(new TrackInfo()) + .add(new TrackAppend()) + .add(new TrackInsert()) + .add(new TrackRemove()) + .add(new TrackClear()) + .add(new TrackRename()) + .add(new TrackClone()) + .build() ); } @@ -70,7 +70,7 @@ public class TrackMainCommand extends MainCommand { } @Override - protected List getObjects(LuckPermsPlugin plugin) { + protected List getTargets(LuckPermsPlugin plugin) { return new ArrayList<>(plugin.getTrackManager().getAll().keySet()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackAppend.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackAppend.java index a33fb8c56..ec84504cd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackAppend.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackAppend.java @@ -47,7 +47,7 @@ public class TrackAppend extends SubCommand { String groupName = args.get(0).toLowerCase(); if (ArgumentChecker.checkNode(groupName)) { - sendDetailedUsage(sender); + sendDetailedUsage(sender, label); return CommandResult.INVALID_ARGS; } @@ -80,7 +80,7 @@ public class TrackAppend extends SubCommand { } @Override - public List onTabComplete(LuckPermsPlugin plugin, Sender sender, List args) { + public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { return getGroupTabComplete(args, plugin); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackInsert.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackInsert.java index 828ca5c4c..b22bd3cf4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackInsert.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackInsert.java @@ -50,7 +50,7 @@ public class TrackInsert extends SubCommand { String groupName = args.get(0).toLowerCase(); if (ArgumentChecker.checkNode(groupName)) { - sendDetailedUsage(sender); + sendDetailedUsage(sender, label); return CommandResult.INVALID_ARGS; } @@ -94,7 +94,7 @@ public class TrackInsert extends SubCommand { } @Override - public List onTabComplete(LuckPermsPlugin plugin, Sender sender, List args) { + public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { return getGroupTabComplete(args, plugin); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackRemove.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackRemove.java index 74640241b..23561c01d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackRemove.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/subcommands/TrackRemove.java @@ -46,7 +46,7 @@ public class TrackRemove extends SubCommand { String groupName = args.get(0).toLowerCase(); if (ArgumentChecker.checkNode(groupName)) { - sendDetailedUsage(sender); + sendDetailedUsage(sender, label); return CommandResult.INVALID_ARGS; } @@ -68,7 +68,7 @@ public class TrackRemove extends SubCommand { } @Override - public List onTabComplete(LuckPermsPlugin plugin, Sender sender, List args) { + public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { return getGroupTabComplete(args, plugin); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java index 45d6d36a8..e50d47390 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java @@ -24,9 +24,9 @@ package me.lucko.luckperms.common.commands.user; import com.google.common.collect.ImmutableList; import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.commands.Command; import me.lucko.luckperms.common.commands.MainCommand; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.Util; import me.lucko.luckperms.common.commands.generic.meta.CommandMeta; import me.lucko.luckperms.common.commands.generic.other.HolderShowTracks; @@ -42,7 +42,7 @@ import java.util.UUID; public class UserMainCommand extends MainCommand { public UserMainCommand() { - super("User", "/%s user ", 2, ImmutableList.>builder() + super("User", "User commands", "/%s user ", 2, ImmutableList.>builder() .add(new UserInfo()) .add(new CommandPermission<>(true)) .add(new CommandParent<>(true)) @@ -100,7 +100,7 @@ public class UserMainCommand extends MainCommand { } @Override - protected List getObjects(LuckPermsPlugin plugin) { + protected List getTargets(LuckPermsPlugin plugin) { return plugin.getPlayerList(); } } \ No newline at end of file diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserDemote.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserDemote.java index eca1be292..e92a7734f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserDemote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserDemote.java @@ -183,7 +183,7 @@ public class UserDemote extends SubCommand { } @Override - public List onTabComplete(LuckPermsPlugin plugin, Sender sender, List args) { + public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { return getTrackTabComplete(args, plugin); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserPromote.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserPromote.java index 136345661..b9c351538 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserPromote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserPromote.java @@ -183,7 +183,7 @@ public class UserPromote extends SubCommand { } @Override - public List onTabComplete(LuckPermsPlugin plugin, Sender sender, List args) { + public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { return getTrackTabComplete(args, plugin); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserSetPrimaryGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserSetPrimaryGroup.java index dd2f18528..f04b439ce 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserSetPrimaryGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/subcommands/UserSetPrimaryGroup.java @@ -72,7 +72,7 @@ public class UserSetPrimaryGroup extends SubCommand { } @Override - public List onTabComplete(LuckPermsPlugin plugin, Sender sender, List args) { + public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { return getGroupTabComplete(args, plugin); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/UsersBulkEditMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/UsersBulkEditMainCommand.java index 09126a0d9..eb30959dd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/UsersBulkEditMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/UsersBulkEditMainCommand.java @@ -24,9 +24,9 @@ package me.lucko.luckperms.common.commands.usersbulkedit; import com.google.common.collect.ImmutableList; import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.commands.Command; import me.lucko.luckperms.common.commands.MainCommand; import me.lucko.luckperms.common.commands.Sender; -import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.usersbulkedit.subcommands.BulkEditGroup; import me.lucko.luckperms.common.commands.usersbulkedit.subcommands.BulkEditPermission; import me.lucko.luckperms.common.storage.Datastore; @@ -39,10 +39,10 @@ import java.util.stream.Collectors; public class UsersBulkEditMainCommand extends MainCommand { public UsersBulkEditMainCommand() { - super("UsersBulkEdit", "/%s usersbulkedit", 1, ImmutableList.>builder() - .add(new BulkEditGroup()) - .add(new BulkEditPermission()) - .build() + super("UsersBulkEdit", "User bulk edit commands", "/%s usersbulkedit", 1, ImmutableList.>builder() + .add(new BulkEditGroup()) + .add(new BulkEditPermission()) + .build() ); } @@ -57,13 +57,13 @@ public class UsersBulkEditMainCommand extends MainCommand { } @Override - protected List getObjects(LuckPermsPlugin plugin) { + protected List getTargets(LuckPermsPlugin plugin) { return null; } @Override - protected List onTabComplete(Sender sender, List args, LuckPermsPlugin plugin) { - final List> subs = getSubCommands().stream() + public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { + final List> subs = getSubCommands().stream() .filter(s -> s.isAuthorized(sender)) .collect(Collectors.toList()); @@ -80,7 +80,7 @@ public class UsersBulkEditMainCommand extends MainCommand { .collect(Collectors.toList()); } - Optional> o = subs.stream() + Optional> o = subs.stream() .filter(s -> s.getName().equalsIgnoreCase(args.get(0))) .limit(1) .findAny(); @@ -89,6 +89,6 @@ public class UsersBulkEditMainCommand extends MainCommand { return Collections.emptyList(); } - return o.get().onTabComplete(plugin, sender, args.subList(1, args.size())); + return o.get().tabComplete(plugin, sender, args.subList(1, args.size())); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/Predicates.java b/common/src/main/java/me/lucko/luckperms/common/utils/Predicates.java index c60f931c3..adf43d84d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/Predicates.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/Predicates.java @@ -35,12 +35,15 @@ import java.util.stream.IntStream; @SuppressWarnings({"WeakerAccess", "unused"}) @UtilityClass public class Predicates { + private static final Predicate FALSE = o -> false; + private static final Predicate TRUE = o -> true; + public static Predicate alwaysFalse() { - return t -> false; + return FALSE; } public static Predicate alwaysTrue() { - return t -> true; + return TRUE; } public static Predicate notInRange(Integer start, Integer end) {