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
*/
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) {

View File

@ -56,8 +56,7 @@ public class CommentConfig extends AbstractConfig {
}
} else {
matcher = countSpacePattern.matcher(part);
if (matcher.find()) {
if (!lastComments.isEmpty()) {
if (matcher.find() && !lastComments.isEmpty()) {
for (final String comment : lastComments) {
builder.append(matcher.group(1));
builder.append(this.checkNull(matcher.group(2)));
@ -68,7 +67,6 @@ public class CommentConfig extends AbstractConfig {
}
lastComments.clear();
}
}
builder.append(part);
builder.append(newLine);
}
@ -91,11 +89,9 @@ 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) {
if (matcher.find() && matcher.groupCount() == 5) {
part = this.checkNull(matcher.group(1)) + matcher.group(4);
}
}
savcontent.append(part.replaceAll("", ".").replaceAll("", "'").replaceAll("", ":"));
savcontent.append(newLine);
}

View File

@ -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<String> getColorList(final List<String> cfgmsg) {
final List<String> 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<String> getMessageList(final String path) {
final List<String> 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);
}

View File

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

View File

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

View File

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