From 4e9903b63a3c24ccce03f367f9a6d19a7a894265 Mon Sep 17 00:00:00 2001 From: Catnies Date: Wed, 25 Jun 2025 01:48:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20SNBTReader,=20=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A7=A3=E6=9E=90=E7=9A=84=E6=97=A0=E5=BC=95=E5=8F=B7?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=9C=AB=E5=B0=BE=E7=9A=84=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/momirealms/craftengine/core/util/SNBTReader.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/SNBTReader.java b/core/src/main/java/net/momirealms/craftengine/core/util/SNBTReader.java index d6a333645..c4904715b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/SNBTReader.java +++ b/core/src/main/java/net/momirealms/craftengine/core/util/SNBTReader.java @@ -170,12 +170,18 @@ public final class SNBTReader extends DefaultStringReader { private Object parsePrimitive() { // 先解析获取值的长度 int tokenStart = cursor; + int lastWhitespace = 0; // 记录值末尾的空格数量,{a:炒鸡 大保健} 和 {a: 炒鸡 大保健 } 都应解析成 "炒鸡 大保健". while (cursor < length) { char c = peek(); if (c == ',' || c == ']' || c == '}') break; cursor++; + if (c == ' ') { + lastWhitespace++; // 遇到空格先增加值, 代表值尾部空格数量. + continue; + } + lastWhitespace = 0; // 遇到正常字符时清空记录的尾部空格数. } - int tokenLength = cursor - tokenStart; + int tokenLength = cursor - tokenStart - lastWhitespace; // 计算值长度需要再减去尾部空格. if (tokenLength == 0) throw new IllegalArgumentException("Empty value at position " + tokenStart); String fullContent = string.substring(tokenStart, tokenStart + tokenLength);