From 3c04a83852f66017be902117cc13ea89d56fe5ae Mon Sep 17 00:00:00 2001 From: wizjany Date: Mon, 29 Apr 2019 17:39:30 -0400 Subject: [PATCH] Add nicer error when using player commands as console. Also fix slash counts for Bukkit. --- .../main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java | 4 ++-- .../worldedit/extension/platform/PlatformCommandManager.java | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index 1c824dcec..99652499d 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -289,7 +289,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { // code of WorldEdit expects it String[] split = new String[args.length + 1]; System.arraycopy(args, 0, split, 1, args.length); - split[0] = cmd.getName(); + split[0] = "/" + cmd.getName(); CommandEvent event = new CommandEvent(wrapCommandSender(sender), Joiner.on(" ").join(split)); getWorldEdit().getEventBus().post(event); @@ -303,7 +303,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { // code of WorldEdit expects it String[] split = new String[args.length + 1]; System.arraycopy(args, 0, split, 1, args.length); - split[0] = cmd.getName(); + split[0] = "/" + cmd.getName(); CommandSuggestionEvent event = new CommandSuggestionEvent(wrapCommandSender(sender), Joiner.on(" ").join(split)); getWorldEdit().getEventBus().post(event); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java index be9a03500..f1f7380a4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java @@ -469,6 +469,10 @@ public final class PlatformCommandManager { store.injectValue(Key.of(Actor.class), ValueProvider.constant(actor)); if (actor instanceof Player) { store.injectValue(Key.of(Player.class), ValueProvider.constant((Player) actor)); + } else { + store.injectValue(Key.of(Player.class), context -> { + throw new CommandException(TextComponent.of("This command must be used with a player."), ImmutableList.of()); + }); } store.injectValue(Key.of(Arguments.class), ValueProvider.constant(event::getArguments)); store.injectValue(Key.of(LocalSession.class),