diff --git a/src/main/java/com/io/yutian/aulib/AuLib.java b/src/main/java/com/io/yutian/aulib/AuLib.java index 226b684..e9709a8 100644 --- a/src/main/java/com/io/yutian/aulib/AuLib.java +++ b/src/main/java/com/io/yutian/aulib/AuLib.java @@ -2,6 +2,7 @@ package com.io.yutian.aulib; import com.io.yutian.aulib.lang.Lang; import com.io.yutian.aulib.listener.GuiHandlerListener; +import com.io.yutian.aulib.util.LangUtil; import org.bukkit.plugin.java.JavaPlugin; public class AuLib extends JavaPlugin { @@ -17,6 +18,8 @@ public class AuLib extends JavaPlugin { Lang.registerLangFile(this); Lang.reload(this); + LangUtil.init(); + } diff --git a/src/main/java/com/io/yutian/aulib/util/LangUtil.java b/src/main/java/com/io/yutian/aulib/util/LangUtil.java new file mode 100644 index 0000000..c7a9c15 --- /dev/null +++ b/src/main/java/com/io/yutian/aulib/util/LangUtil.java @@ -0,0 +1,41 @@ +package com.io.yutian.aulib.util; + +import com.io.yutian.aulib.AuLib; +import com.io.yutian.aulib.expiringmap.ExpirationPolicy; +import com.io.yutian.aulib.expiringmap.ExpiringMap; +import org.json.JSONObject; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.concurrent.TimeUnit; + +public class LangUtil { + + private static ExpiringMap expiringMap = ExpiringMap.builder().expiration(3, TimeUnit.MINUTES).expirationPolicy(ExpirationPolicy.CREATED).build(); + private static JSONObject jsonObject = new JSONObject(); + + public static String getLang(String key) { + if (expiringMap.containsKey(key)) { + return expiringMap.get(key); + } + String value = jsonObject.getString(key); + expiringMap.put(key, value); + return value; + } + + public static void init() { + File file = FileUtil.getFile(AuLib.inst(), "", "zh_cn.json"); + if (!file.exists()) { + AuLib.inst().saveResource("zh_cn.json", false); + } + try { + String s = new String(Files.readAllBytes(Paths.get(file.toURI()))); + jsonObject = new JSONObject(s); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/resources/zh_cn.json b/src/main/resources/zh_cn.json index dfe6444..2baaad1 100644 --- a/src/main/resources/zh_cn.json +++ b/src/main/resources/zh_cn.json @@ -4169,7 +4169,7 @@ "parsing.int.invalid": "无效的整型数据“%s”", "parsing.long.expected": "需要长整型", "parsing.long.invalid": "无效的长整型数据“%s”", - "parsing.quote.escape": "双引号内的字符串包含无效的转义序列“\\%s”", + "parsing.quote.escape": "双引号内的字符串包含无效的转义序列“%s”", "parsing.quote.expected.end": "字符串的双引号不成对", "parsing.quote.expected.start": "字符串的开头需要双引号", "particle.notFound": "未知的粒子:%s",