geforkt von Mirrors/FastAsyncWorldEdit
feat: allow captions in SuggestInputParseException (#2239)
- Deprecate for removal methods using string message - Fixes #2026
Dieser Commit ist enthalten in:
Ursprung
74aff920a8
Commit
7c01c1e95e
@ -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<List<String>> getSuggestions;
|
||||
private String prefix;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link SuggestInputParseException#SuggestInputParseException(Component, Supplier)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "TODO")
|
||||
public SuggestInputParseException(String msg, String prefix, Supplier<List<String>> 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<List<String>> 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<List<String>> 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<List<String>> 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<List<String>> getSuggestions) {
|
||||
this(new InputParseException(message), getSuggestions);
|
||||
}
|
||||
|
||||
public static SuggestInputParseException of(Throwable other, Supplier<List<String>> 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<List<String>> getSuggestions) {
|
||||
if (other instanceof SuggestInputParseException) {
|
||||
return (SuggestInputParseException) other;
|
||||
}
|
||||
return new SuggestInputParseException(other, getSuggestions);
|
||||
}
|
||||
|
||||
public SuggestInputParseException(InputParseException other, Supplier<List<String>> 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<Object> 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;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ public class RichMaskParser extends FaweParser<Mask> {
|
||||
@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<Mask> {
|
||||
"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<Mask> {
|
||||
"https://intellectualsites.github.io/fastasyncworldedit-documentation/masks/masks"
|
||||
))
|
||||
)),
|
||||
full,
|
||||
() -> {
|
||||
if (full.length() == 1) {
|
||||
return new ArrayList<>(worldEdit.getMaskFactory().getSuggestions(""));
|
||||
|
@ -47,8 +47,7 @@ public class RichPatternParser extends FaweParser<Pattern> {
|
||||
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<Pattern> {
|
||||
"https://intellectualsites.github.io/fastasyncworldedit-documentation/patterns/patterns"
|
||||
))
|
||||
)),
|
||||
full,
|
||||
() -> {
|
||||
if (full.length() == 1) {
|
||||
return new ArrayList<>(worldEdit.getPatternFactory().getSuggestions(""));
|
||||
|
@ -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<BlockType> 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<String> values = new HashSet<>();
|
||||
types.stream().filter(t -> t.hasProperty(fKey)).forEach(t -> {
|
||||
Property<Object> p = t.getProperty(fKey);
|
||||
@ -287,7 +286,7 @@ public class BlockMaskBuilder {
|
||||
}
|
||||
|
||||
private void suggest(String input, String property, Collection<BlockType> 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<PropertyKey> keys = PropertyKeySet.empty();
|
||||
finalTypes.forEach(t -> t.getProperties().forEach(p -> keys.add(p.getKey())));
|
||||
return keys.stream().map(PropertyKey::getName)
|
||||
|
@ -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<BlockState>, 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<BlockState>, 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<BlockState>, Pattern {
|
||||
);
|
||||
} else {
|
||||
throw new SuggestInputParseException(
|
||||
"No operator for " + state,
|
||||
"",
|
||||
Caption.of("fawe.error.no-operator-for-input", state),
|
||||
() -> Collections.singletonList("=")
|
||||
);
|
||||
}
|
||||
|
@ -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)
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren