From 309530e610df3b9ffdfa67741f4eb7cc7c703f72 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Thu, 22 Dec 2016 19:52:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E8=BF=9C=E7=A8=8B?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF=20=E6=B7=BB=E5=8A=A0=E8=BF=9C=E7=A8=8B?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../pw/yumc/YumCore/config/ext/YumConfig.java | 22 +++++++++++-------- .../java/pw/yumc/YumCore/global/L10N.java | 9 ++++---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/pw/yumc/YumCore/config/ext/YumConfig.java b/src/main/java/pw/yumc/YumCore/config/ext/YumConfig.java index c84c8cf..492da22 100644 --- a/src/main/java/pw/yumc/YumCore/config/ext/YumConfig.java +++ b/src/main/java/pw/yumc/YumCore/config/ext/YumConfig.java @@ -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; } } diff --git a/src/main/java/pw/yumc/YumCore/global/L10N.java b/src/main/java/pw/yumc/YumCore/global/L10N.java index 0d2ecf1..b7eb806 100644 --- a/src/main/java/pw/yumc/YumCore/global/L10N.java +++ b/src/main/java/pw/yumc/YumCore/global/L10N.java @@ -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 local = YumConfig.getLocal(CONFIG_NAME).getContentMap(); - Map remote = YumConfig.getRemote(CONFIG_NAME).getContentMap(); if (local != null) { Log.info("本地汉化文件词条数量: " + local.size()); content.putAll(local); } + Map remote = YumConfig.getRemote(CONFIG_NAME).getContentMap(); if (remote != null) { Log.info("远程汉化文件词条数量: " + remote.size()); content.putAll(remote);