From 290f047f6ad3c9206fe9e4b3c8be2097e42552a5 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Tue, 23 Apr 2019 15:08:05 +1000 Subject: [PATCH] Fix tab complete error for single property states --- .../fawe/command/SuggestInputParseException.java | 9 +++++++++ .../worldedit/registry/state/BooleanProperty.java | 9 ++++++++- .../sk89q/worldedit/world/block/BlockState.java | 14 +++++--------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/SuggestInputParseException.java b/worldedit-core/src/main/java/com/boydti/fawe/command/SuggestInputParseException.java index 76e9243ff..595044844 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/SuggestInputParseException.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/command/SuggestInputParseException.java @@ -11,6 +11,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.function.Supplier; +import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkNotNull; @@ -52,6 +53,14 @@ public class SuggestInputParseException extends InputParseException { return null; } + public static SuggestInputParseException of(String input, List values) { + throw new SuggestInputParseException("No value: " + input, input, () -> + values.stream() + .map(v -> v.toString()) + .filter(v -> v.startsWith(input)) + .collect(Collectors.toList())); + } + @Override public synchronized Throwable getCause() { return cause.getCause(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/BooleanProperty.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/BooleanProperty.java index b445dbece..a707afa8e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/BooleanProperty.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/BooleanProperty.java @@ -48,7 +48,14 @@ public class BooleanProperty extends AbstractProperty { @Override public int getIndexFor(CharSequence string) throws IllegalArgumentException { - return string.charAt(0) == 't' ? defaultIndex : 1 - defaultIndex; + switch (string.charAt(0)) { + case 't': + return defaultIndex; + case 'f': + return 1 - defaultIndex; + default: + return -1; + } } @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index 9a72f35a5..71c6b7ad0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -145,8 +145,10 @@ public class BlockState implements BlockStateHolder, FawePattern { String name = property.getName(); charSequence.setSubstring(propStrStart + name.length() + 2, state.length() - 1); - - return type.withPropertyId(property.getIndexFor(charSequence)); + int index = charSequence.length() <= 0 ? -1 : property.getIndexFor(charSequence); + if (index != -1) { + return type.withPropertyId(index); + } } int stateId; if (defaultState != null) { @@ -167,13 +169,7 @@ public class BlockState implements BlockStateHolder, FawePattern { if (property != null) { int index = property.getIndexFor(charSequence); if (index == -1) { - String input = charSequence.toString(); - List values = property.getValues(); - throw new SuggestInputParseException("No value: " + input + " for " + type, input, () -> - values.stream() - .map(v -> v.toString()) - .filter(v -> v.startsWith(input)) - .collect(Collectors.toList())); + throw SuggestInputParseException.of(charSequence.toString(), property.getValues()); } stateId = property.modifyIndex(stateId, index); } else {