1
mirror of https://github.com/CarmJos/UserPrefix.git synced 2026-07-16 08:51:09 +08:00

2.1.7 提供自定义配置文件存储位置的功能

This commit is contained in:
carm
2021-10-24 07:12:47 +08:00
parent 83b9ced6f5
commit 1a2644210b
5 changed files with 39 additions and 2 deletions
@@ -11,6 +11,14 @@ public class PrefixConfig {
public static ConfigValue<Boolean> DEBUG = new ConfigValue<>("debug", Boolean.class, false);
public static class CustomStorage {
public static ConfigValue<Boolean> ENABLE = new ConfigValue<>("custom-storage.enable", Boolean.class, false);
public static ConfigValue<String> PATH = new ConfigValue<>("custom-storage.path", String.class, "prefixes/");
}
public static class Functions {
public static ConfigValue<Boolean> NAME_PREFIX = new ConfigValue<>("functions.OnNamePrefix", Boolean.class, true);
@@ -1,6 +1,7 @@
package cc.carm.plugin.userprefix.manager;
import cc.carm.plugin.userprefix.Main;
import cc.carm.plugin.userprefix.configuration.PrefixConfig;
import cc.carm.plugin.userprefix.model.ConfiguredPrefix;
import cc.carm.plugin.userprefix.util.ItemStackFactory;
import org.bukkit.Material;
@@ -37,7 +38,7 @@ public class PrefixManager {
public static void loadConfiguredPrefixes() {
File prefixDataFolder = new File(Main.getInstance().getDataFolder() + File.separator + FOLDER_NAME);
File prefixDataFolder = getStorageFolder();
if (!prefixDataFolder.isDirectory() || !prefixDataFolder.exists()) {
prefixDataFolder.mkdir();
}
@@ -150,5 +151,18 @@ 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);
}
} else {
return new File(Main.getInstance().getDataFolder() + File.separator + FOLDER_NAME);
}
}
}