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:
parent
ec5cb657cc
commit
b4d7f14d49
@ -560,9 +560,9 @@ public class FileConfig extends AbstractConfig {
|
|||||||
/**
|
/**
|
||||||
* 更新配置文件
|
* 更新配置文件
|
||||||
*
|
*
|
||||||
* @param newcfg
|
* @param newCfg
|
||||||
* 新配置文件
|
* 新配置文件
|
||||||
* @param oldcfg
|
* @param oldCfg
|
||||||
* 旧配置文件
|
* 旧配置文件
|
||||||
* @return 更新以后的配置文件
|
* @return 更新以后的配置文件
|
||||||
*/
|
*/
|
||||||
@ -599,7 +599,8 @@ public class FileConfig extends AbstractConfig {
|
|||||||
Object var = oldCfg.get(string);
|
Object var = oldCfg.get(string);
|
||||||
// 需要进行节点检查 还有类型检查 不同类型情况下 使用新配置
|
// 需要进行节点检查 还有类型检查 不同类型情况下 使用新配置
|
||||||
if (var != null && !(var instanceof MemorySection)) {
|
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.w("警告! 旧数据类型与新配置类型不匹配!");
|
||||||
}
|
}
|
||||||
Log.debug(String.format(CONFIG_UPDATE_VALUE, string, var));
|
Log.debug(String.format(CONFIG_UPDATE_VALUE, string, var));
|
||||||
|
@ -35,17 +35,18 @@ public abstract class AbstractInjectConfig {
|
|||||||
*
|
*
|
||||||
* @param field
|
* @param field
|
||||||
* 字段
|
* 字段
|
||||||
* @param value
|
|
||||||
* 值
|
|
||||||
* @throws IllegalAccessException
|
* @throws IllegalAccessException
|
||||||
* @throws IllegalArgumentException
|
* @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()) {
|
switch (field.getType().getName()) {
|
||||||
case "java.util.List":
|
case "java.util.List":
|
||||||
value = new ArrayList<>();
|
value = new ArrayList<>();
|
||||||
|
break;
|
||||||
case "java.util.Map":
|
case "java.util.Map":
|
||||||
value = new HashMap<>();
|
value = new HashMap<>();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
field.set(this, value);
|
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 {
|
private Object hanldeDefault(Class<?> field, String path, Object value) throws IllegalAccessException, IllegalArgumentException, InstantiationException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||||
if (InjectConfigurationSection.class.isAssignableFrom(field)) {
|
if (InjectConfigurationSection.class.isAssignableFrom(field)) {
|
||||||
if (config.isConfigurationSection(path)) { return field
|
if (config.isConfigurationSection(path)) { return field.getConstructor(ConfigurationSection.class).newInstance(config.getConfigurationSection(path)); }
|
||||||
.getConstructor(ConfigurationSection.class)
|
|
||||||
.newInstance(config.getConfigurationSection(path)); }
|
|
||||||
Log.w(INJECT_TYPE_ERROR, path, ConfigurationSection.class.getName(), value.getClass().getName());
|
Log.w(INJECT_TYPE_ERROR, path, ConfigurationSection.class.getName(), value.getClass().getName());
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
@ -123,7 +122,7 @@ public abstract class AbstractInjectConfig {
|
|||||||
value = convertType(type, path, value);
|
value = convertType(type, path, value);
|
||||||
}
|
}
|
||||||
if (type.equals(String.class)) {
|
if (type.equals(String.class)) {
|
||||||
value = ChatColor.translateAlternateColorCodes('&', (String) value);
|
value = ChatColor.translateAlternateColorCodes('&', String.valueOf(value));
|
||||||
}
|
}
|
||||||
field.set(this, value);
|
field.set(this, value);
|
||||||
Log.d("设置字段 %s 为 %s ", field.getName(), value);
|
Log.d("设置字段 %s 为 %s ", field.getName(), value);
|
||||||
@ -219,16 +218,13 @@ public abstract class AbstractInjectConfig {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
if (field.getAnnotation(Nullable.class) == null) {
|
if (field.getAnnotation(Nullable.class) == null) {
|
||||||
Log.w(PATH_NOT_FOUND, path);
|
Log.w(PATH_NOT_FOUND, path);
|
||||||
applyDefault(field, value);
|
applyDefault(field);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hanldeValue(path, field, value);
|
hanldeValue(path, field, value);
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
Log.w(INJECT_TYPE_ERROR,
|
Log.w(INJECT_TYPE_ERROR, path, field.getType().getName(), value != null ? value.getClass().getName() : "空指针");
|
||||||
path,
|
|
||||||
field.getType().getName(),
|
|
||||||
value != null ? value.getClass().getName() : "空指针");
|
|
||||||
Log.debug(ex);
|
Log.debug(ex);
|
||||||
} catch (ConfigParseException e) {
|
} catch (ConfigParseException e) {
|
||||||
Log.w(e.getMessage());
|
Log.w(e.getMessage());
|
||||||
|
@ -84,7 +84,7 @@ public class InjectParse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface Parse<FC> {
|
public interface Parse<FC> {
|
||||||
public FC parse(ConfigurationSection config, String path);
|
FC parse(ConfigurationSection config, String path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user