From 048eb12dafa676e1bafbc62ea1745827c720ff8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Sat, 12 Oct 2019 22:35:01 +0800 Subject: [PATCH] + fix lag & update TMap --- src/main/scala/io/izzel/taboolib/TabooLib.java | 5 +++++ src/main/scala/io/izzel/taboolib/util/TMap.java | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/scala/io/izzel/taboolib/TabooLib.java b/src/main/scala/io/izzel/taboolib/TabooLib.java index 1357223..9361651 100644 --- a/src/main/scala/io/izzel/taboolib/TabooLib.java +++ b/src/main/scala/io/izzel/taboolib/TabooLib.java @@ -71,6 +71,11 @@ public class TabooLib { // 创建线程检测服务器是否关闭 Executors.newSingleThreadExecutor().submit(() -> { while (NMS.handle().isRunning()) { + try { + Thread.sleep(50); + } catch (InterruptedException e) { + e.printStackTrace(); + } } // 保存数据 Local.saveFiles(); diff --git a/src/main/scala/io/izzel/taboolib/util/TMap.java b/src/main/scala/io/izzel/taboolib/util/TMap.java index 6de9a63..d366623 100644 --- a/src/main/scala/io/izzel/taboolib/util/TMap.java +++ b/src/main/scala/io/izzel/taboolib/util/TMap.java @@ -56,11 +56,11 @@ public class TMap { } public static TMap parse(String in) { - Matcher matcher = Pattern.compile("(?[^{}]+)?\\{(?[^<>]+)}").matcher(in); + Matcher matcher = Pattern.compile("(?[^{}]+)?\\{(?[^<>]+)}").matcher(in.replaceAll("[\r\n]", "")); if (matcher.find()) { TMap map = new TMap(matcher.group("name")); for (String content : matcher.group("content").split(";")) { - String[] v = content.split("="); + String[] v = parsePair(content); if (v.length == 2) { map.content.put(v[0].toLowerCase().trim(), v[1].trim()); } @@ -70,6 +70,18 @@ public class TMap { return new TMap(null); } + public static String[] parsePair(String in) { + String[] v = in.split("="); + StringBuilder r = new StringBuilder(); + for (int i = 1; i < v.length; i++) { + if (i > 1) { + r.append("="); + } + r.append(v[i]); + } + return new String[] {v[0], r.toString().replace("`", "")}; + } + @Override public boolean equals(Object o) { if (this == o) {