From 29a844dd7d6c745c6c509c43b85c2cd16d21d7a4 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Tue, 8 Aug 2017 22:24:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E6=9E=90=E7=89=B9=E6=AE=8A?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 5 ++- .../pw/yumc/MiaoChat/config/ChatConfig.java | 3 +- .../pw/yumc/MiaoChat/config/ChatRule.java | 4 +- .../pw/yumc/MiaoChat/config/ChatRuleTest.java | 43 +++++++++++++++++++ 4 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 src/test/pw/yumc/MiaoChat/config/ChatRuleTest.java diff --git a/pom.xml b/pom.xml index d22b61f..4dd7b1f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 pw.yumc MiaoChat - 1.8.5 + 1.8.6 ${project.name} @@ -70,8 +70,9 @@ http://ci.yumc.pw/job/${project.artifactId}/ - §a正式版本 §bv1.8.5 + §a正式版本 §bv1.8.6 + §617-08-08 §c修复: 解析特殊字符错误问题; §617-07-25 §c修复: 类库版本错误; §617-07-24 §c修复: 兼容 1.12 版本; §617-05-21 §c修复: BungeeCord未分配分组时报错; diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java b/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java index 7a945f3..3cf5944 100644 --- a/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java +++ b/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java @@ -12,9 +12,8 @@ import pw.yumc.YumCore.bukkit.P; import pw.yumc.YumCore.config.FileConfig; /** - * - * @since 2016年9月9日 下午4:40:50 * @author 喵♂呜 + * @since 2016年9月9日 下午4:40:50 */ public class ChatConfig { private static String F = "Formats"; diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java b/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java index c18a420..eb5170e 100644 --- a/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java +++ b/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java @@ -18,8 +18,8 @@ import pw.yumc.YumCore.tellraw.Tellraw; /** * 聊天规则 * - * @since 2016年9月9日 下午4:59:47 * @author 喵♂呜 + * @since 2016年9月9日 下午4:59:47 */ public class ChatRule extends InjectConfigurationSection { private transient static MiaoChat plugin = P.getPlugin(); @@ -117,7 +117,7 @@ public class ChatRule extends InjectConfigurationSection { } String tempvar = format; for (String var : temp) { - String[] args = tempvar.split("\\[" + var + "]", 2); + String[] args = tempvar.split(Pattern.quote("[" + var + "]"), 2); if (!"".equals(args[0])) { formats.add(args[0]); } diff --git a/src/test/pw/yumc/MiaoChat/config/ChatRuleTest.java b/src/test/pw/yumc/MiaoChat/config/ChatRuleTest.java new file mode 100644 index 0000000..b8526a3 --- /dev/null +++ b/src/test/pw/yumc/MiaoChat/config/ChatRuleTest.java @@ -0,0 +1,43 @@ +package pw.yumc.MiaoChat.config; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.junit.Test; + +/** + * Created with IntelliJ IDEA + * + * @author 喵♂呜 + * Created on 2017/8/8 16:23. + */ +public class ChatRuleTest { + private transient static Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[]]"); + + @Test + public void testSplit() { + List formats = new ArrayList<>(); + String format = "[mvp+][player]: "; + Matcher m = FORMAT_PATTERN.matcher(format); + LinkedList temp = new LinkedList<>(); + while (m.find()) { + temp.add(m.group(1)); + } + String tempvar = format; + for (String var : temp) { + String[] args = tempvar.split(Pattern.quote("[" + var + "]"), 2); + if (!"".equals(args[0])) { + formats.add(args[0]); + } + formats.add(var); + tempvar = args.length == 2 ? args[1] : ""; + } + if (!tempvar.isEmpty()) { + formats.add(tempvar); + } + formats.forEach(System.out::println); + } +} \ No newline at end of file