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