mirror of
https://github.com/CarmJos/UserPrefix.git
synced 2024-09-19 20:15:47 +00:00
自动提交默认值
This commit is contained in:
parent
3b03ec4616
commit
2357699324
@ -32,8 +32,13 @@ public class ConfigValue<V> {
|
||||
}
|
||||
|
||||
public V get() {
|
||||
if (getConfiguration().contains(this.configSection)) {
|
||||
Object val = getConfiguration().get(this.configSection, this.defaultValue);
|
||||
return this.clazz.isInstance(val) ? this.clazz.cast(val) : this.defaultValue;
|
||||
} else {
|
||||
// 如果没有默认值,就把配置写进去,便于配置
|
||||
return setDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public void set(V value) {
|
||||
@ -45,4 +50,9 @@ public class ConfigValue<V> {
|
||||
this.source.save();
|
||||
}
|
||||
|
||||
public V setDefault() {
|
||||
set(this.defaultValue);
|
||||
return this.defaultValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,10 +45,12 @@ public class PrefixManager {
|
||||
|
||||
String[] filesList = prefixDataFolder.list();
|
||||
if (filesList == null || filesList.length < 1) {
|
||||
Main.log("配置文件中暂无任何前缀配置,请检查。");
|
||||
Main.log("配置文件夹中暂无任何前缀配置问,请检查。");
|
||||
Main.log("There's no configured prefix.");
|
||||
Main.log("Path: " + prefixDataFolder.getAbsolutePath());
|
||||
return;
|
||||
}
|
||||
|
||||
List<File> files = Arrays.stream(filesList)
|
||||
.map(s -> new File(prefixDataFolder, s))
|
||||
.filter(File::isFile)
|
||||
@ -75,7 +77,8 @@ public class PrefixManager {
|
||||
|
||||
public static void loadDefaultPrefix() {
|
||||
PrefixManager.defaultPrefix = null;
|
||||
ConfigurationSection defaultPrefixSection = ConfigManager.getPluginConfig().getConfig().getConfigurationSection("defaultPrefix");
|
||||
ConfigurationSection defaultPrefixSection = ConfigManager.getPluginConfig()
|
||||
.getConfig().getConfigurationSection("defaultPrefix");
|
||||
if (defaultPrefixSection != null) {
|
||||
try {
|
||||
String name = defaultPrefixSection.getString("name", "默认前缀");
|
||||
@ -153,12 +156,7 @@ public class PrefixManager {
|
||||
|
||||
private static File getStorageFolder() {
|
||||
if (PrefixConfig.CustomStorage.ENABLE.get()) {
|
||||
String path = PrefixConfig.CustomStorage.PATH.get();
|
||||
if (path.startsWith(File.separator)) {
|
||||
return new File(path);
|
||||
} else {
|
||||
return new File(Main.getInstance().getDataFolder() + File.separator + path);
|
||||
}
|
||||
return new File(PrefixConfig.CustomStorage.PATH.get());
|
||||
} else {
|
||||
return new File(Main.getInstance().getDataFolder() + File.separator + FOLDER_NAME);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: ${project.version}
|
||||
version: ${project.version} #配置文件版本,若与插件版本不同请记得检查配置文件内容
|
||||
|
||||
debug: false
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user