9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00

修复没有抛出未读完错误的问题

This commit is contained in:
jhqwqmc
2025-12-01 10:47:27 +08:00
parent 5d9ede392a
commit ac48881ae0
3 changed files with 27 additions and 17 deletions

View File

@@ -88,22 +88,22 @@ warning.config.type.vector3f: "<yellow>在文件 <arg:0> 发现问题 - 无法
warning.config.type.vec3d: "<yellow>在文件 <arg:0> 发现问题 - 无法加载 '<arg:1>': 无法将 '<arg:2>' 转换为双精度浮点数三维向量类型 (选项 '<arg:3>')</yellow>" warning.config.type.vec3d: "<yellow>在文件 <arg:0> 发现问题 - 无法加载 '<arg:1>': 无法将 '<arg:2>' 转换为双精度浮点数三维向量类型 (选项 '<arg:3>')</yellow>"
warning.config.type.map: "<yellow>在文件 <arg:0> 发现问题 - 无法加载 '<arg:1>': 无法将 '<arg:2>' 转换为映射类型 (选项 '<arg:3>')</yellow>" warning.config.type.map: "<yellow>在文件 <arg:0> 发现问题 - 无法加载 '<arg:1>': 无法将 '<arg:2>' 转换为映射类型 (选项 '<arg:3>')</yellow>"
warning.config.type.snbt.invalid_syntax: "<yellow>在文件 <arg:0> 发现问题 - 无法加载 '<arg:1>': 无效的 SNBT 语法 '<arg:2>'</yellow>" warning.config.type.snbt.invalid_syntax: "<yellow>在文件 <arg:0> 发现问题 - 无法加载 '<arg:1>': 无效的 SNBT 语法 '<arg:2>'</yellow>"
warning.config.type.snbt.invalid_syntax.parse_error: "<yellow><arg:0>, 位于第 <arg:1> 个字符: <arg:2></yellow>" warning.config.type.snbt.invalid_syntax.parse_error: "<yellow><arg:0>位于第<arg:1>个字符<arg:2></yellow>"
warning.config.type.snbt.invalid_syntax.here: "<yellow><--[此处]</yellow>" warning.config.type.snbt.invalid_syntax.here: "<yellow><--[此处]</yellow>"
warning.config.type.snbt.parser.expected_string_uuid: "<yellow>应为表示有效 UUID 的字符串</yellow>" warning.config.type.snbt.parser.expected_string_uuid: "<yellow>应为表示有效UUID的字符串</yellow>"
warning.config.type.snbt.parser.expected_number_or_boolean: "<yellow>应为数字或布尔型</yellow>" warning.config.type.snbt.parser.expected_number_or_boolean: "<yellow>应为数字或布尔型</yellow>"
warning.config.type.snbt.parser.trailing: "<yellow>多余的尾随数据</yellow>" warning.config.type.snbt.parser.trailing: "<yellow>多余的尾随数据</yellow>"
warning.config.type.snbt.parser.expected.compound: "<yellow>应为复合标签</yellow>" warning.config.type.snbt.parser.expected.compound: "<yellow>应为复合标签</yellow>"
warning.config.type.snbt.parser.number_parse_failure: "<yellow>解析数字失败: <arg:0></yellow>" warning.config.type.snbt.parser.number_parse_failure: "<yellow>解析数字失败<arg:0></yellow>"
warning.config.type.snbt.parser.expected_hex_escape: "<yellow>字符字面量长度应为 <arg:0></yellow>" warning.config.type.snbt.parser.expected_hex_escape: "<yellow>字符字面量长度应为<arg:0></yellow>"
warning.config.type.snbt.parser.invalid_codepoint: "<yellow>无效的 Unicode 字符码位: <arg:0></yellow>" warning.config.type.snbt.parser.invalid_codepoint: "<yellow>无效的Unicode字符码位<arg:0></yellow>"
warning.config.type.snbt.parser.no_such_operation: "<yellow>不存在的操作: <arg:0></yellow>" warning.config.type.snbt.parser.no_such_operation: "<yellow>不存在的操作: <arg:0></yellow>"
warning.config.type.snbt.parser.expected_integer_type: "<yellow>应为整数</yellow>" warning.config.type.snbt.parser.expected_integer_type: "<yellow>应为整数</yellow>"
warning.config.type.snbt.parser.expected_float_type: "<yellow>应为浮点数</yellow>" warning.config.type.snbt.parser.expected_float_type: "<yellow>应为浮点数</yellow>"
warning.config.type.snbt.parser.expected_non_negative_number: "<yellow>应为非负数</yellow>" warning.config.type.snbt.parser.expected_non_negative_number: "<yellow>应为非负数</yellow>"
warning.config.type.snbt.parser.invalid_character_name: "<yellow>无效的 Unicode 字符名称</yellow>" warning.config.type.snbt.parser.invalid_character_name: "<yellow>无效的Unicode字符名称</yellow>"
warning.config.type.snbt.parser.invalid_array_element_type: "<yellow>无效的数组元素类型</yellow>" warning.config.type.snbt.parser.invalid_array_element_type: "<yellow>无效的数组元素类型</yellow>"
warning.config.type.snbt.parser.invalid_unquoted_start: "<yellow>无引号字符串不能以数字 0-9、+ 或 - 开头</yellow>" warning.config.type.snbt.parser.invalid_unquoted_start: "<yellow>无引号字符串不能以数字0-9、+或-开头</yellow>"
warning.config.type.snbt.parser.expected_unquoted_string: "<yellow>应为有效的无引号字符串</yellow>" warning.config.type.snbt.parser.expected_unquoted_string: "<yellow>应为有效的无引号字符串</yellow>"
warning.config.type.snbt.parser.invalid_string_contents: "<yellow>无效的字符串内容</yellow>" warning.config.type.snbt.parser.invalid_string_contents: "<yellow>无效的字符串内容</yellow>"
warning.config.type.snbt.parser.expected_binary_numeral: "<yellow>应为二进制数</yellow>" warning.config.type.snbt.parser.expected_binary_numeral: "<yellow>应为二进制数</yellow>"
@@ -111,9 +111,9 @@ warning.config.type.snbt.parser.underscore_not_allowed: "<yellow>数字的开头
warning.config.type.snbt.parser.expected_decimal_numeral: "<yellow>应为十进制数</yellow>" warning.config.type.snbt.parser.expected_decimal_numeral: "<yellow>应为十进制数</yellow>"
warning.config.type.snbt.parser.expected_hex_numeral: "<yellow>应为十六进制数</yellow>" warning.config.type.snbt.parser.expected_hex_numeral: "<yellow>应为十六进制数</yellow>"
warning.config.type.snbt.parser.empty_key: "<yellow>键不能为空</yellow>" warning.config.type.snbt.parser.empty_key: "<yellow>键不能为空</yellow>"
warning.config.type.snbt.parser.leading_zero_not_allowed: "<yellow>十进制数不能以 0 开头</yellow>" warning.config.type.snbt.parser.leading_zero_not_allowed: "<yellow>十进制数不能以0开头</yellow>"
warning.config.type.snbt.parser.infinity_not_allowed: "<yellow>不允许使用非有限数的数值</yellow>" warning.config.type.snbt.parser.infinity_not_allowed: "<yellow>不允许使用非有限数的数值</yellow>"
warning.config.type.snbt.parser.incorrect: "<yellow>应为字面量 <arg:0></yellow>" warning.config.type.snbt.parser.incorrect: "<yellow>应为字面量<arg:0></yellow>"
warning.config.number.missing_type: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少数字类型所需的 'type' 参数</yellow>" warning.config.number.missing_type: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少数字类型所需的 'type' 参数</yellow>"
warning.config.number.invalid_type: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 使用了无效的数字类型 '<arg:2>'</yellow>" warning.config.number.invalid_type: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 使用了无效的数字类型 '<arg:2>'</yellow>"
warning.config.number.missing_argument: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少数字参数</yellow>" warning.config.number.missing_argument: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少数字参数</yellow>"

