diff --git a/src/main/java/pw/yumc/YumCore/config/AbstractConfig.java b/src/main/java/pw/yumc/YumCore/config/AbstractConfig.java index 6ecc944..c8bc0a6 100644 --- a/src/main/java/pw/yumc/YumCore/config/AbstractConfig.java +++ b/src/main/java/pw/yumc/YumCore/config/AbstractConfig.java @@ -54,7 +54,7 @@ public abstract class AbstractConfig extends YamlConfiguration { /** * 配置文件内容MAP */ - protected Map contentsMap; + protected Map contentsMap; /** * 配置内容字符串 @@ -64,7 +64,7 @@ public abstract class AbstractConfig extends YamlConfiguration { /** * @return 获得配置内容 */ - public Map getContentMap() { + public Map getContentMap() { return contentsMap; } @@ -95,7 +95,7 @@ public abstract class AbstractConfig extends YamlConfiguration { public void loadFromString(final String contents) throws InvalidConfigurationException { Validate.notNull(contents, CONTENT_NOT_BE_NULL); try { - contentsMap = (Map) yamlz.load(contents); + contentsMap = (Map) yamlz.load(contents); } catch (final YAMLException e) { throw new InvalidConfigurationException(e); } catch (final ClassCastException e) { diff --git a/src/main/java/pw/yumc/YumCore/config/CommentConfig.java b/src/main/java/pw/yumc/YumCore/config/CommentConfig.java index 22ca7dc..32d40ea 100644 --- a/src/main/java/pw/yumc/YumCore/config/CommentConfig.java +++ b/src/main/java/pw/yumc/YumCore/config/CommentConfig.java @@ -56,18 +56,16 @@ public class CommentConfig extends AbstractConfig { } } else { matcher = countSpacePattern.matcher(part); - if (matcher.find()) { - if (!lastComments.isEmpty()) { - for (final String comment : lastComments) { - builder.append(matcher.group(1)); - builder.append(this.checkNull(matcher.group(2))); - builder.append(commentPrefixSymbol); - builder.append(comment); - builder.append(commentSuffixSymbol); - builder.append(newLine); - } - lastComments.clear(); + if (matcher.find() && !lastComments.isEmpty()) { + for (final String comment : lastComments) { + builder.append(matcher.group(1)); + builder.append(this.checkNull(matcher.group(2))); + builder.append(commentPrefixSymbol); + builder.append(comment); + builder.append(commentSuffixSymbol); + builder.append(newLine); } + lastComments.clear(); } builder.append(part); builder.append(newLine); @@ -91,10 +89,8 @@ public class CommentConfig extends AbstractConfig { final String[] parts = contents.split(newLine); for (String part : parts) { final Matcher matcher = toPattern.matcher(part); - if (matcher.find()) { - if (matcher.groupCount() == 5) { - part = this.checkNull(matcher.group(1)) + matcher.group(4); - } + if (matcher.find() && matcher.groupCount() == 5) { + part = this.checkNull(matcher.group(1)) + matcher.group(4); } savcontent.append(part.replaceAll(".", ".").replaceAll("'", "'").replaceAll(":", ":")); savcontent.append(newLine); diff --git a/src/main/java/pw/yumc/YumCore/config/FileConfig.java b/src/main/java/pw/yumc/YumCore/config/FileConfig.java index a182192..c51e9f9 100644 --- a/src/main/java/pw/yumc/YumCore/config/FileConfig.java +++ b/src/main/java/pw/yumc/YumCore/config/FileConfig.java @@ -8,6 +8,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Set; @@ -185,7 +186,7 @@ public class FileConfig extends AbstractConfig { public List getColorList(final List cfgmsg) { final List message = new ArrayList<>(); if (cfgmsg == null) { - return null; + return Collections.emptyList(); } for (final String msg : cfgmsg) { message.add(ChatColor.translateAlternateColorCodes('&', msg)); @@ -265,7 +266,7 @@ public class FileConfig extends AbstractConfig { public List getMessageList(final String path) { final List cfgmsg = this.getStringList(path); if (cfgmsg == null) { - return null; + return Collections.emptyList(); } for (int i = 0; i < cfgmsg.size(); i++) { cfgmsg.set(i, ChatColor.translateAlternateColorCodes(ALT_COLOR_CHAR, cfgmsg.get(i))); @@ -498,7 +499,9 @@ public class FileConfig extends AbstractConfig { * @return yyyy-MM-dd HH:mm:ss */ protected String getStringDate(String format) { - format = format == null ? "yyyy-MM-dd HH:mm:ss" : format; + if (format == null) { + format = "yyyy-MM-dd HH:mm:ss"; + } final Date currentTime = new Date(); return new SimpleDateFormat(format).format(currentTime); } diff --git a/src/main/java/pw/yumc/YumCore/config/RemoteConfig.java b/src/main/java/pw/yumc/YumCore/config/RemoteConfig.java index 834f17e..46a8349 100644 --- a/src/main/java/pw/yumc/YumCore/config/RemoteConfig.java +++ b/src/main/java/pw/yumc/YumCore/config/RemoteConfig.java @@ -52,7 +52,8 @@ public class RemoteConfig extends FileConfig { String result = def; try { result = getConfig(url).getString(tag); - } catch (final Exception e) { + } catch (final NullPointerException e) { + // Ignore } return result; } diff --git a/src/main/java/pw/yumc/YumCore/config/YumConfig.java b/src/main/java/pw/yumc/YumCore/config/YumConfig.java index c302206..fec303d 100644 --- a/src/main/java/pw/yumc/YumCore/config/YumConfig.java +++ b/src/main/java/pw/yumc/YumCore/config/YumConfig.java @@ -12,6 +12,9 @@ public class YumConfig { private static final String fromYumc = "配置 %s 来自 YUMC 数据中心..."; private static final String createError = "从 YUMC 数据中心下载配置 %s 失败..."; + private YumConfig() { + } + /** * 获得本地配置文件 * diff --git a/src/main/java/pw/yumc/YumCore/misc/L10N.java b/src/main/java/pw/yumc/YumCore/misc/L10N.java index 6b9b322..8221166 100644 --- a/src/main/java/pw/yumc/YumCore/misc/L10N.java +++ b/src/main/java/pw/yumc/YumCore/misc/L10N.java @@ -117,8 +117,8 @@ public class L10N { @Override public void run() { try { - final Map local = (Map) YumConfig.getLocal(CONFIG_NAME).getContentMap(); - final Map remote = (Map) YumConfig.getRemote(CONFIG_NAME).getContentMap(); + final Map local = YumConfig.getLocal(CONFIG_NAME).getContentMap(); + final Map remote = YumConfig.getRemote(CONFIG_NAME).getContentMap(); if (local != null) { Log.info("本地汉化文件词条数量: " + local.size()); content.putAll(local);