From a22bcb1c2aba40f6b7251b7533177099f444d552 Mon Sep 17 00:00:00 2001 From: thislooksfun Date: Thu, 19 Mar 2020 17:23:11 -0500 Subject: [PATCH] Fix tab completion --- .../com/sk89q/worldedit/bukkit/WorldEditPlugin.java | 2 ++ .../extension/platform/PlatformCommandManager.java | 10 ++++++---- 2 files changed, 8 insertions(+), 4 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 3a2c2d7fd..e2ace7f6a 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 @@ -654,6 +654,8 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter int firstSpace = buffer.indexOf(' '); if (firstSpace < 0) return; String label = buffer.substring(0, firstSpace); + // Strip leading slash, if present. + label = label.startsWith("/") ? label.substring(1) : label; final Optional command = WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().getCommand(label); if (!command.isPresent()) return; 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 205a5e966..dbd1e841b 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 @@ -815,7 +815,10 @@ public final class PlatformCommandManager { @Subscribe public void handleCommandSuggestion(CommandSuggestionEvent event) { try { - String arguments = event.getArguments(); + String rawArgs = event.getArguments(); + // Increase the resulting positions by 1 if we remove a leading `/` + final int posOffset = rawArgs.startsWith("/") ? 1 : 0; + String arguments = rawArgs.startsWith("/") ? rawArgs.substring(1) : rawArgs; List split = parseArgs(arguments).collect(Collectors.toList()); List argStrings = split.stream() .map(Substring::getSubstring) @@ -837,11 +840,10 @@ public final class PlatformCommandManager { Substring original = suggestion.getReplacedArgument() == split.size() ? Substring.from(arguments, noSlashLength, noSlashLength) : split.get(suggestion.getReplacedArgument()); - // increase original points by 1, for removed `/` in `parseArgs` return Substring.wrap( suggestion.getSuggestion(), - original.getStart() + 1, - original.getEnd() + 1 + original.getStart() + posOffset, + original.getEnd() + posOffset ); }).collect(Collectors.toList())); } catch (ConditionFailedException e) {