From 8996cf02afee9fd5fbc9751f238b816c91e7e4b3 Mon Sep 17 00:00:00 2001 From: Luck Date: Thu, 4 Jun 2020 01:32:56 +0100 Subject: [PATCH] Add player argument to'/lp verbose command' to execute the test command as another player --- bukkit/src/main/resources/luckperms.commodore | 4 ++- .../command/access/CommandPermission.java | 1 + .../common/commands/misc/VerboseCommand.java | 34 +++++++++++++++---- .../common/locale/command/CommandSpec.java | 3 +- .../lucko/luckperms/common/sender/Sender.java | 12 ------- 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/bukkit/src/main/resources/luckperms.commodore b/bukkit/src/main/resources/luckperms.commodore index cff691cfc..146b96fc5 100644 --- a/bukkit/src/main/resources/luckperms.commodore +++ b/bukkit/src/main/resources/luckperms.commodore @@ -17,7 +17,9 @@ luckperms { filter brigadier:string greedy_phrase; } command { - command brigadier:string greedy_phrase; + player brigadier:string single_word { + command brigadier:string greedy_phrase; + } } } tree { diff --git a/common/src/main/java/me/lucko/luckperms/common/command/access/CommandPermission.java b/common/src/main/java/me/lucko/luckperms/common/command/access/CommandPermission.java index 74bd066f7..fb7ef3999 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/access/CommandPermission.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/access/CommandPermission.java @@ -37,6 +37,7 @@ public enum CommandPermission { EDITOR("editor", Type.NONE), DEBUG("debug", Type.NONE), VERBOSE("verbose", Type.NONE), + VERBOSE_COMMAND_OTHER("verbose.commandother", Type.NONE), TREE("tree", Type.NONE), SEARCH("search", Type.NONE), CHECK("check", Type.NONE), 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 e429290d2..59ab5fba0 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 @@ -52,7 +52,6 @@ import net.kyori.text.format.TextColor; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Executor; public class VerboseCommand extends SingleCommand { public VerboseCommand(LocaleManager locale) { @@ -70,20 +69,41 @@ public class VerboseCommand extends SingleCommand { String mode = args.get(0).toLowerCase(); if (mode.equals("command") || mode.equals("cmd")) { - if (args.size() == 1) { + if (args.size() < 3) { sendDetailedUsage(sender, label); return CommandResult.INVALID_ARGS; } - String commandWithSlash = String.join(" ", args.subList(1, args.size())); + String executorName = args.get(1); + Sender executor; + + if (executorName.equalsIgnoreCase("me") || executorName.equalsIgnoreCase(sender.getName())) { + executor = sender; + } else { + if (!CommandPermission.VERBOSE_COMMAND_OTHER.isAuthorized(sender)) { + Message.COMMAND_NO_PERMISSION.send(sender); + return CommandResult.NO_PERMISSION; + } + + executor = plugin.getOnlineSenders() + .filter(s -> s.getName().equalsIgnoreCase(executorName)) + .findAny() + .orElse(null); + + if (executor == null) { + Message.USER_NOT_ONLINE.send(sender, executorName); + return CommandResult.STATE_ERROR; + } + } + + String commandWithSlash = String.join(" ", args.subList(2, args.size())); String command = commandWithSlash.charAt(0) == '/' ? commandWithSlash.substring(1) : commandWithSlash; - Executor syncExecutor = plugin.getBootstrap().getScheduler().sync(); - syncExecutor.execute(() -> { - Message.VERBOSE_ON_COMMAND.send(sender, sender.getName(), command); + plugin.getBootstrap().getScheduler().sync().execute(() -> { + Message.VERBOSE_ON_COMMAND.send(sender, executor.getName(), command); verboseHandler.registerListener(sender, VerboseFilter.acceptAll(), true); - sender.performCommand(command); + executor.performCommand(command); verboseHandler.unregisterListener(sender); Message.VERBOSE_OFF_COMMAND.send(sender); diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/command/CommandSpec.java b/common/src/main/java/me/lucko/luckperms/common/locale/command/CommandSpec.java index af59a5433..9f8c88434 100644 --- a/common/src/main/java/me/lucko/luckperms/common/locale/command/CommandSpec.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/command/CommandSpec.java @@ -66,7 +66,8 @@ public enum CommandSpec { VERBOSE("Controls the plugins verbose permission check monitoring system.", "/%s verbose [filter]", Argument.list( Argument.create("on|record|off|upload|command", true, "whether to enable/disable logging, or to upload the logged output"), - Argument.create("filter", false, "the filter to match entries against") + Argument.create("filter", false, "the filter to match entries against"), + Argument.create(" ", false, "the player/command to run") ) ), TREE("Generates a tree view (ordered list hierarchy) of all permissions known to LuckPerms.", "/%s tree [scope] [player]", diff --git a/common/src/main/java/me/lucko/luckperms/common/sender/Sender.java b/common/src/main/java/me/lucko/luckperms/common/sender/Sender.java index 2cdf53c92..11732f2f7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/sender/Sender.java +++ b/common/src/main/java/me/lucko/luckperms/common/sender/Sender.java @@ -96,18 +96,6 @@ public interface Sender { return name + "@" + location; } - /** - * Gets the name used to identify this sender in verbose events. - * - * @return the verbose check target name - */ - default String getVerboseCheckTarget() { - if (isConsole()) { - return "internal/console"; - } - return getName(); - } - /** * Gets the sender's unique id. *