View File

@@ -46,7 +46,7 @@ public class ComponentsModifier<I> implements ItemDataModifier<I> {
} else if (string.startsWith("(snbt) ")) { } else if (string.startsWith("(snbt) ")) {
String snbt = string.substring("(snbt) ".length()); String snbt = string.substring("(snbt) ".length());
try { try {
return TagParser.parseCompoundFully(snbt); return TagParser.parseTagFully(snbt);
} catch (CommandSyntaxException e) { } catch (CommandSyntaxException e) {
throw new LocalizedResourceConfigException("warning.config.type.snbt.invalid_syntax", e.getMessage()); throw new LocalizedResourceConfigException("warning.config.type.snbt.invalid_syntax", e.getMessage());
} }

View File

@@ -15,6 +15,7 @@ import net.momirealms.sparrow.nbt.codec.LegacyJavaOps;
import net.momirealms.sparrow.nbt.codec.LegacyNBTOps; import net.momirealms.sparrow.nbt.codec.LegacyNBTOps;
import net.momirealms.sparrow.nbt.codec.NBTOps; import net.momirealms.sparrow.nbt.codec.NBTOps;
@SuppressWarnings("unused")
public class TagParser<T> { public class TagParser<T> {
public static final SimpleCommandExceptionType ERROR_TRAILING_DATA = new LocalizedSimpleCommandExceptionType( public static final SimpleCommandExceptionType ERROR_TRAILING_DATA = new LocalizedSimpleCommandExceptionType(
new LocalizedMessage("warning.config.type.snbt.parser.trailing") new LocalizedMessage("warning.config.type.snbt.parser.trailing")
@@ -24,8 +25,8 @@ public class TagParser<T> {
); );
public static final char ELEMENT_SEPARATOR = ','; public static final char ELEMENT_SEPARATOR = ',';
public static final char NAME_VALUE_SEPARATOR = ':'; public static final char NAME_VALUE_SEPARATOR = ':';
private static final TagParser<Tag> NBT_OPS_PARSER = create(VersionHelper.isOrAbove1_20_5() ? NBTOps.INSTANCE : LegacyNBTOps.INSTANCE); public static final TagParser<Tag> NBT_OPS_PARSER = create(VersionHelper.isOrAbove1_20_5() ? NBTOps.INSTANCE : LegacyNBTOps.INSTANCE);
private static final TagParser<Object> JAVA_OPS_PARSER = create(VersionHelper.isOrAbove1_20_5() ? JavaOps.INSTANCE : LegacyJavaOps.INSTANCE); public static final TagParser<Object> JAVA_OPS_PARSER = create(VersionHelper.isOrAbove1_20_5() ? JavaOps.INSTANCE : LegacyJavaOps.INSTANCE);
private final DynamicOps<T> ops; private final DynamicOps<T> ops;
private final Grammar<T> grammar; private final Grammar<T> grammar;
@@ -48,15 +49,20 @@ public class TagParser<T> {
} }
throw ERROR_EXPECTED_COMPOUND.createWithContext(reader); throw ERROR_EXPECTED_COMPOUND.createWithContext(reader);
} }
public static CompoundTag parseCompoundFully(String input) throws CommandSyntaxException { public static CompoundTag parseCompoundFully(String input) throws CommandSyntaxException {
StringReader reader = new StringReader(input); StringReader reader = new StringReader(input);
return parseCompoundAsArgument(reader); Tag result = NBT_OPS_PARSER.parseFully(reader);
return castToCompoundOrThrow(reader, result);
}
public static Tag parseTagFully(String input) throws CommandSyntaxException {
StringReader reader = new StringReader(input);
return NBT_OPS_PARSER.parseFully(reader);
} }
public static Object parseObjectFully(String input) throws CommandSyntaxException { public static Object parseObjectFully(String input) throws CommandSyntaxException {
StringReader reader = new StringReader(input); StringReader reader = new StringReader(input);
return parseObjectAsArgument(reader); return JAVA_OPS_PARSER.parseFully(reader);
} }
public T parseFully(String input) throws CommandSyntaxException { public T parseFully(String input) throws CommandSyntaxException {
@@ -77,8 +83,12 @@ public class TagParser<T> {
} }
public static CompoundTag parseCompoundAsArgument(StringReader reader) throws CommandSyntaxException { public static CompoundTag parseCompoundAsArgument(StringReader reader) throws CommandSyntaxException {
Tag tag = NBT_OPS_PARSER.parseAsArgument(reader); Tag result = parseTagAsArgument(reader);
return castToCompoundOrThrow(reader, tag); return castToCompoundOrThrow(reader, result);
}
public static Tag parseTagAsArgument(StringReader reader) throws CommandSyntaxException {
return NBT_OPS_PARSER.parseAsArgument(reader);
} }
public static Object parseObjectAsArgument(StringReader reader) throws CommandSyntaxException { public static Object parseObjectAsArgument(StringReader reader) throws CommandSyntaxException {