1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-22 01:48:50 +00:00

feat: 修复远程配置无法获取的错误 添加远程配置缓存

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-12-22 19:52:51 +08:00
parent 486b77e413
commit 309530e610
2 changed files with 18 additions and 13 deletions

View File

@ -1,17 +1,18 @@
package pw.yumc.YumCore.config.ext; 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.File;
import java.io.IOException; import java.io.IOException;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.config.FileConfig;
public class YumConfig { public class YumConfig {
protected static String REMOTEFILECENTER = "http://data.yumc.pw/config/"; protected static String REMOTEFILECENTER = "http://data.yumc.pw/config/";
protected static String DataFolder = "plugins" + File.separatorChar + "YumCore"; 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 fromYumc = "配置 %s 来自 YUMC 数据中心...";
private static String createError = "从 YUMC 数据中心下载配置 %s 失败..."; private static String createError = "从 YUMC 数据中心下载配置 %s 失败 使用缓存的配置...";
private YumConfig() { private YumConfig() {
} }
@ -31,18 +32,21 @@ public class YumConfig {
/** /**
* 获得远程配置文件 * 获得远程配置文件
* *
* @param url * @param configname
* 配置文件地址 * 配置文件地址
* @return {@link FileConfig} * @return {@link FileConfig}
*/ */
public static FileConfig getRemote(String url) { public static FileConfig getRemote(String configname) {
FileConfig config = null; FileConfig config;
try { try {
config = new RemoteConfig(REMOTEFILECENTER + url); config = new RemoteConfig(REMOTEFILECENTER + configname);
config.save(new File(CacheFolder, configname));
Log.i(fromYumc, configname);
} catch (IOException e) { } catch (IOException e) {
Log.d(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; return config;
} }
} }

View File

@ -1,15 +1,16 @@
package pw.yumc.YumCore.global; package pw.yumc.YumCore.global;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.SpawnEgg; import org.bukkit.material.SpawnEgg;
import pw.yumc.YumCore.bukkit.Log; import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.config.FileConfig; import pw.yumc.YumCore.config.FileConfig;
import pw.yumc.YumCore.config.ext.YumConfig; 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() { public void run() {
try { try {
Map<String, String> local = YumConfig.getLocal(CONFIG_NAME).getContentMap(); Map<String, String> local = YumConfig.getLocal(CONFIG_NAME).getContentMap();
Map<String, String> remote = YumConfig.getRemote(CONFIG_NAME).getContentMap();
if (local != null) { if (local != null) {
Log.info("本地汉化文件词条数量: " + local.size()); Log.info("本地汉化文件词条数量: " + local.size());
content.putAll(local); content.putAll(local);
} }
Map<String, String> remote = YumConfig.getRemote(CONFIG_NAME).getContentMap();
if (remote != null) { if (remote != null) {
Log.info("远程汉化文件词条数量: " + remote.size()); Log.info("远程汉化文件词条数量: " + remote.size());
content.putAll(remote); content.putAll(remote);