4
1
mirror of https://e.coding.net/circlecloud/MiaoChat.git synced 2024-12-22 19:18:47 +00:00

fix: 解析特殊字符错误问题

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2017-08-08 22:24:33 +08:00
parent d4f2c62d9b
commit 29a844dd7d
4 changed files with 49 additions and 6 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId>
<artifactId>MiaoChat</artifactId>
<version>1.8.5</version>
<version>1.8.6</version>
<build>
<finalName>${project.name}</finalName>
<resources>
@ -70,8 +70,9 @@
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
</ciManagement>
<properties>
<update.description>§a正式版本 §bv1.8.5</update.description>
<update.description>§a正式版本 §bv1.8.6</update.description>
<update.changes>
§617-08-08 §c修复: 解析特殊字符错误问题;
§617-07-25 §c修复: 类库版本错误;
§617-07-24 §c修复: 兼容 1.12 版本;
§617-05-21 §c修复: BungeeCord未分配分组时报错;

View File

@ -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";

View File

@ -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]);
}

View File

@ -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<String> formats = new ArrayList<>();
String format = "[mvp+][player]: ";
Matcher m = FORMAT_PATTERN.matcher(format);
LinkedList<String> 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);
}
}