Add player argument to'/lp verbose command' to execute the test command as another player

This commit is contained in:
Luck 2020-06-04 01:32:56 +01:00
parent e37c77a1be
commit 8996cf02af
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 33 additions and 21 deletions

View File

@ -17,9 +17,11 @@ luckperms {
filter brigadier:string greedy_phrase;
}
command {
player brigadier:string single_word {
command brigadier:string greedy_phrase;
}
}
}
tree {
scope brigadier:string single_word {
player brigadier:string single_word;

View File

@ -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),

View File

@ -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);

View File

@ -66,7 +66,8 @@ public enum CommandSpec {
VERBOSE("Controls the plugins verbose permission check monitoring system.", "/%s verbose <on|record|off|upload> [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("<me|player> <command>", false, "the player/command to run")
)
),
TREE("Generates a tree view (ordered list hierarchy) of all permissions known to LuckPerms.", "/%s tree [scope] [player]",

View File

@ -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.
*