mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-11-21 01:38:51 +00:00
feat: 修复远程配置无法获取的错误 添加远程配置缓存
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
486b77e413
commit
309530e610
@ -1,17 +1,18 @@
|
||||
package pw.yumc.YumCore.config.ext;
|
||||
|
||||
import pw.yumc.YumCore.bukkit.Log;
|
||||
import pw.yumc.YumCore.config.FileConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import pw.yumc.YumCore.bukkit.Log;
|
||||
import pw.yumc.YumCore.config.FileConfig;
|
||||
|
||||
public class YumConfig {
|
||||
protected static String REMOTEFILECENTER = "http://data.yumc.pw/config/";
|
||||
protected static String DataFolder = "plugins" + File.separatorChar + "YumCore";
|
||||
protected static String CacheFolder = DataFolder + File.separatorChar + "cache";
|
||||
|
||||
private static String fromYumc = "配置 %s 来自 YUMC 数据中心...";
|
||||
private static String createError = "从 YUMC 数据中心下载配置 %s 失败...";
|
||||
private static String createError = "从 YUMC 数据中心下载配置 %s 失败 使用缓存的配置...";
|
||||
|
||||
private YumConfig() {
|
||||
}
|
||||
@ -31,18 +32,21 @@ public class YumConfig {
|
||||
/**
|
||||
* 获得远程配置文件
|
||||
*
|
||||
* @param url
|
||||
* @param configname
|
||||
* 配置文件地址
|
||||
* @return {@link FileConfig}
|
||||
*/
|
||||
public static FileConfig getRemote(String url) {
|
||||
FileConfig config = null;
|
||||
public static FileConfig getRemote(String configname) {
|
||||
FileConfig config;
|
||||
try {
|
||||
config = new RemoteConfig(REMOTEFILECENTER + url);
|
||||
config = new RemoteConfig(REMOTEFILECENTER + configname);
|
||||
config.save(new File(CacheFolder, configname));
|
||||
Log.i(fromYumc, configname);
|
||||
} catch (IOException e) {
|
||||
Log.d(e);
|
||||
config = new FileConfig(new File(CacheFolder, configname));
|
||||
Log.i(createError, configname);
|
||||
}
|
||||
Log.info(String.format(config == null ? createError : fromYumc, url));
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
package pw.yumc.YumCore.global;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.SpawnEgg;
|
||||
|
||||
import pw.yumc.YumCore.bukkit.Log;
|
||||
import pw.yumc.YumCore.config.FileConfig;
|
||||
import pw.yumc.YumCore.config.ext.YumConfig;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 本地化工具类
|
||||
*
|
||||
@ -120,11 +121,11 @@ public class L10N {
|
||||
public void run() {
|
||||
try {
|
||||
Map<String, String> local = YumConfig.getLocal(CONFIG_NAME).getContentMap();
|
||||
Map<String, String> remote = YumConfig.getRemote(CONFIG_NAME).getContentMap();
|
||||
if (local != null) {
|
||||
Log.info("本地汉化文件词条数量: " + local.size());
|
||||
content.putAll(local);
|
||||
}
|
||||
Map<String, String> remote = YumConfig.getRemote(CONFIG_NAME).getContentMap();
|
||||
if (remote != null) {
|
||||
Log.info("远程汉化文件词条数量: " + remote.size());
|
||||
content.putAll(remote);
|
||||
|
Loading…
Reference in New Issue
Block a user