1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-12-25 07:08:52 +00:00

fix: 修复配置更新存在的问题

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-10-28 13:26:28 +08:00
parent ec5cb657cc
commit b4d7f14d49
3 changed files with 14 additions and 17 deletions

View File

@ -560,9 +560,9 @@ public class FileConfig extends AbstractConfig {
/**
* 更新配置文件
*
* @param newcfg
* @param newCfg
* 新配置文件
* @param oldcfg
* @param oldCfg
* 旧配置文件
* @return 更新以后的配置文件
*/
@ -599,7 +599,8 @@ public class FileConfig extends AbstractConfig {
Object var = oldCfg.get(string);
// 需要进行节点检查 还有类型检查 不同类型情况下 使用新配置
if (var != null && !(var instanceof MemorySection)) {
if (!newCfg.get(string).getClass().equals(var.getClass())) {
Object newVer = newCfg.get(string);
if (newVer != null && !newVer.getClass().equals(var.getClass())) {
Log.w("警告! 旧数据类型与新配置类型不匹配!");
}
Log.debug(String.format(CONFIG_UPDATE_VALUE, string, var));

View File

@ -35,17 +35,18 @@ public abstract class AbstractInjectConfig {
*
* @param field
* 字段
* @param value
*
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
private void applyDefault(Field field, Object value) throws IllegalArgumentException, IllegalAccessException {
private void applyDefault(Field field) throws IllegalArgumentException, IllegalAccessException {
Object value = null;
switch (field.getType().getName()) {
case "java.util.List":
value = new ArrayList<>();
break;
case "java.util.Map":
value = new HashMap<>();
break;
}
field.set(this, value);
}
@ -92,9 +93,7 @@ public abstract class AbstractInjectConfig {
*/
private Object hanldeDefault(Class<?> field, String path, Object value) throws IllegalAccessException, IllegalArgumentException, InstantiationException, InvocationTargetException, NoSuchMethodException, SecurityException {
if (InjectConfigurationSection.class.isAssignableFrom(field)) {
if (config.isConfigurationSection(path)) { return field
.getConstructor(ConfigurationSection.class)
.newInstance(config.getConfigurationSection(path)); }
if (config.isConfigurationSection(path)) { return field.getConstructor(ConfigurationSection.class).newInstance(config.getConfigurationSection(path)); }
Log.w(INJECT_TYPE_ERROR, path, ConfigurationSection.class.getName(), value.getClass().getName());
}
return value;
@ -123,7 +122,7 @@ public abstract class AbstractInjectConfig {
value = convertType(type, path, value);
}
if (type.equals(String.class)) {
value = ChatColor.translateAlternateColorCodes('&', (String) value);
value = ChatColor.translateAlternateColorCodes('&', String.valueOf(value));
}
field.set(this, value);
Log.d("设置字段 %s 为 %s ", field.getName(), value);
@ -219,16 +218,13 @@ public abstract class AbstractInjectConfig {
if (value == null) {
if (field.getAnnotation(Nullable.class) == null) {
Log.w(PATH_NOT_FOUND, path);
applyDefault(field, value);
applyDefault(field);
}
return;
}
hanldeValue(path, field, value);
} catch (IllegalArgumentException ex) {
Log.w(INJECT_TYPE_ERROR,
path,
field.getType().getName(),
value != null ? value.getClass().getName() : "空指针");
Log.w(INJECT_TYPE_ERROR, path, field.getType().getName(), value != null ? value.getClass().getName() : "空指针");
Log.debug(ex);
} catch (ConfigParseException e) {
Log.w(e.getMessage());

View File

@ -84,7 +84,7 @@ public class InjectParse {
}
}
public static interface Parse<FC> {
public FC parse(ConfigurationSection config, String path);
public interface Parse<FC> {
FC parse(ConfigurationSection config, String path);
}
}