diff --git a/.idea/misc.xml b/.idea/misc.xml index 63ea76a..23ff514 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -14,5 +14,5 @@ - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index b52fa21..fe3045c 100644 --- a/pom.xml +++ b/pom.xml @@ -27,8 +27,8 @@ maven-compiler-plugin 3.8.1 - ${java.version} - ${java.version} + 11 + 11 diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java index f575d81..18d0081 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java @@ -48,13 +48,12 @@ public class T2CBupdateAPI { private static String pluginVersion; public static void onUpdateCheckTimer(Plugin plugin, String prefix, String discord, Integer spigotID, String url) { - Integer finalInterval; - if (T2CBlibConfig.getUpdateTimer() < 1){ - finalInterval = 1; - } else finalInterval = T2CBlibConfig.getUpdateTimer(); + if ((int) T2CBlibConfig.VALUES.updateTimer.getValue() < 1) { + T2CBlibConfig.VALUES.updateTimer.setValue(1); + } ProxyServer.getInstance().getScheduler().schedule(plugin, new Runnable() { public void run() { - if (T2CBlibConfig.getUpdateCheckFullDisable()) return; + if ((boolean) T2CBlibConfig.VALUES.updateCheckFullDisable.getValue()) return; (new T2CBupdateCheckerGit(plugin, spigotID)).getVersion((webData) -> { pluginVersion = plugin.getDescription().getVersion(); T2CupdateObject update = new T2CupdateObject( @@ -77,6 +76,6 @@ public class T2CBupdateAPI { } }, pluginVersion, spigotID, url); } - }, 0, finalInterval * 60 * 20L, TimeUnit.SECONDS); + }, 0, (int) T2CBlibConfig.VALUES.updateTimer.getValue() * 60 * 20L, TimeUnit.SECONDS); } } diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java index 0300fcd..de697b7 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java @@ -26,9 +26,9 @@ public class T2CBupdateCheckerGit { } public void getVersion(Consumer consumer, String pluginVersion, Integer spigotID, String gitKey) { - if (T2CBlibConfig.getUpdateCheckFullDisable()) return; + if ((boolean)T2CBlibConfig.VALUES.updateCheckFullDisable.getValue() ) return; String RepoURL = "https://git.t2code.net/api/v1/repos/" + gitKey + "/releases?limit=1"; - if (!T2CBlibConfig.getSeePreReleaseUpdates()) { + if (!(boolean)T2CBlibConfig.VALUES.seePreReleaseUpdates.getValue() ) { RepoURL = RepoURL + "&pre-release=false"; } String finalRepoURL = RepoURL; diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/yaml/T2CBconfigWriter.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/yaml/T2CBconfigWriter.java new file mode 100644 index 0000000..7f5c62a --- /dev/null +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/yaml/T2CBconfigWriter.java @@ -0,0 +1,100 @@ +// This class was created by JaTiTV. + +package net.t2code.t2codelib.BUNGEE.api.yaml; + +import net.md_5.bungee.config.ConfigurationProvider; +import net.md_5.bungee.config.YamlConfiguration; +import net.t2code.t2codelib.T2CconfigItem; +import net.md_5.bungee.config.Configuration; + +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 T2CBconfigWriter { + + private static Configuration config; + + + public static void createConfig(File configFile, T2CconfigItem[] values, String... header) { + if (!configFile.exists()) { + configFile.getParentFile().mkdirs(); + try { + configFile.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + return; + } + } + + try { + config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); + } catch (IOException e) { + throw new RuntimeException(e); + } + Map> comments = new LinkedHashMap<>(); + + for(T2CconfigItem item : values){ + if(!config.contains(item.getKey())){ + config.set(item.getKey(), item.getValue()); + } + comments.put(item.getKey(), item.getComments()); + } + saveConfigWithComments(configFile, comments, header); + readConfig(config,values); + } + + private static void readConfig(Configuration config, T2CconfigItem[] values) { + for(T2CconfigItem item : values){ + item.setValue(config.get(item.getKey())); + } + } + + private static void saveConfigWithComments(File file, Map> 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(Configuration section, Map> comments, StringBuilder builder, String prefix, int indentLevel) { + String indent = " ".repeat(indentLevel); + + + for (String key : section.getKeys()) { + String fullKey = prefix.isEmpty() ? key : prefix + "." + key; + Object value = section.get(key); + + // Add comment if it exists for this key + List 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 Configuration) { + // Correctly add the section + builder.append(indent).append(key).append(":\n"); + addSection((Configuration) value, comments, builder, fullKey, indentLevel + 1); + } else { + // Add value with proper indentation + builder.append(indent).append(key).append(": ").append(value).append("\n"); + } + } + } +} diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java index 4aef1a1..37189cd 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java @@ -3,9 +3,10 @@ package net.t2code.t2codelib.BUNGEE.system; import net.md_5.bungee.api.plugin.Plugin; import net.t2code.t2codelib.BUNGEE.api.messages.T2CBsend; import net.t2code.t2codelib.BUNGEE.api.update.T2CBupdateAPI; +import net.t2code.t2codelib.BUNGEE.api.yaml.T2CBconfigWriter; import net.t2code.t2codelib.BUNGEE.system.bstats.T2CBmetrics; -import net.t2code.t2codelib.BUNGEE.system.config.T2CBlibConfig; import net.t2code.t2codelib.BUNGEE.api.bungeePlayers.T2CBbungeePlayers; +import net.t2code.t2codelib.BUNGEE.system.config.T2CBlibConfig; import net.t2code.t2codelib.BUNGEE.system.pluginMessaging.T2CplmsgBcmd; import net.t2code.t2codelib.BUNGEE.system.pluginMessaging.autoResponse.T2CapiAutoResponse; import net.t2code.t2codelib.BUNGEE.system.pluginMessaging.commandgui.T2CapiCGUI; @@ -23,16 +24,7 @@ public class T2CBload { T2CBsend.console(prefix + " §2Discord: §6" + discord); T2CBmetrics.Bstats(plugin, bstatsID); - try { - T2CBlibConfig.create(); - } catch (IOException e) { - throw new RuntimeException(e); - } - try { - T2CBlibConfig.select(); - } catch (IOException e) { - throw new RuntimeException(e); - } + T2CBlibConfig.set(); T2CBupdateAPI.onUpdateCheckTimer(plugin, prefix, discord, spigotID, url); @@ -44,16 +36,16 @@ public class T2CBload { plugin.getProxy().getPluginManager().registerListener(plugin, new T2CBbungeePlayers()); T2CBbungeePlayers.sendToSpigotDeleteAll(); - if (T2CBlibConfig.getApiCommandGUIEnable()) { + if ((boolean) T2CBlibConfig.VALUES.apiCommandGUIEnable.getValue()) { plugin.getProxy().registerChannel("t2c:cguiopl"); plugin.getProxy().getPluginManager().registerListener(plugin, new T2CapiCGUI()); T2CapiCGUI.sendToSpigotDeleteAll(); } - if (T2CBlibConfig.getApiAutoResponse()) { + if ( (boolean)T2CBlibConfig.VALUES.apiAutoResponse.getValue() ) { plugin.getProxy().registerChannel("t2c:aresp"); plugin.getProxy().getPluginManager().registerListener(plugin, new T2CapiAutoResponse()); } - if (T2CBlibConfig.getApiOpSecurity()) { + if ((boolean)T2CBlibConfig.VALUES.apiOpSecurity.getValue()) { plugin.getProxy().registerChannel("t2c:t2c:opsec"); plugin.getProxy().getPluginManager().registerListener(plugin, new T2CapiOpSecurity()); } diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java index 87c0643..926e155 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java @@ -1,63 +1,63 @@ package net.t2code.t2codelib.BUNGEE.system.config; -import lombok.Getter; -import net.md_5.bungee.config.Configuration; -import net.md_5.bungee.config.ConfigurationProvider; -import net.md_5.bungee.config.YamlConfiguration; -import net.t2code.t2codelib.BUNGEE.api.messages.T2CBsend; -import net.t2code.t2codelib.BUNGEE.api.yaml.T2CBconfig; +import net.t2code.t2codelib.BUNGEE.api.yaml.T2CBconfigWriter; import net.t2code.t2codelib.BUNGEE.system.T2CodeBMain; +import net.t2code.t2codelib.T2CconfigItem; import net.t2code.t2codelib.Util; import java.io.File; -import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; public class T2CBlibConfig { - public static void create() throws IOException { - long long_ = System.currentTimeMillis(); - File config = new File(T2CodeBMain.getPlugin().getDataFolder(), "config.yml"); - if (!T2CodeBMain.getPlugin().getDataFolder().exists()) T2CodeBMain.getPlugin().getDataFolder().mkdir(); - if (!config.exists()) { - config.createNewFile(); + public enum VALUES implements T2CconfigItem{ + updateTimer("UpdateCheck.TimerInMin", 60), + seePreReleaseUpdates("UpdateCheck.SeePreReleaseUpdates", true), + updateCheckFullDisable("Plugin.UpdateCheck.AllPlugins.FullDisable", false), + + apiCommandGUIEnable("API.CommandGUI.Enable", false, "Aktiviere die API für CommandGUI"), + apiAutoResponse("API.AutoResponse.Enable", false), + apiOpSecurity("API.OPSecurity.Enable", false), + + ; + + + private final String key; + private Object value; + private final List comments; + + VALUES(String key, Object value, String... comments) { + this.key = key; + this.value = value; + this.comments = new ArrayList<>(Arrays.asList(comments)); } - Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - T2CBconfig.set("UpdateCheck.TimerInMin", 60, configuration); - T2CBconfig.set("UpdateCheck.SeePreReleaseUpdates", true, configuration); - T2CBconfig.set("Plugin.UpdateCheck.AllPlugins.FullDisable", false, configuration); - T2CBconfig.set("API.CommandGUI.Enable", false, configuration); - T2CBconfig.set("API.AutoResponse.Enable", false, configuration); - T2CBconfig.set("API.OPSecurity.Enable", false, configuration); + @Override + public String getKey() { + return key; + } - ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, config); - T2CBsend.console(Util.getPrefix() + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms"); + @Override + public Object getValue() { + return value; + } + + @Override + public List getComments() { + return comments; + } + + @Override + public void setValue(Object newValue) { + value = newValue; + } } - public static void select() throws IOException { - File config = new File(T2CodeBMain.getPlugin().getDataFolder(), "config.yml"); - Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); + public static void set(){ + T2CBconfigWriter.createConfig(new File(T2CodeBMain.getPlugin().getDataFolder(), "config.yml"), VALUES.values(), Util.getLogo()); - updateTimer = configuration.getInt("UpdateCheck.TimerInMin"); - seePreReleaseUpdates = configuration.getBoolean("UpdateCheck.SeePreReleaseUpdates"); - updateCheckFullDisable = configuration.getBoolean("Plugin.UpdateCheck.AllPlugins.FullDisable"); - - apiCommandGUIEnable = configuration.getBoolean("API.CommandGUI.Enable"); - apiAutoResponse = configuration.getBoolean("API.AutoResponse.Enable"); - apiOpSecurity = configuration.getBoolean("API.OPSecurity.Enable"); } - @Getter - private static Integer updateTimer; - @Getter - private static Boolean seePreReleaseUpdates; - @Getter - private static Boolean updateCheckFullDisable; - @Getter - private static Boolean apiCommandGUIEnable; - @Getter - private static Boolean apiAutoResponse; - @Getter - private static Boolean apiOpSecurity; - } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/yaml/T2CconfigEnumManager.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/yaml/T2CconfigEnumManager.java new file mode 100644 index 0000000..d3faea0 --- /dev/null +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/yaml/T2CconfigEnumManager.java @@ -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 additionalEnums = new ArrayList<>(); + + public static class AdditionalEnum implements T2CconfigItem { + private final String key; + private String path; + private Object value; + private List 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 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 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; + } +} diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/yaml/T2CconfigWriter.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/yaml/T2CconfigWriter.java new file mode 100644 index 0000000..134ade9 --- /dev/null +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/yaml/T2CconfigWriter.java @@ -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> 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> 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> 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 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"); + } + } + } +} diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java index 780af59..3a5a22d 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java @@ -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(); diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigCreate.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigCreate.java index 7db005a..375d37e 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigCreate.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigCreate.java @@ -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 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 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"); } } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigKey.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigKey.java new file mode 100644 index 0000000..43f4c89 --- /dev/null +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigKey.java @@ -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 +} diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java index 91a0a42..3ecd372 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java @@ -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"); + } } diff --git a/src/main/java/net/t2code/t2codelib/T2CconfigItem.java b/src/main/java/net/t2code/t2codelib/T2CconfigItem.java new file mode 100644 index 0000000..cf0b8a6 --- /dev/null +++ b/src/main/java/net/t2code/t2codelib/T2CconfigItem.java @@ -0,0 +1,11 @@ +package net.t2code.t2codelib; + + +import java.util.List; + +public interface T2CconfigItem { + String getKey(); + Object getValue(); + List getComments(); + void setValue(Object newValue); +} diff --git a/src/main/java/net/t2code/t2codelib/Util.java b/src/main/java/net/t2code/t2codelib/Util.java index a802956..9ce2de7 100644 --- a/src/main/java/net/t2code/t2codelib/Util.java +++ b/src/main/java/net/t2code/t2codelib/Util.java @@ -14,7 +14,7 @@ public class Util { public static String getInfoText() { - return "Description: "+T2CodeLibMain.getPlugin().getDescription().getDescription()+"" ; + return "Description: " + T2CodeLibMain.getPlugin().getDescription().getDescription() + ""; } public static String getPrefix() { @@ -59,4 +59,22 @@ public class Util { "T2C-LoginPermissionAuth" ); } + + @Getter + private static final String[] logo = new String[]{ + "####################################################################################################################", + "## ##", + "## /$$$$$$$$ /$$$$$$ /$$$$$$ /$$ /$$ ##", + "## |__ $$__//$$__ $$ /$$__ $$ | $$ | $$ ##", + "## | $$ |__/ \\ $$| $$ \\__/ /$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$ ##", + "## | $$ /$$$$$$/| $$ /$$__ $$ /$$__ $$ /$$__ $$ | $$__ $$ /$$__ $$|_ $$_/ ##", + "## | $$ /$$____/ | $$ | $$ \\ $$| $$ | $$| $$$$$$$$ | $$ \\ $$| $$$$$$$$ | $$ ##", + "## | $$ | $$ | $$ $$| $$ | $$| $$ | $$| $$_____/ | $$ | $$| $$_____/ | $$ /$$ ##", + "## | $$ | $$$$$$$$| $$$$$$/| $$$$$$/| $$$$$$$| $$$$$$$ /$$| $$ | $$| $$$$$$$ | $$$$/ ##", + "## |__/ |________/ \\______/ \\______/ \\_______/ \\_______/|__/|__/ |__/ \\_______/ \\___/ ##", + "## ##", + "## T2CodeLib from JaTiTV / T2Code.net. In case of problems please contact the Discord: https://dc.t2code.net ##", + "## ##", + "####################################################################################################################" + }; }