development status
add EnumManager
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
// This class was created by JaTiTV.
|
||||
|
||||
package net.t2code.t2codelib.SPIGOT.api.yaml;
|
||||
|
||||
import net.t2code.t2codelib.T2CconfigItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class T2CconfigEnumManager {
|
||||
|
||||
private final List<AdditionalEnum> additionalEnums = new ArrayList<>();
|
||||
|
||||
public static class AdditionalEnum implements T2CconfigItem {
|
||||
private final String key;
|
||||
private String path;
|
||||
private Object value;
|
||||
private List<String> comments;
|
||||
|
||||
public AdditionalEnum(String key, String path, Object value, String... comments) {
|
||||
this.key = key;
|
||||
this.path = path;
|
||||
this.value = value;
|
||||
this.comments = new ArrayList<>(Arrays.asList(comments));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object newValue) {
|
||||
value = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Method to add or change an "enum" value
|
||||
public void addOrChangeEnum(Object key, String path, Object value, String... comments) {
|
||||
// Check if the key already exists
|
||||
for (AdditionalEnum enumValue : additionalEnums) {
|
||||
if (enumValue.key.equals(key)) {
|
||||
// Update existing enum
|
||||
enumValue.path = path;
|
||||
enumValue.value = value;
|
||||
enumValue.comments = Arrays.asList(comments);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Add new enum
|
||||
AdditionalEnum newEnum = new AdditionalEnum(key.toString(), path, value, comments);
|
||||
additionalEnums.add(newEnum);
|
||||
}
|
||||
|
||||
// Method to retrieve all enums (original and additional)
|
||||
public List<AdditionalEnum> getAllEnums() {
|
||||
return new ArrayList<>(additionalEnums);
|
||||
}
|
||||
|
||||
// Method to retrieve specific enum details
|
||||
public AdditionalEnum getEnumDetails(Object key) {
|
||||
for (AdditionalEnum e : additionalEnums) {
|
||||
if (e.key.equals(key.toString())) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,96 @@
|
||||
// This class was created by JaTiTV.
|
||||
|
||||
package net.t2code.t2codelib.SPIGOT.api.yaml;
|
||||
|
||||
import net.t2code.t2codelib.T2CconfigItem;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class T2CconfigWriter {
|
||||
|
||||
private static FileConfiguration config;
|
||||
|
||||
|
||||
public static void createConfig(File configFile, T2CconfigEnumManager manager, String... header) {
|
||||
if (!configFile.exists()) {
|
||||
configFile.getParentFile().mkdirs();
|
||||
try {
|
||||
configFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
Map<String, List<String>> comments = new LinkedHashMap<>();
|
||||
|
||||
for(T2CconfigEnumManager.AdditionalEnum item : manager.getAllEnums()){
|
||||
config.addDefault(item.getKey(), item.getValue());
|
||||
comments.put(item.getKey(), item.getComments());
|
||||
}
|
||||
|
||||
// Copy default values if they are missing
|
||||
config.options().copyDefaults(true);
|
||||
saveConfigWithComments(configFile, comments, header);
|
||||
readConfig(config,values);
|
||||
}
|
||||
|
||||
private static void readConfig(FileConfiguration config, T2CconfigItem[] values) {
|
||||
for(T2CconfigItem item : values){
|
||||
item.setValue(config.get(item.getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveConfigWithComments(File file, Map<String, List<String>> comments, String... headers) {
|
||||
try {
|
||||
StringBuilder configContent = new StringBuilder();
|
||||
for(String h : headers){
|
||||
configContent.append("# ").append(h).append("\n");
|
||||
}
|
||||
configContent.append("\n");
|
||||
addSection(config, comments, configContent, "", 0);
|
||||
|
||||
// Write the content to the file
|
||||
Files.write(file.toPath(), configContent.toString().getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void addSection(ConfigurationSection section, Map<String, List<String>> comments, StringBuilder builder, String prefix, int indentLevel) {
|
||||
String indent = " ".repeat(indentLevel);
|
||||
|
||||
|
||||
for (String key : section.getKeys(false)) {
|
||||
String fullKey = prefix.isEmpty() ? key : prefix + "." + key;
|
||||
Object value = section.get(key);
|
||||
|
||||
// Add comment if it exists for this key
|
||||
List<String> commentList = comments.get(fullKey);
|
||||
if (commentList != null) {
|
||||
for(String c : commentList){
|
||||
builder.append(indent).append("# ").append(c).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the value is a section (nested map)
|
||||
if (value instanceof ConfigurationSection) {
|
||||
// Correctly add the section
|
||||
builder.append(indent).append(key).append(":\n");
|
||||
addSection((ConfigurationSection) value, comments, builder, fullKey, indentLevel + 1);
|
||||
} else {
|
||||
// Add value with proper indentation
|
||||
builder.append(indent).append(key).append(": ").append(value).append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -131,7 +131,7 @@ public final class T2CodeLibMain extends JavaPlugin {
|
||||
|
||||
|
||||
plugin.getCommand("t2code").setExecutor(new CmdExecuter());
|
||||
ConfigCreate.configCreate();
|
||||
ConfigCreate.set();
|
||||
T2CitemVersion.scan();
|
||||
LanguagesCreate.langCreate();
|
||||
SelectLibConfig.onSelect();
|
||||
|
@@ -1,46 +1,87 @@
|
||||
package net.t2code.t2codelib.SPIGOT.system.config.config;
|
||||
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||
import net.t2code.t2codelib.SPIGOT.api.yaml.T2Cconfig;
|
||||
import net.t2code.t2codelib.SPIGOT.api.yaml.T2CconfigEnumManager;
|
||||
import net.t2code.t2codelib.SPIGOT.api.yaml.T2CconfigWriter;
|
||||
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||
import net.t2code.t2codelib.T2CconfigItem;
|
||||
import net.t2code.t2codelib.Util;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class ConfigCreate {
|
||||
|
||||
public static void configCreate() {
|
||||
long long_ = System.currentTimeMillis();
|
||||
if (new File(T2CodeLibMain.getPath(), "config.yml").exists()){
|
||||
if (T2CodeLibMain.getPlugin().getConfig().getBoolean("Plugin.Debug")) T2Csend.console(Util.getPrefix() + " §5DEBUG: §6" + " §4config.yml are created / updated...");
|
||||
} else T2Csend.console(Util.getPrefix() + " §4config.yml are created...");
|
||||
/**
|
||||
public enum VALUES implements T2CconfigItem {
|
||||
updateCheckOnJoin("plugin.updateCheck.onJoin", true),
|
||||
updateCheckTimeInterval("plugin.updateCheck.timeInterval", 60),
|
||||
seePreReleaseUpdates("plugin.updateCheck.seePreReleaseUpdates", true),
|
||||
updateCheckFullDisable("plugin.updateCheck.allPlugins.FullDisable", false),
|
||||
debug("plugin.debug.debugModus", false),
|
||||
developerTool("plugin.debug.developerTool", true),
|
||||
language("plugin.language", "english"),
|
||||
bungee("proxy.enable", T2CodeLibMain.getIsBungee()),
|
||||
inventoriesCloseByServerStop("player.inventories.closeByServerStop", true),
|
||||
commandPermToggleCommand("command.permToggle.permissionSetCommand", "lp user [player] permission set [perm] [value]"),
|
||||
|
||||
;
|
||||
|
||||
File config = new File(T2CodeLibMain.getPath(), "config.yml");
|
||||
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
||||
private final String key;
|
||||
private Object value;
|
||||
private final List<String> comments;
|
||||
|
||||
|
||||
T2Cconfig.set("Plugin.UpdateCheck.OnJoin", true, yamlConfiguration);
|
||||
T2Cconfig.set("Plugin.UpdateCheck.TimeInterval", 60, yamlConfiguration);
|
||||
T2Cconfig.set("Plugin.UpdateCheck.SeePreReleaseUpdates", true, yamlConfiguration);
|
||||
T2Cconfig.set("Plugin.UpdateCheck.AllPlugins.FullDisable", false, yamlConfiguration);
|
||||
T2Cconfig.set("Plugin.language", "english", yamlConfiguration);
|
||||
T2Cconfig.set("Plugin.Not recommended to disable.developerTool", true, yamlConfiguration);
|
||||
|
||||
T2Cconfig.set("BungeeCord.Enable", T2CodeLibMain.getIsBungee(), yamlConfiguration);
|
||||
T2Cconfig.set("Player.Inventories.CloseByServerStop", true, yamlConfiguration);
|
||||
|
||||
T2Cconfig.set("Command.PermToggle.PermissionSetCommand","lp user [player] permission set [perm] [value]",yamlConfiguration);
|
||||
|
||||
try {
|
||||
yamlConfiguration.save(config);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
VALUES(String key, Object value, String... comments) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.comments = new ArrayList<>(Arrays.asList(comments));
|
||||
}
|
||||
|
||||
T2Csend.console(Util.getPrefix() + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||
@Override
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object newValue) {
|
||||
value = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
public static final T2CconfigEnumManager manager = new T2CconfigEnumManager();
|
||||
|
||||
|
||||
public static void set() {
|
||||
long long_ = System.currentTimeMillis();
|
||||
|
||||
manager.addOrChangeEnum(ConfigKey.updateCheckOnJoin, "plugin.updateCheck.onJoin", true);
|
||||
manager.addOrChangeEnum(ConfigKey.updateCheckTimeInterval, "plugin.updateCheck.timeInterval", 60);
|
||||
manager.addOrChangeEnum(ConfigKey.seePreReleaseUpdates, "plugin.updateCheck.seePreReleaseUpdates", true);
|
||||
manager.addOrChangeEnum(ConfigKey.updateCheckFullDisable, "plugin.updateCheck.allPlugins.FullDisable", false);
|
||||
manager.addOrChangeEnum(ConfigKey.debug, "plugin.debug.debugModus", false);
|
||||
manager.addOrChangeEnum(ConfigKey.developerTool, "plugin.debug.developerTool", true);
|
||||
manager.addOrChangeEnum(ConfigKey.language, "plugin.language", "english");
|
||||
manager.addOrChangeEnum(ConfigKey.bungee, "proxy.enable", T2CodeLibMain.getIsBungee());
|
||||
manager.addOrChangeEnum(ConfigKey.inventoriesCloseByServerStop, "player.inventories.closeByServerStop", true);
|
||||
manager.addOrChangeEnum(ConfigKey.commandPermToggleCommand, "command.permToggle.permissionSetCommand", "lp user [player] permission set [perm] [value]");
|
||||
|
||||
T2CconfigWriter.createConfig(new File(T2CodeLibMain.getPath(), "config.yml"), manager.getAllEnums(), "PL von", "Jattitv");
|
||||
T2CconfigWriter.createConfig(new File(T2CodeLibMain.getPath(), "config.yml"), VALUES.values(), "PL von", "Jattitv");
|
||||
|
||||
T2Csend.console(Util.getPrefix() + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,14 @@
|
||||
package net.t2code.t2codelib.SPIGOT.system.config.config;
|
||||
|
||||
public enum ConfigKey {
|
||||
updateCheckOnJoin,
|
||||
updateCheckTimeInterval,
|
||||
seePreReleaseUpdates,
|
||||
updateCheckFullDisable,
|
||||
debug,
|
||||
developerTool,
|
||||
language,
|
||||
bungee,
|
||||
inventoriesCloseByServerStop,
|
||||
commandPermToggleCommand
|
||||
}
|
@@ -1,10 +1,14 @@
|
||||
package net.t2code.t2codelib.SPIGOT.system.config.config;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||
import net.t2code.t2codelib.SPIGOT.api.yaml.T2Cconfig;
|
||||
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||
import net.t2code.t2codelib.Util;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SelectLibConfig {
|
||||
|
||||
@@ -50,4 +54,36 @@ public class SelectLibConfig {
|
||||
inventoriesCloseByServerStop = yamlConfiguration.getBoolean("Player.Inventories.CloseByServerStop");
|
||||
commandPermToggleCommand = yamlConfiguration.getString("Command.PermToggle.PermissionSetCommand");
|
||||
}
|
||||
|
||||
public static void configCreate() {
|
||||
long long_ = System.currentTimeMillis();
|
||||
if (new File(T2CodeLibMain.getPath(), "config.yml").exists()){
|
||||
if (T2CodeLibMain.getPlugin().getConfig().getBoolean("Plugin.Debug")) T2Csend.console(Util.getPrefix() + " §5DEBUG: §6" + " §4config.yml are created / updated...");
|
||||
} else T2Csend.console(Util.getPrefix() + " §4config.yml are created...");
|
||||
|
||||
|
||||
File config = new File(T2CodeLibMain.getPath(), "config.yml");
|
||||
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
||||
|
||||
|
||||
T2Cconfig.set("Plugin.UpdateCheck.OnJoin", true, yamlConfiguration);
|
||||
T2Cconfig.set("Plugin.UpdateCheck.TimeInterval", 60, yamlConfiguration);
|
||||
T2Cconfig.set("Plugin.UpdateCheck.SeePreReleaseUpdates", true, yamlConfiguration);
|
||||
T2Cconfig.set("Plugin.UpdateCheck.AllPlugins.FullDisable", false, yamlConfiguration);
|
||||
T2Cconfig.set("Plugin.language", "english", yamlConfiguration);
|
||||
T2Cconfig.set("Plugin.Not recommended to disable.developerTool", true, yamlConfiguration);
|
||||
|
||||
T2Cconfig.set("BungeeCord.Enable", T2CodeLibMain.getIsBungee(), yamlConfiguration);
|
||||
T2Cconfig.set("Player.Inventories.CloseByServerStop", true, yamlConfiguration);
|
||||
|
||||
T2Cconfig.set("Command.PermToggle.PermissionSetCommand","lp user [player] permission set [perm] [value]",yamlConfiguration);
|
||||
|
||||
try {
|
||||
yamlConfiguration.save(config);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
T2Csend.console(Util.getPrefix() + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user