diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/SuggestInputParseException.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/SuggestInputParseException.java index c38b38888..bd10e6d20 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/SuggestInputParseException.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/SuggestInputParseException.java @@ -1,6 +1,8 @@ package com.fastasyncworldedit.core.command; +import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.extension.input.InputParseException; +import com.sk89q.worldedit.util.formatting.text.Component; import java.lang.reflect.InvocationTargetException; import java.util.List; @@ -13,33 +15,81 @@ public class SuggestInputParseException extends InputParseException { private final InputParseException cause; private final Supplier> getSuggestions; - private String prefix; + /** + * @deprecated Use {@link SuggestInputParseException#SuggestInputParseException(Component, Supplier)} + */ + @Deprecated(forRemoval = true, since = "TODO") public SuggestInputParseException(String msg, String prefix, Supplier> getSuggestions) { - this(new InputParseException(msg), prefix, getSuggestions); + this(new InputParseException(msg), getSuggestions); } + /** + * @deprecated Use {@link SuggestInputParseException#of(Throwable, Supplier)} + */ + @Deprecated(forRemoval = true, since = "TODO") public static SuggestInputParseException of(Throwable other, String prefix, Supplier> getSuggestions) { if (other instanceof InputParseException) { - return of((InputParseException) other, prefix, getSuggestions); + return of((InputParseException) other, getSuggestions); } - return of(new InputParseException(other.getMessage()), prefix, getSuggestions); + return of(new InputParseException(other.getMessage()), getSuggestions); } + /** + * @deprecated Use {@link SuggestInputParseException#of(InputParseException, Supplier)} + */ + @Deprecated(forRemoval = true, since = "TODO") public static SuggestInputParseException of(InputParseException other, String prefix, Supplier> getSuggestions) { if (other instanceof SuggestInputParseException) { return (SuggestInputParseException) other; } - return new SuggestInputParseException(other, prefix, getSuggestions); + return new SuggestInputParseException(other, getSuggestions); } + /** + * @deprecated Use {@link SuggestInputParseException#SuggestInputParseException(InputParseException, Supplier)} + */ + @Deprecated(forRemoval = true, since = "TODO") public SuggestInputParseException(InputParseException other, String prefix, Supplier> getSuggestions) { - super(other.getMessage()); + super(other.getRichMessage()); + checkNotNull(getSuggestions); + checkNotNull(other); + this.cause = other; + this.getSuggestions = getSuggestions; + } + + /** + * Create a new SuggestInputParseException instance + * + * @param message Message to send + * @param getSuggestions Supplier of list of sugegstions to give to user + * @since TODO + */ + public SuggestInputParseException(Component message, Supplier> getSuggestions) { + this(new InputParseException(message), getSuggestions); + } + + public static SuggestInputParseException of(Throwable other, Supplier> getSuggestions) { + if (other instanceof InputParseException) { + return of((InputParseException) other, getSuggestions); + } + //noinspection deprecation + return of(new InputParseException(other.getMessage()), getSuggestions); + } + + public static SuggestInputParseException of(InputParseException other, Supplier> getSuggestions) { + if (other instanceof SuggestInputParseException) { + return (SuggestInputParseException) other; + } + return new SuggestInputParseException(other, getSuggestions); + } + + public SuggestInputParseException(InputParseException other, Supplier> getSuggestions) { + super(other.getRichMessage()); checkNotNull(getSuggestions); checkNotNull(other); this.cause = other; this.getSuggestions = getSuggestions; - this.prefix = prefix; } public static SuggestInputParseException get(InvocationTargetException e) { @@ -54,7 +104,7 @@ public class SuggestInputParseException extends InputParseException { } public static SuggestInputParseException of(String input, List values) { - throw new SuggestInputParseException("No value: " + input, input, () -> + throw new SuggestInputParseException(Caption.of("fawe.error.no-value-for-input", input), () -> values.stream() .map(Object::toString) .filter(v -> v.startsWith(input)) @@ -76,8 +126,12 @@ public class SuggestInputParseException extends InputParseException { return getSuggestions.get(); } + /** + * @deprecated Unused + */ + @Deprecated(forRemoval = true, since = "TODO") public SuggestInputParseException prepend(String input) { - this.prefix = input + prefix; + // Do nothing return this; } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/RichMaskParser.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/RichMaskParser.java index 31c8f3d3e..f86645b67 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/RichMaskParser.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/RichMaskParser.java @@ -50,7 +50,7 @@ public class RichMaskParser extends FaweParser { @Override public Mask parseFromInput(String input, ParserContext context) throws InputParseException { if (input.isEmpty()) { - throw new SuggestInputParseException("No input provided", "", () -> Stream + throw new SuggestInputParseException(Caption.of("fawe.error.no-input-provided"), () -> Stream .of("#", ",", "&") .map(n -> n + ":") .collect(Collectors.toList()) @@ -95,7 +95,6 @@ public class RichMaskParser extends FaweParser { "https://intellectualsites.github.io/fastasyncworldedit-documentation/patterns/patterns" )) )), - full, () -> { if (full.length() == 1) { return new ArrayList<>(worldEdit.getMaskFactory().getSuggestions("")); @@ -162,7 +161,6 @@ public class RichMaskParser extends FaweParser { "https://intellectualsites.github.io/fastasyncworldedit-documentation/masks/masks" )) )), - full, () -> { if (full.length() == 1) { return new ArrayList<>(worldEdit.getMaskFactory().getSuggestions("")); diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/pattern/RichPatternParser.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/pattern/RichPatternParser.java index 4971ee878..3ebd84fa6 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/pattern/RichPatternParser.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/pattern/RichPatternParser.java @@ -47,8 +47,7 @@ public class RichPatternParser extends FaweParser { public Pattern parseFromInput(String input, ParserContext context) throws InputParseException { if (input.isEmpty()) { throw new SuggestInputParseException( - "No input provided", - "", + Caption.of("fawe.error.no-input-provided"), () -> Stream .concat(Stream.of("#", ",", "&"), BlockTypes.getNameSpaces().stream().map(n -> n + ":")) .collect(Collectors.toList()) @@ -88,7 +87,6 @@ public class RichPatternParser extends FaweParser { "https://intellectualsites.github.io/fastasyncworldedit-documentation/patterns/patterns" )) )), - full, () -> { if (full.length() == 1) { return new ArrayList<>(worldEdit.getPatternFactory().getSuggestions("")); diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/BlockMaskBuilder.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/BlockMaskBuilder.java index 0b89e0ada..5bfeb766c 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/BlockMaskBuilder.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/BlockMaskBuilder.java @@ -178,8 +178,7 @@ public class BlockMaskBuilder { } if (operator == null) { throw new SuggestInputParseException( - "No operator for " + input, - "", + Caption.of("fawe.error.no-operator-for-input", input), () -> Arrays.asList("=", "~", "!", "<", ">", "<=", ">=") ); } @@ -195,7 +194,7 @@ public class BlockMaskBuilder { String value = charSequence.toString(); final PropertyKey fKey = key; Collection types = type != null ? Collections.singleton(type) : blockTypeList; - throw new SuggestInputParseException("No value for " + input, input, () -> { + throw new SuggestInputParseException(Caption.of("fawe.error.no-value-for-input", input), () -> { HashSet values = new HashSet<>(); types.stream().filter(t -> t.hasProperty(fKey)).forEach(t -> { Property p = t.getProperty(fKey); @@ -287,7 +286,7 @@ public class BlockMaskBuilder { } private void suggest(String input, String property, Collection finalTypes) throws InputParseException { - throw new SuggestInputParseException(input + " does not have: " + property, input, () -> { + throw new SuggestInputParseException(Caption.of("worldedit.error.parser.unknown-property", property, input), () -> { Set keys = PropertyKeySet.empty(); finalTypes.forEach(t -> t.getProperties().forEach(p -> keys.add(p.getKey()))); return keys.stream().map(PropertyKey::getName) 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 87959ebe6..f08675fc5 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 @@ -20,6 +20,7 @@ package com.sk89q.worldedit.world.block; import com.fastasyncworldedit.core.command.SuggestInputParseException; +import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.function.mask.SingleBlockStateMask; import com.fastasyncworldedit.core.queue.ITileInput; import com.fastasyncworldedit.core.registry.state.PropertyKey; @@ -43,6 +44,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.AbstractProperty; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.concurrency.LazyReference; +import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.nbt.CompoundBinaryTag; import com.sk89q.worldedit.world.registry.BlockMaterial; @@ -150,7 +152,7 @@ public class BlockState implements BlockStateHolder, Pattern { type = BlockTypes.get(key); if (type == null) { String input = key.toString(); - throw new SuggestInputParseException("Does not match a valid block type: " + input, input, () -> Stream.of( + throw new SuggestInputParseException(Caption.of("fawe.error.invalid-block-type", TextComponent.of(input)), () -> Stream.of( BlockTypesCache.values) .map(BlockType::getId) .filter(id -> StringMan.blockStateMatches(input, id)) @@ -211,8 +213,7 @@ public class BlockState implements BlockStateHolder, Pattern { String input = charSequence.toString(); BlockType finalType = type; throw new SuggestInputParseException( - "Invalid property " + key + ":" + input + " for type " + type, - input, + Caption.of("worldedit.error.parser.unknown-property", key + ":" + input, type), () -> finalType.getProperties().stream() .map(Property::getName) @@ -222,8 +223,7 @@ public class BlockState implements BlockStateHolder, Pattern { ); } else { throw new SuggestInputParseException( - "No operator for " + state, - "", + Caption.of("fawe.error.no-operator-for-input", state), () -> Collections.singletonList("=") ); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java index e79a9af5a..b8af4bce5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java @@ -20,9 +20,11 @@ package com.sk89q.worldedit.world.block; import com.fastasyncworldedit.core.command.SuggestInputParseException; +import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.util.StringMan; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.world.registry.LegacyMapper; import javax.annotation.Nullable; @@ -1967,7 +1969,7 @@ public final class BlockTypes { } } - throw new SuggestInputParseException("Does not match a valid block type: " + inputLower, inputLower, () -> Stream.of( + throw new SuggestInputParseException(Caption.of("fawe.error.invalid-block-type", TextComponent.of(input)), () -> Stream.of( BlockTypesCache.values) .filter(b -> StringMan.blockStateMatches(inputLower, b.getId())) .map(BlockType::getId)