diff --git a/src/main/java/de/mcmdev/vanish/command/VanishCommand.java b/src/main/java/de/mcmdev/vanish/command/VanishCommand.java index 4a52ca9..20bf00c 100644 --- a/src/main/java/de/mcmdev/vanish/command/VanishCommand.java +++ b/src/main/java/de/mcmdev/vanish/command/VanishCommand.java @@ -24,6 +24,7 @@ import de.mcmdev.vanish.VanishPlugin; import de.mcmdev.vanish.api.VanishApi; import de.mcmdev.vanish.config.Config; +import io.papermc.paper.command.brigadier.argument.ArgumentTypes; import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.Commands; import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; @@ -50,14 +51,22 @@ public void register() { private LiteralCommandNode createCommandNode() { return Commands.literal("vanish") - .requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("vanish.command")) + .requires(source -> source.getSender().hasPermission("vanish.command")) .executes(this::run) + .then( + Commands.argument("target", ArgumentTypes.player()) + .requires(source -> source.getSender().hasPermission("vanish.command.others")) + .executes(this::run) + ) .then( Commands.literal("setlevel") - .requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("vanish.command.setlevel")) + .requires(source -> source.getSender().hasPermission("vanish.command.setlevel")) .executes(this::runSetlevel) .then( - Commands.argument("level", IntegerArgumentType.integer(0, config.maximumHidingLevel())) + Commands.argument( + "level", + IntegerArgumentType.integer(0, config.maximumHidingLevel()) + ) .executes(this::runSetlevelLevel) ) ) @@ -65,16 +74,24 @@ private LiteralCommandNode createCommandNode() { } private int run(final CommandContext context) { - if (!(context.getSource().getExecutor() instanceof final Player player)) { - return 1; + + Player target; + + if (context.getArguments().containsKey("target")) { + target = context.getArgument("target", Player.class); + } else { + if (!(context.getSource().getExecutor() instanceof Player player)) { + return 1; + } + target = player; } - if (vanishApi.isVanished(player)) { - vanishApi.unvanish(player); - config.messages().toggleOff().send(player); + if (vanishApi.isVanished(target)) { + vanishApi.unvanish(target); + config.messages().toggleOff().send(target); } else { - vanishApi.vanish(player); - config.messages().toggleOn().send(player); + vanishApi.vanish(target); + config.messages().toggleOn().send(target); } return 0;