remove EnumManager

This commit is contained in:
2024-07-01 15:01:08 +02:00
parent 9413f0f7c8
commit bbe8fbce49
16 changed files with 131 additions and 184 deletions

View File

@@ -28,7 +28,7 @@ public class T2CbungeeCommandSenderReciver {
}
}
output.writeUTF(information);
output.writeUTF(String.valueOf(T2CLibConfig.manager.getValues(T2CLibConfig.key.serverUUID).getValue()));
output.writeUTF(String.valueOf(T2CLibConfig.VALUES.serverUUID.getValue()));
} catch (IOException e) {
e.printStackTrace();
}

View File

@@ -135,19 +135,19 @@ public final class T2CodeLibMain extends JavaPlugin {
plugin.getCommand("t2code").setExecutor(new CmdExecuter());
T2CLibConfig.set();
T2Ctemplate.onLoadSeparateStroke(prefix);
T2Ctemplate.onStartMsg(prefix, "§3Use Proxy: §6" + (boolean)T2CLibConfig.manager.getValues(T2CLibConfig.key.proxy).getValue());
T2Ctemplate.onStartMsg(prefix, "§3serverUUID: §6" + T2CLibConfig.manager.getValues(T2CLibConfig.key.serverUUID).getValue());
T2Ctemplate.onStartMsg(prefix, "§3Use Proxy: §6" + (boolean)T2CLibConfig.VALUES.proxy.getValue());
T2Ctemplate.onStartMsg(prefix, "§3serverUUID: §6" + T2CLibConfig.VALUES.serverUUID.getValue());
T2Ctemplate.onLoadSeparateStroke(prefix);
T2CitemVersion.scan();
LanguagesCreate.langCreate();
SelectLibMsg.onSelect();
T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getGit(), Util.getSpigotID(), Util.getDiscord(),
(boolean) T2CLibConfig.manager.getValues(T2CLibConfig.key.updateCheckOnJoin).getValue(),
(boolean) T2CLibConfig.manager.getValues(T2CLibConfig.key.seePreReleaseUpdates).getValue(),
(int) T2CLibConfig.manager.getValues(T2CLibConfig.key.updateCheckTimeInterval).getValue());
(boolean) T2CLibConfig.VALUES.updateCheckOnJoin.getValue(),
(boolean) T2CLibConfig.VALUES.seePreReleaseUpdates.getValue(),
(int) T2CLibConfig.VALUES.updateCheckTimeInterval.getValue());
Metrics.Bstats(plugin, Util.getBstatsID());
if ((boolean) T2CLibConfig.manager.getValues(T2CLibConfig.key.proxy).getValue()) {
if ((boolean) T2CLibConfig.VALUES.proxy.getValue()) {
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bcmd");
T2Csend.debug(plugin, "registerIncomingPluginChannel §et2c:bcmd");
@@ -171,7 +171,7 @@ public final class T2CodeLibMain extends JavaPlugin {
// Plugin shutdown logic
if (!load) return;
ReportLogStorage.save();
if ((boolean) T2CLibConfig.manager.getValues(T2CLibConfig.key.inventoriesCloseByServerStop).getValue()) {
if ((boolean) T2CLibConfig.VALUES.inventoriesCloseByServerStop.getValue()) {
for (Player player : Bukkit.getOnlinePlayers()) {
player.closeInventory();
}

View File

@@ -31,7 +31,7 @@ public class Metrics {
public static void Bstats(Plugin plugin, int bstatsID) {
int pluginId = bstatsID; // <-- Replace with the id of your plugin!
Metrics metrics = new Metrics((JavaPlugin) plugin, pluginId);
metrics.addCustomChart(new SimplePie("updatecheckonjoin", () -> String.valueOf(T2CLibConfig.manager.getValues(T2CLibConfig.key.updateCheckOnJoin).getValue())));
metrics.addCustomChart(new SimplePie("updatecheckonjoin", () -> String.valueOf(T2CLibConfig.VALUES.updateCheckOnJoin.getValue())));
}
private final Plugin plugin;

View File

@@ -92,7 +92,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
return false;
}
T2Csend.sender(sender, ("[prefix] <red>T2C ServerID:</red> <gold><hover:show_text:'<yellow>copy</yellow>'>" +
"<click:copy_to_clipboard:[id]>[id]</click></hover></gold>").replace("[prefix]", Util.getPrefix()).replace("[id]", String.valueOf(T2CLibConfig.manager.getValues(T2CLibConfig.key.serverUUID).getValue())));
"<click:copy_to_clipboard:[id]>[id]</click></hover></gold>").replace("[prefix]", Util.getPrefix()).replace("[id]", String.valueOf(T2CLibConfig.VALUES.serverUUID.getValue())));
return false;
case "bcmd":
if (!sender.hasPermission("t2code.admin")) {

View File

@@ -93,10 +93,10 @@ public class Commands {
String permission = args[2];
if (player.hasPermission(permission)) {
T2Ccmd.console(String.valueOf(T2CLibConfig.manager.getValues(T2CLibConfig.key.commandPermToggleCommand).getValue()).replace("[player]",player.getName()).replace("[perm]",permission).replace("[value]", "false"));
T2Ccmd.console(String.valueOf(T2CLibConfig.VALUES.commandPermToggleCommand.getValue()).replace("[player]",player.getName()).replace("[perm]",permission).replace("[value]", "false"));
T2Csend.sender(sender, "§2Permission §8'§6" + permission + "§8' §2was set to §6false §2for the player §6" + player.getName() + "§2.");
} else {
T2Ccmd.console(String.valueOf(T2CLibConfig.manager.getValues(T2CLibConfig.key.commandPermToggleCommand).getValue()).replace("[player]",player.getName()).replace("[perm]",permission).replace("[value]", "true"));
T2Ccmd.console(String.valueOf(T2CLibConfig.VALUES.commandPermToggleCommand.getValue()).replace("[player]",player.getName()).replace("[perm]",permission).replace("[value]", "true"));
T2Csend.sender(sender, "§2Permission §8'§6" + permission + "§8' §2was set to §6true §2for the player §6" + player.getName() + "§2.");
}

View File

@@ -27,7 +27,7 @@ public class Development implements Listener {
if (!args[0].equals("_t2code_")) {
return;
}
if (!(boolean) T2CLibConfig.manager.getValues(T2CLibConfig.key.developerTool).getValue()) {
if (!(boolean) T2CLibConfig.VALUES.developerTool.getValue()) {
T2Csend.player(e.getPlayer(), Util.getPrefix() + " The Development Tool is disabled.");
}
e.setCancelled(true);

View File

@@ -1,53 +1,40 @@
package net.t2code.t2codelib.SPIGOT.system.config.config;
import net.t2code.t2codelib.SPIGOT.api.yaml.T2CconfigEnumManager;
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
import net.t2code.t2codelib.T2CconfigItem;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
public class ConvertT2ClibConfig {
public static final T2CconfigEnumManager manager = T2CLibConfig.manager;
public static YamlConfiguration yamlConfiguration;
public static void convert() {
File config = new File(T2CodeLibMain.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
yamlConfiguration = YamlConfiguration.loadConfiguration(config);
if (!config.exists()) return;
if (yamlConfiguration.contains("plugin.updateCheck.onJoin")) return;
if (yamlConfiguration.contains("Plugin.UpdateCheck.OnJoin")){
manager.getValues(T2CLibConfig.key.updateCheckOnJoin).setValue(yamlConfiguration.get("Plugin.UpdateCheck.OnJoin"));
}
if (yamlConfiguration.contains("Plugin.UpdateCheck.TimeInterval")){
manager.getValues(T2CLibConfig.key.updateCheckTimeInterval).setValue(yamlConfiguration.get("Plugin.UpdateCheck.TimeInterval"));
}
if (yamlConfiguration.contains("Plugin.UpdateCheck.SeePreReleaseUpdates")){
manager.getValues(T2CLibConfig.key.seePreReleaseUpdates).setValue(yamlConfiguration.get("Plugin.UpdateCheck.SeePreReleaseUpdates"));
}
if (yamlConfiguration.contains("Plugin.UpdateCheck.AllPlugins.FullDisable")){
manager.getValues(T2CLibConfig.key.updateCheckFullDisable).setValue(yamlConfiguration.get("Plugin.UpdateCheck.AllPlugins.FullDisable"));
}
if (yamlConfiguration.contains("Plugin.Debug")){
manager.getValues(T2CLibConfig.key.debug).setValue(yamlConfiguration.get("Plugin.Debug"));
}
if (yamlConfiguration.contains("Plugin.language")){
manager.getValues(T2CLibConfig.key.language).setValue(yamlConfiguration.get("Plugin.language"));
}
if (yamlConfiguration.contains("Plugin.Not recommended to disable.developerTool")){
manager.getValues(T2CLibConfig.key.developerTool).setValue(yamlConfiguration.get("Plugin.Not recommended to disable.developerTool"));
}
if (yamlConfiguration.contains("BungeeCord.Enable")){
manager.getValues(T2CLibConfig.key.proxy).setValue(yamlConfiguration.get("BungeeCord.Enable"));
}
if (yamlConfiguration.contains("Player.Inventories.CloseByServerStop")){
manager.getValues(T2CLibConfig.key.inventoriesCloseByServerStop).setValue(yamlConfiguration.get("Player.Inventories.CloseByServerStop"));
}
if (yamlConfiguration.contains("Command.PermToggle.PermissionSetCommand")){
manager.getValues(T2CLibConfig.key.commandPermToggleCommand).setValue(yamlConfiguration.get("Command.PermToggle.PermissionSetCommand"));
}
set("Plugin.UpdateCheck.OnJoin",T2CLibConfig.VALUES.updateCheckOnJoin);
set("Plugin.UpdateCheck.TimeInterval",T2CLibConfig.VALUES.updateCheckTimeInterval);
set("Plugin.UpdateCheck.SeePreReleaseUpdates",T2CLibConfig.VALUES.seePreReleaseUpdates);
set("Plugin.UpdateCheck.AllPlugins.FullDisable",T2CLibConfig.VALUES.updateCheckFullDisable);
set("Plugin.Debug",T2CLibConfig.VALUES.debug);
set("Plugin.language",T2CLibConfig.VALUES.language);
set("Plugin.Not recommended to disable.developerTool",T2CLibConfig.VALUES.developerTool);
set("BungeeCord.Enable",T2CLibConfig.VALUES.proxy);
set("Player.Inventories.CloseByServerStop",T2CLibConfig.VALUES.inventoriesCloseByServerStop);
set("Command.PermToggle.PermissionSetCommand",T2CLibConfig.VALUES.updateCheckOnJoin);
config.delete();
}
private static void set(String path, T2CconfigItem item){
if (yamlConfiguration.contains(path)){
item.setValue(yamlConfiguration.get(path));
}
}
}

View File

@@ -1,71 +1,90 @@
package net.t2code.t2codelib.SPIGOT.system.config.config;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
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 java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class T2CLibConfig {
public static final T2CconfigEnumManager manager = new T2CconfigEnumManager();
public static enum VALUES implements T2CconfigItem {
public enum key {
updateCheckOnJoin,
updateCheckTimeInterval,
seePreReleaseUpdates,
updateCheckFullDisable,
debug,
developerTool,
language,
proxy,
serverUUID,
inventoriesCloseByServerStop,
commandPermToggleCommand
updateCheckOnJoin("plugin.updateCheck.onJoin", true, "In this option you can set if players with the permission 't2code.lib.updatemsg' will get an update message on join when an update for the plugin is available."),
updateCheckTimeInterval("plugin.updateCheck.timeInterval", 60, "In this option you can set the time interval in minutes in which updates should be checked."),
seePreReleaseUpdates("plugin.updateCheck.seePreReleaseUpdates", true, "In this option you can set whether you want to receive and display beta and snapshot versions in the update check."),
updateCheckFullDisable("plugin.updateCheck.allPlugins.fullDisable", false, "This option deactivates all update checks for plugins that use the T2CodeLib."),
debug("plugin.debug.debugModus", false, "The debug mode sends more detailed debug information to the console.", "In this version of the plugin no debug messages are built in!"),
developerTool("plugin.debug.developerTool", false, "This option activates advanced tools for the developers of plugins that use the T2CodeLib.", "If you don't know exactly what this is for, you should leave it deactivated!"),
language("plugin.language", "english", "In this option you can set the language of the plugin."),
space_proxy("proxy", null, ""),
proxy("proxy.enable", T2CodeLibMain.getIsBungee(), "This option must be activated if you use the T2CodeLib on a BungeeCord, Waterfall or Velocity Proxy as a bridge."
, "Please note that the individual APIs of the plugins that use a bridge on a proxy must be activated in the config.yml of the T2CodeLib on the proxy!"),
serverUUID("proxy.serverUUID", UUID.randomUUID(), "This UUID is used for the communication of the plugins in a network with several servers.", "This UUID may only occur once in a network!"),
space_player("player", null, ""),
inventoriesCloseByServerStop("player.inventories.closeByServerStop", true, "If this option is enabled, all players on the server (spigot, paper, etc.) will have their inventory / GUIs closed when the server is shut down or restarted.",
"This does not mean the entire network if a proxy is used),", "the inventory / GUIs are closed if players have them open when the server is shut down or restarted."),
space_command("command", null, ""),
commandPermToggleCommand("command.permToggle.permissionSetCommand", "lp user [player] permission set [perm] [value]",
"This option specifies which command is to be used for the T2CodeLib command '/t2code permtoggle <player> <permission>'."),
;
private final String path;
private Object value;
private final List<String> comments;
VALUES(String path, Object value, String... comments) {
this.path = path;
this.value = value;
this.comments = new ArrayList<>(Arrays.asList(comments));
}
@Override
public String getPath() {
return path;
}
@Override
public Object getValue() {
return value;
}
@Override
public List<String> getComments() {
return comments;
}
@Override
public void setValue(Object newValue) {
value = newValue;
}
}
public static void set() {
long long_ = System.currentTimeMillis();
setEnum();
ConvertT2ClibConfig.convert();
T2CconfigWriter.createConfig(new File(T2CodeLibMain.getPath(), "config.yml"), manager, Util.getConfigLogo());
T2CconfigWriter.createConfig(new File(T2CodeLibMain.getPath(), "config.yml"), VALUES.values(), Util.getConfigLogo());
T2Ctemplate.onStartMsg(Util.getPrefix(), "§2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
}
private static void setEnum() {
manager.set(key.updateCheckOnJoin, "plugin.updateCheck.onJoin", true, "In this option you can set if players with the permission 't2code.lib.updatemsg' will get an update message on join when an update for the plugin is available.");
manager.set(key.updateCheckTimeInterval, "plugin.updateCheck.timeInterval", 60, "In this option you can set the time interval in minutes in which updates should be checked.");
manager.set(key.seePreReleaseUpdates, "plugin.updateCheck.seePreReleaseUpdates", true, "In this option you can set whether you want to receive and display beta and snapshot versions in the update check.");
manager.set(key.updateCheckFullDisable, "plugin.updateCheck.allPlugins.fullDisable", false, "This option deactivates all update checks for plugins that use the T2CodeLib.");
manager.set(key.debug, "plugin.debug.debugModus", false, "The debug mode sends more detailed debug information to the console.", "In this version of the plugin no debug messages are built in!");
manager.set(key.developerTool, "plugin.debug.developerTool", false, "This option activates advanced tools for the developers of plugins that use the T2CodeLib.", "If you don't know exactly what this is for, you should leave it deactivated!");
manager.set(key.language, "plugin.language", "english", "In this option you can set the language of the plugin.");
manager.set("space-proxy", "proxy", null, "");
manager.set(key.proxy, "proxy.enable", T2CodeLibMain.getIsBungee(), "This option must be activated if you use the T2CodeLib on a BungeeCord, Waterfall or Velocity Proxy as a bridge."
, "Please note that the individual APIs of the plugins that use a bridge on a proxy must be activated in the config.yml of the T2CodeLib on the proxy!");
manager.set(key.serverUUID, "proxy.serverUUID", UUID.randomUUID(), "This UUID is used for the communication of the plugins in a network with several servers.", "This UUID may only occur once in a network!");
manager.set("space-player", "player", null, "");
manager.set(key.inventoriesCloseByServerStop, "player.inventories.closeByServerStop", true, "If this option is enabled, all players on the server (spigot, paper, etc.) will have their inventory / GUIs closed when the server is shut down or restarted.", "This does not mean the entire network if a proxy is used),", "the inventory / GUIs are closed if players have them open when the server is shut down or restarted.");
manager.set("space-command", "command", null, "");
manager.set(key.commandPermToggleCommand, "command.permToggle.permissionSetCommand", "lp user [player] permission set [perm] [value]",
"This option specifies which command is to be used for the T2CodeLib command '/t2code permtoggle <player> <permission>'.");
}
}

View File

@@ -28,17 +28,17 @@ public class SelectLibMsg {
File msg;
msg = new File(T2CodeLibMain.getPath(), "languages/" + T2CLibConfig.manager.getValues(T2CLibConfig.key.language).getValue() + ".yml");
msg = new File(T2CodeLibMain.getPath(), "languages/" + T2CLibConfig.VALUES.language.getValue() + ".yml");
if (!msg.isFile()) {
T2Ctemplate.onStartMsg(Util.getPrefix(),"");
T2Ctemplate.onStartMsg(Util.getPrefix(), "§4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
T2Ctemplate.onStartMsg(Util.getPrefix(), "§4The selected §c" + T2CLibConfig.manager.getValues(T2CLibConfig.key.language).getValue() + " §4language file was not found.");
T2Ctemplate.onStartMsg(Util.getPrefix(), "§4The selected §c" + T2CLibConfig.VALUES.language.getValue() + " §4language file was not found.");
T2Ctemplate.onStartMsg(Util.getPrefix(), "§6The default language §eEnglish §6is used!");
T2Ctemplate.onStartMsg(Util.getPrefix(), "§4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
T2Ctemplate.onStartMsg(Util.getPrefix(),"");
msg = new File(T2CodeLibMain.getPath(), "languages/" + "english.yml");
selectMSG = "english";
} else selectMSG = (String) T2CLibConfig.manager.getValues(T2CLibConfig.key.language).getValue();
} else selectMSG = (String) T2CLibConfig.VALUES.language.getValue();
YamlConfiguration yamlConfiguration_msg = YamlConfiguration.loadConfiguration(msg);
vaultNotSetUp = T2Creplace.replace(prefix, yamlConfiguration_msg.getString("Plugin.VaultNotSetUp"));