3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-08 04:20:06 +01:00

Fix tab completion

Dieser Commit ist enthalten in:
thislooksfun 2020-03-19 17:23:11 -05:00
Ursprung 8a70f97445
Commit a22bcb1c2a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 5D5237F389B11752
2 geänderte Dateien mit 8 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -654,6 +654,8 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
int firstSpace = buffer.indexOf(' '); int firstSpace = buffer.indexOf(' ');
if (firstSpace < 0) return; if (firstSpace < 0) return;
String label = buffer.substring(0, firstSpace); String label = buffer.substring(0, firstSpace);
// Strip leading slash, if present.
label = label.startsWith("/") ? label.substring(1) : label;
final Optional<org.enginehub.piston.Command> command final Optional<org.enginehub.piston.Command> command
= WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().getCommand(label); = WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().getCommand(label);
if (!command.isPresent()) return; if (!command.isPresent()) return;

Datei anzeigen

@ -815,7 +815,10 @@ public final class PlatformCommandManager {
@Subscribe @Subscribe
public void handleCommandSuggestion(CommandSuggestionEvent event) { public void handleCommandSuggestion(CommandSuggestionEvent event) {
try { 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<Substring> split = parseArgs(arguments).collect(Collectors.toList()); List<Substring> split = parseArgs(arguments).collect(Collectors.toList());
List<String> argStrings = split.stream() List<String> argStrings = split.stream()
.map(Substring::getSubstring) .map(Substring::getSubstring)
@ -837,11 +840,10 @@ public final class PlatformCommandManager {
Substring original = suggestion.getReplacedArgument() == split.size() Substring original = suggestion.getReplacedArgument() == split.size()
? Substring.from(arguments, noSlashLength, noSlashLength) ? Substring.from(arguments, noSlashLength, noSlashLength)
: split.get(suggestion.getReplacedArgument()); : split.get(suggestion.getReplacedArgument());
// increase original points by 1, for removed `/` in `parseArgs`
return Substring.wrap( return Substring.wrap(
suggestion.getSuggestion(), suggestion.getSuggestion(),
original.getStart() + 1, original.getStart() + posOffset,
original.getEnd() + 1 original.getEnd() + posOffset
); );
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
} catch (ConditionFailedException e) { } catch (ConditionFailedException e) {