mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
修复没有抛出未读完错误的问题
This commit is contained in:
@@ -88,15 +88,15 @@ warning.config.type.vector3f: "<yellow>在文件 <arg:0> 发现问题 - 无法
|
||||
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.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.parser.expected_string_uuid: "<yellow>应为表示有效UUID的字符串</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.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.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.expected_integer_type: "<yellow>应为整数</yellow>"
|
||||
warning.config.type.snbt.parser.expected_float_type: "<yellow>应为浮点数</yellow>"
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ComponentsModifier<I> implements ItemDataModifier<I> {
|
||||
} else if (string.startsWith("(snbt) ")) {
|
||||
String snbt = string.substring("(snbt) ".length());
|
||||
try {
|
||||
return TagParser.parseCompoundFully(snbt);
|
||||
return TagParser.parseTagFully(snbt);
|
||||
} catch (CommandSyntaxException e) {
|
||||
throw new LocalizedResourceConfigException("warning.config.type.snbt.invalid_syntax", e.getMessage());
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.momirealms.sparrow.nbt.codec.LegacyJavaOps;
|
||||
import net.momirealms.sparrow.nbt.codec.LegacyNBTOps;
|
||||
import net.momirealms.sparrow.nbt.codec.NBTOps;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TagParser<T> {
|
||||
public static final SimpleCommandExceptionType ERROR_TRAILING_DATA = new LocalizedSimpleCommandExceptionType(
|
||||
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 NAME_VALUE_SEPARATOR = ':';
|
||||
private 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<Tag> NBT_OPS_PARSER = create(VersionHelper.isOrAbove1_20_5() ? NBTOps.INSTANCE : LegacyNBTOps.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 Grammar<T> grammar;
|
||||
|
||||
@@ -48,15 +49,20 @@ public class TagParser<T> {
|
||||
}
|
||||
throw ERROR_EXPECTED_COMPOUND.createWithContext(reader);
|
||||
}
|
||||
|
||||
public static CompoundTag parseCompoundFully(String input) throws CommandSyntaxException {
|
||||
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 {
|
||||
StringReader reader = new StringReader(input);
|
||||
return parseObjectAsArgument(reader);
|
||||
return JAVA_OPS_PARSER.parseFully(reader);
|
||||
}
|
||||
|
||||
public T parseFully(String input) throws CommandSyntaxException {
|
||||
@@ -77,8 +83,12 @@ public class TagParser<T> {
|
||||
}
|
||||
|
||||
public static CompoundTag parseCompoundAsArgument(StringReader reader) throws CommandSyntaxException {
|
||||
Tag tag = NBT_OPS_PARSER.parseAsArgument(reader);
|
||||
return castToCompoundOrThrow(reader, tag);
|
||||
Tag result = parseTagAsArgument(reader);
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user