This commit is contained in:
YuTian 2024-07-20 00:14:56 +08:00
parent a2997f7a41
commit 73db9af465
3 changed files with 45 additions and 1 deletions

View File

@ -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();
}

View File

@ -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<String, String> 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();
}
}
}

View File

@ -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",