chore: add a more informative error when parsing block properties (#2524)

This commit is contained in:
Jordan 2023-12-18 14:58:53 +00:00 committed by GitHub
parent 17abaeb19e
commit f44b1b48c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -178,9 +178,18 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
String name = property.getName(); String name = property.getName();
charSequence.setSubstring(propStrStart + name.length() + 2, state.length() - 1); charSequence.setSubstring(propStrStart + name.length() + 2, state.length() - 1);
int index = charSequence.length() <= 0 ? -1 : property.getIndexFor(charSequence); try {
if (index != -1) { int index = charSequence.length() <= 0 ? -1 : property.getIndexFor(charSequence);
return type.withPropertyId(index); if (index != -1) {
return type.withPropertyId(index);
}
} catch (Exception e) {
throw new InputParseException(Caption.of(
"fawe.error.invalid-block-state-property",
TextComponent.of(charSequence.toString()),
TextComponent.of(name),
TextComponent.of(state)
), e);
} }
} }
int stateId; int stateId;
@ -200,7 +209,17 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
case ',': { case ',': {
charSequence.setSubstring(last, i); charSequence.setSubstring(last, i);
if (property != null) { if (property != null) {
int index = property.getIndexFor(charSequence); int index;
try {
index = property.getIndexFor(charSequence);
} catch (Exception e) {
throw new InputParseException(Caption.of(
"fawe.error.invalid-block-state-property",
TextComponent.of(charSequence.toString()),
TextComponent.of(property.getName()),
TextComponent.of(state)
), e);
}
if (index == -1) { if (index == -1) {
throw SuggestInputParseException.of(charSequence.toString(), (List<Object>) property.getValues()); throw SuggestInputParseException.of(charSequence.toString(), (List<Object>) property.getValues());
} }

View File

@ -92,6 +92,7 @@
"fawe.error.parser.invalid-data": "Invalid data: {0}", "fawe.error.parser.invalid-data": "Invalid data: {0}",
"fawe.error.unsupported": "Unsupported!", "fawe.error.unsupported": "Unsupported!",
"fawe.error.invalid-block-type": "Does not match a valid block type: {0}", "fawe.error.invalid-block-type": "Does not match a valid block type: {0}",
"fawe.error.invalid-block-state-property": "Cannot parse value `{0}` for property `{1}`, block state: `{2}`",
"fawe.error.nbt.forbidden": "You are not allowed to use nbt. Lacking permission: {0}", "fawe.error.nbt.forbidden": "You are not allowed to use nbt. Lacking permission: {0}",
"fawe.error.invalid-arguments": "Invalid amount of arguments. Expected: {0}", "fawe.error.invalid-arguments": "Invalid amount of arguments. Expected: {0}",
"fawe.error.unrecognised-tag": "Unrecognised tag: {0} {1}", "fawe.error.unrecognised-tag": "Unrecognised tag: {0} {1}",