Fix suggestions on Bukkit for good

This commit is contained in:
Kenzie Togami
2019-07-27 23:31:38 -07:00
parent 3a5170a0e8
commit 76b608f90b
2 changed files with 14 additions and 4 deletions

View File

@ -21,7 +21,6 @@ package com.sk89q.worldedit.internal.command;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.internal.util.Substring;
import com.sk89q.worldedit.util.formatting.text.Component;
@ -70,18 +69,29 @@ public class CommandUtil {
CommandArgParser.spaceSplit(arguments)
);
return suggestions.stream()
// Re-map suggestions to only operate on the last non-quoted word
.map(CommandUtil::onlyOnLastQuotedWord)
.map(suggestion -> CommandUtil.suggestLast(lastArg, suggestion))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(toList());
}
private static Substring onlyOnLastQuotedWord(Substring suggestion) {
String substr = suggestion.getSubstring();
int sp = substr.lastIndexOf(' ');
if (sp < 0) {
return suggestion;
}
return Substring.wrap(substr.substring(sp + 1), suggestion.getStart() + sp + 1, suggestion.getEnd());
}
/**
* Given the last word of a command, mutate the suggestion to replace the last word, if
* possible.
*/
private static Optional<String> suggestLast(Substring last, Substring suggestion) {
if (suggestion.getStart() == last.getEnd()) {
if (suggestion.getStart() == last.getEnd() && !last.getSubstring().equals("\"")) {
// this suggestion is for the next argument.
if (last.getSubstring().isEmpty()) {
return Optional.of(suggestion.getSubstring());