1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-22 01:48:50 +00:00

fix: 修复一般问题

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-09-19 16:59:10 +08:00
parent fed4b94a8d
commit ba46c73cc7
6 changed files with 27 additions and 24 deletions

View File

@ -54,7 +54,7 @@ public abstract class AbstractConfig extends YamlConfiguration {
/** /**
* 配置文件内容MAP * 配置文件内容MAP
*/ */
protected Map<?, ?> contentsMap; protected Map contentsMap;
/** /**
* 配置内容字符串 * 配置内容字符串
@ -64,7 +64,7 @@ public abstract class AbstractConfig extends YamlConfiguration {
/** /**
* @return 获得配置内容 * @return 获得配置内容
*/ */
public Map<?, ?> getContentMap() { public Map getContentMap() {
return contentsMap; return contentsMap;
} }
@ -95,7 +95,7 @@ public abstract class AbstractConfig extends YamlConfiguration {
public void loadFromString(final String contents) throws InvalidConfigurationException { public void loadFromString(final String contents) throws InvalidConfigurationException {
Validate.notNull(contents, CONTENT_NOT_BE_NULL); Validate.notNull(contents, CONTENT_NOT_BE_NULL);
try { try {
contentsMap = (Map<?, ?>) yamlz.load(contents); contentsMap = (Map) yamlz.load(contents);
} catch (final YAMLException e) { } catch (final YAMLException e) {
throw new InvalidConfigurationException(e); throw new InvalidConfigurationException(e);
} catch (final ClassCastException e) { } catch (final ClassCastException e) {

View File

@ -56,18 +56,16 @@ public class CommentConfig extends AbstractConfig {
} }
} else { } else {
matcher = countSpacePattern.matcher(part); matcher = countSpacePattern.matcher(part);
if (matcher.find()) { if (matcher.find() && !lastComments.isEmpty()) {
if (!lastComments.isEmpty()) { for (final String comment : lastComments) {
for (final String comment : lastComments) { builder.append(matcher.group(1));
builder.append(matcher.group(1)); builder.append(this.checkNull(matcher.group(2)));
builder.append(this.checkNull(matcher.group(2))); builder.append(commentPrefixSymbol);
builder.append(commentPrefixSymbol); builder.append(comment);
builder.append(comment); builder.append(commentSuffixSymbol);
builder.append(commentSuffixSymbol); builder.append(newLine);
builder.append(newLine);
}
lastComments.clear();
} }
lastComments.clear();
} }
builder.append(part); builder.append(part);
builder.append(newLine); builder.append(newLine);
@ -91,10 +89,8 @@ public class CommentConfig extends AbstractConfig {
final String[] parts = contents.split(newLine); final String[] parts = contents.split(newLine);
for (String part : parts) { for (String part : parts) {
final Matcher matcher = toPattern.matcher(part); final Matcher matcher = toPattern.matcher(part);
if (matcher.find()) { if (matcher.find() && matcher.groupCount() == 5) {
if (matcher.groupCount() == 5) { part = this.checkNull(matcher.group(1)) + matcher.group(4);
part = this.checkNull(matcher.group(1)) + matcher.group(4);
}
} }
savcontent.append(part.replaceAll("", ".").replaceAll("", "'").replaceAll("", ":")); savcontent.append(part.replaceAll("", ".").replaceAll("", "'").replaceAll("", ":"));
savcontent.append(newLine); savcontent.append(newLine);

View File

@ -8,6 +8,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -185,7 +186,7 @@ public class FileConfig extends AbstractConfig {
public List<String> getColorList(final List<String> cfgmsg) { public List<String> getColorList(final List<String> cfgmsg) {
final List<String> message = new ArrayList<>(); final List<String> message = new ArrayList<>();
if (cfgmsg == null) { if (cfgmsg == null) {
return null; return Collections.emptyList();
} }
for (final String msg : cfgmsg) { for (final String msg : cfgmsg) {
message.add(ChatColor.translateAlternateColorCodes('&', msg)); message.add(ChatColor.translateAlternateColorCodes('&', msg));
@ -265,7 +266,7 @@ public class FileConfig extends AbstractConfig {
public List<String> getMessageList(final String path) { public List<String> getMessageList(final String path) {
final List<String> cfgmsg = this.getStringList(path); final List<String> cfgmsg = this.getStringList(path);
if (cfgmsg == null) { if (cfgmsg == null) {
return null; return Collections.emptyList();
} }
for (int i = 0; i < cfgmsg.size(); i++) { for (int i = 0; i < cfgmsg.size(); i++) {
cfgmsg.set(i, ChatColor.translateAlternateColorCodes(ALT_COLOR_CHAR, cfgmsg.get(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 * @return yyyy-MM-dd HH:mm:ss
*/ */
protected String getStringDate(String format) { 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(); final Date currentTime = new Date();
return new SimpleDateFormat(format).format(currentTime); return new SimpleDateFormat(format).format(currentTime);
} }

View File

@ -52,7 +52,8 @@ public class RemoteConfig extends FileConfig {
String result = def; String result = def;
try { try {
result = getConfig(url).getString(tag); result = getConfig(url).getString(tag);
} catch (final Exception e) { } catch (final NullPointerException e) {
// Ignore
} }
return result; return result;
} }

View File

@ -12,6 +12,9 @@ public class YumConfig {
private static final String fromYumc = "配置 %s 来自 YUMC 数据中心..."; private static final String fromYumc = "配置 %s 来自 YUMC 数据中心...";
private static final String createError = "从 YUMC 数据中心下载配置 %s 失败..."; private static final String createError = "从 YUMC 数据中心下载配置 %s 失败...";
private YumConfig() {
}
/** /**
* 获得本地配置文件 * 获得本地配置文件
* *

View File

@ -117,8 +117,8 @@ public class L10N {
@Override @Override
public void run() { public void run() {
try { try {
final Map<String, String> local = (Map<String, String>) YumConfig.getLocal(CONFIG_NAME).getContentMap(); final Map<String, String> local = YumConfig.getLocal(CONFIG_NAME).getContentMap();
final Map<String, String> remote = (Map<String, String>) YumConfig.getRemote(CONFIG_NAME).getContentMap(); final Map<String, String> remote = YumConfig.getRemote(CONFIG_NAME).getContentMap();
if (local != null) { if (local != null) {
Log.info("本地汉化文件词条数量: " + local.size()); Log.info("本地汉化文件词条数量: " + local.size());
content.putAll(local); content.putAll(local);