From 232ba7f95dbca60d0af8c52b7dab820f817e71cf Mon Sep 17 00:00:00 2001 From: 502647092 Date: Mon, 12 Sep 2016 19:33:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E9=87=8D=E8=BD=BD?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 2 +- .../java/pw/yumc/MiaoChat/config/ChatConfig.java | 15 ++++++++++----- .../java/pw/yumc/MiaoChat/config/ChatRule.java | 4 +++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 6d038b9..d99315f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 pw.yumc MiaoChat - 1.2 + 1.3 ${project.name} diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java b/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java index bfac3e0..3c3a5e1 100644 --- a/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java +++ b/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java @@ -4,7 +4,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedList; -import java.util.List; import java.util.Map; import org.bukkit.entity.Player; @@ -22,7 +21,7 @@ public class ChatConfig { private static final String F = "Formats"; private final Map formats; private final RuleComparator rulecomp; - private final List rules; + private final LinkedList rules; private final FileConfig config; private final FileConfig format; @@ -32,7 +31,7 @@ public class ChatConfig { rulecomp = new RuleComparator(); formats = new HashMap<>(); rules = new LinkedList<>(); - reload(); + load(); } /** @@ -55,21 +54,27 @@ public class ChatConfig { return formats.get(name); } - public void reload() { - format.reload(); + public void load() { formats.clear(); for (final String name : format.getKeys(false)) { formats.put(name, new ChatMessagePart(format.getConfigurationSection(name))); + Log.d("载入聊天格式: %s", name); } rules.clear(); if (config.isSet(F)) { for (final String rule : config.getConfigurationSection(F).getKeys(false)) { rules.add(new ChatRule(rule, config.getConfigurationSection(F + "." + rule))); + Log.d("载入聊天规则: %s => \"%s\"", rule, rules.getLast().getFormat()); } } Collections.sort(rules, rulecomp); } + public void reload() { + format.reload(); + load(); + } + private class RuleComparator implements Comparator { @Override public int compare(final ChatRule o1, final ChatRule o2) { diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java b/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java index 145e1bc..3b4dedc 100644 --- a/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java +++ b/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java @@ -93,7 +93,9 @@ public class ChatRule extends InjectConfigurationSection { if (!temp.isEmpty()) { for (final String var : temp) { final String[] args = tempvar.split("\\[" + var + "\\]", 2); - formats.add(args[0]); + if (!"".equals(args[0])) { + formats.add(args[0]); + } formats.add(var); tempvar = args[1]; }