remove EnumManager
This commit is contained in:
@@ -38,7 +38,7 @@ public class T2CbungeePlayers implements PluginMessageListener {
|
||||
bungeePlayers.remove(input);
|
||||
break;
|
||||
case GIVEALL:
|
||||
if (!T2CLibConfig.manager.getValues(T2CLibConfig.key.serverUUID).getValue().equals(uuid)) {
|
||||
if (!T2CLibConfig.VALUES.serverUUID.getValue().equals(uuid)) {
|
||||
return;
|
||||
}
|
||||
bungeePlayers.clear();
|
||||
@@ -68,7 +68,7 @@ public class T2CbungeePlayers implements PluginMessageListener {
|
||||
DataOutputStream output = new DataOutputStream(stream);
|
||||
try {
|
||||
output.writeUTF(T2CbungeePlayersEnum.GIVEALL.name());
|
||||
output.writeUTF(T2CLibConfig.manager.getValues(T2CLibConfig.key.serverUUID).getValue().toString());
|
||||
output.writeUTF(T2CLibConfig.VALUES.serverUUID.getValue().toString());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class T2CbungeePlayers implements PluginMessageListener {
|
||||
player.sendPluginMessage(T2CodeLibMain.getPlugin(), "t2c:bonlp", stream.toByteArray());
|
||||
T2Csend.debug(T2CodeLibMain.getPlugin(), "PluginMessage received channel: t2c:bonlp");
|
||||
T2Csend.debug(T2CodeLibMain.getPlugin(), "PluginMessage send subChannel: " + T2CbungeePlayersEnum.GIVEALL.name());
|
||||
T2Csend.debug(T2CodeLibMain.getPlugin(), "PluginMessage send output/uuid: " + T2CLibConfig.manager.getValues(T2CLibConfig.key.serverUUID).getValue().toString());
|
||||
T2Csend.debug(T2CodeLibMain.getPlugin(), "PluginMessage send output/uuid: " + T2CLibConfig.VALUES.serverUUID.getValue().toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -186,7 +186,7 @@ public class T2CupdateAPI {
|
||||
}
|
||||
|
||||
public static void onUpdateCheck(Plugin plugin, String prefix, String gitKey, Integer spigotID, String discord, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
|
||||
if ((boolean) T2CLibConfig.manager.getValues(T2CLibConfig.key.updateCheckFullDisable).getValue()) return;
|
||||
if ((boolean) T2CLibConfig.VALUES.updateCheckFullDisable.getValue()) return;
|
||||
new T2CupdateCheckerGit((JavaPlugin) plugin, prefix, gitKey, spigotID, discord, updateCheckOnJoin, seePreReleaseUpdates, timeInterval);
|
||||
}
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ public class T2CupdateCheckerGit {
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if ((boolean) T2CLibConfig.manager.getValues(T2CLibConfig.key.updateCheckFullDisable).getValue()) return;
|
||||
if ((boolean) T2CLibConfig.VALUES.updateCheckFullDisable.getValue()) return;
|
||||
getVersion((webData) -> {
|
||||
T2CupdateObject update = new T2CupdateObject(
|
||||
plugin.getName(),
|
||||
|
@@ -7,7 +7,7 @@ public class T2CLibConfig {
|
||||
*/
|
||||
@Deprecated(since = "16.7", forRemoval = true)
|
||||
public static Boolean getUpdateCheckOnJoin() {
|
||||
return (boolean) net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.manager.getValues(net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.key.updateCheckOnJoin).getValue();
|
||||
return (boolean) net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.VALUES.updateCheckOnJoin.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -15,7 +15,7 @@ public class T2CLibConfig {
|
||||
*/
|
||||
@Deprecated(since = "16.7", forRemoval = true)
|
||||
public static Integer getUpdateCheckTimeInterval() {
|
||||
return (Integer) net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.manager.getValues(net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.key.updateCheckTimeInterval).getValue();
|
||||
return (Integer) net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.VALUES.updateCheckTimeInterval.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,7 +23,7 @@ public class T2CLibConfig {
|
||||
*/
|
||||
@Deprecated(since = "16.7", forRemoval = true)
|
||||
public static Boolean getSeePreReleaseUpdates() {
|
||||
return (boolean) net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.manager.getValues(net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.key.seePreReleaseUpdates).getValue();
|
||||
return (boolean) net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.VALUES.seePreReleaseUpdates.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,7 +31,7 @@ public class T2CLibConfig {
|
||||
*/
|
||||
@Deprecated(since = "16.7", forRemoval = true)
|
||||
public static Boolean getDebug() {
|
||||
return (boolean) net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.manager.getValues(net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.key.debug).getValue();
|
||||
return (boolean) net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.VALUES.debug.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +39,7 @@ public class T2CLibConfig {
|
||||
*/
|
||||
@Deprecated(since = "16.7", forRemoval = true)
|
||||
public static String getLanguage() {
|
||||
return (String) net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.manager.getValues(net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.key.language).getValue();
|
||||
return (String) net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.VALUES.language.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +47,7 @@ public class T2CLibConfig {
|
||||
*/
|
||||
@Deprecated(since = "16.7", forRemoval = true)
|
||||
public static Boolean getBungee() {
|
||||
return (boolean) net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.manager.getValues(net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.key.proxy).getValue();
|
||||
return (boolean) net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.VALUES.proxy.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,6 +55,6 @@ public class T2CLibConfig {
|
||||
*/
|
||||
@Deprecated(since = "16.7", forRemoval = true)
|
||||
public static Boolean getInventoriesCloseByServerStop() {
|
||||
return (boolean) net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.manager.getValues(net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.key.inventoriesCloseByServerStop).getValue();
|
||||
return (boolean) net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig.VALUES.inventoriesCloseByServerStop.getValue();
|
||||
}
|
||||
}
|
||||
|
@@ -1,65 +0,0 @@
|
||||
// This class was created by JaTiTV.
|
||||
|
||||
package net.t2code.t2codelib.SPIGOT.api.yaml;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class T2CconfigEnumManager {
|
||||
|
||||
private final List<AdditionalEnum> additionalEnums = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
public static class AdditionalEnum {
|
||||
private final String key;
|
||||
private String path;
|
||||
@Setter
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
// Method to add or change an "enum" value
|
||||
public void set(@NotNull Object key, @NotNull 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 getValues(Object key) {
|
||||
for (AdditionalEnum e : additionalEnums) {
|
||||
if (e.key.equals(key.toString())) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
|
||||
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;
|
||||
@@ -18,7 +19,7 @@ public class T2CconfigWriter {
|
||||
private static FileConfiguration config;
|
||||
|
||||
|
||||
public static void createConfig(File configFile, T2CconfigEnumManager manager, String... header) {
|
||||
public static void createConfig(File configFile, T2CconfigItem[] values, String... header) {
|
||||
if (!configFile.exists()) {
|
||||
configFile.getParentFile().mkdirs();
|
||||
try {
|
||||
@@ -32,7 +33,7 @@ public class T2CconfigWriter {
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
Map<String, List<String>> comments = new LinkedHashMap<>();
|
||||
|
||||
for(T2CconfigEnumManager.AdditionalEnum value : manager.getAllEnums()){
|
||||
for(T2CconfigItem value : values){
|
||||
config.addDefault(value.getPath(), value.getValue());
|
||||
comments.put(value.getPath(), value.getComments());
|
||||
}
|
||||
@@ -40,11 +41,11 @@ public class T2CconfigWriter {
|
||||
// Copy default values if they are missing
|
||||
config.options().copyDefaults(true);
|
||||
saveConfigWithComments(configFile, comments, header);
|
||||
readConfig(config,manager);
|
||||
readConfig(config,values);
|
||||
}
|
||||
|
||||
private static void readConfig(FileConfiguration config, T2CconfigEnumManager manager) {
|
||||
for(T2CconfigEnumManager.AdditionalEnum value : manager.getAllEnums()){
|
||||
private static void readConfig(FileConfiguration config, T2CconfigItem[] values) {
|
||||
for(T2CconfigItem value : values){
|
||||
value.setValue(config.get(value.getPath()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user