From 9585f1162daf5921f94efc7a9d73fa156aa465e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Wed, 7 Feb 2018 23:05:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9AGlobalDataManager=20?= =?UTF-8?q?=E9=83=A8=E5=88=86=E8=AF=AD=E6=B3=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../taboolib/database/GlobalDataManager.java | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/src/me/skymc/taboolib/database/GlobalDataManager.java b/src/main/src/me/skymc/taboolib/database/GlobalDataManager.java index a3552e1..649a581 100644 --- a/src/main/src/me/skymc/taboolib/database/GlobalDataManager.java +++ b/src/main/src/me/skymc/taboolib/database/GlobalDataManager.java @@ -316,19 +316,34 @@ public class GlobalDataManager { @Override public void run() { - for (String name : variables.keySet()) { - // 获取数据 - HashMap value = Main.getConnection().getValueLast(Main.getTablePrefix() + "_plugindata", "name", name, "variable", "upgrade"); + /** + * 根据正序排列获取所有变量 + * 新的变量会覆盖旧的变量 + */ + LinkedList> list = Main.getConnection().getValues(Main.getTablePrefix() + "_plugindata", "id", -1, false, "name", "variable", "upgrade"); + // 循环变量 + for (HashMap value : list) { + Object name = value.get("name"); try { - // 检查更新服务器的名称是与本服不同 - if (!value.get("upgrade").toString().equals(variables.get(name).getUpgradeUID())) { - if (value.get("variable").toString().equals("null")) { - variables.remove(name); - } - else { - variables.get(name).setVariable(value.get("variable").toString()); + // 如果变量存在 + if (variables.containsKey(name)) { + // 如果变量不是由本服更新 + if (!value.get("upgrade").equals(variables.get(name).getUpgradeUID())) { + // 如果变量是空 + if (value.get("variable").equals("null")) { + // 删除变量 + variables.remove(name); + } + else { + // 更新变量 + variables.get(name).setVariable(value.get("variable").toString()); + } } } + // 如果变量存在则下载到本地 + else if (!value.get("variable").equals("null")) { + variables.put(value.get("name").toString(), new SQLVariable(value.get("name").toString(), value.get("variable").toString(), value.get("upgrade").toString())); + } } catch (Exception e) { // 移除