small code changes

This commit is contained in:
JaTiTV 2024-07-02 06:11:10 +02:00
parent 90f899cb16
commit d8f0752ea7
6 changed files with 145 additions and 33 deletions

View File

@ -27,8 +27,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<configuration> <configuration>
<source>9</source> <source>11</source>
<target>9</target> <target>11</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -3,7 +3,7 @@ package net.t2code.t2codelib.SPIGOT.api.yaml;
public class T2CLibConfig { public class T2CLibConfig {
/** /**
* @deprecated since version 16.7, use the manager directly instead as with the return. * @deprecated since version 16.7, use the method from the return!
*/ */
@Deprecated(since = "16.7", forRemoval = true) @Deprecated(since = "16.7", forRemoval = true)
public static Boolean getUpdateCheckOnJoin() { public static Boolean getUpdateCheckOnJoin() {
@ -11,7 +11,7 @@ public class T2CLibConfig {
} }
/** /**
* @deprecated since version 16.7, use the manager directly instead as with the return. * @deprecated since version 16.7, use the method from the return!
*/ */
@Deprecated(since = "16.7", forRemoval = true) @Deprecated(since = "16.7", forRemoval = true)
public static Integer getUpdateCheckTimeInterval() { public static Integer getUpdateCheckTimeInterval() {
@ -19,7 +19,7 @@ public class T2CLibConfig {
} }
/** /**
* @deprecated since version 16.7, use the manager directly instead as with the return. * @deprecated since version 16.7, use the method from the return!
*/ */
@Deprecated(since = "16.7", forRemoval = true) @Deprecated(since = "16.7", forRemoval = true)
public static Boolean getSeePreReleaseUpdates() { public static Boolean getSeePreReleaseUpdates() {
@ -27,7 +27,7 @@ public class T2CLibConfig {
} }
/** /**
* @deprecated since version 16.7, use the manager directly instead as with the return. * @deprecated since version 16.7, use the method from the return!
*/ */
@Deprecated(since = "16.7", forRemoval = true) @Deprecated(since = "16.7", forRemoval = true)
public static Boolean getDebug() { public static Boolean getDebug() {
@ -35,7 +35,7 @@ public class T2CLibConfig {
} }
/** /**
* @deprecated since version 16.7, use the manager directly instead as with the return. * @deprecated since version 16.7, use the method from the return!
*/ */
@Deprecated(since = "16.7", forRemoval = true) @Deprecated(since = "16.7", forRemoval = true)
public static String getLanguage() { public static String getLanguage() {
@ -43,7 +43,7 @@ public class T2CLibConfig {
} }
/** /**
* @deprecated since version 16.7, use the manager directly instead as with the return. * @deprecated since version 16.7, use the method from the return!
*/ */
@Deprecated(since = "16.7", forRemoval = true) @Deprecated(since = "16.7", forRemoval = true)
public static Boolean getBungee() { public static Boolean getBungee() {
@ -51,7 +51,7 @@ public class T2CLibConfig {
} }
/** /**
* @deprecated since version 16.7, use the manager directly instead as with the return. * @deprecated since version 16.7, use the method from the return!
*/ */
@Deprecated(since = "16.7", forRemoval = true) @Deprecated(since = "16.7", forRemoval = true)
public static Boolean getInventoriesCloseByServerStop() { public static Boolean getInventoriesCloseByServerStop() {

View File

@ -12,51 +12,80 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class T2Cconfig { public class T2Cconfig {
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static void set(String path, String value, YamlConfiguration YamlConfiguration) { public static void set(String path, String value, YamlConfiguration YamlConfiguration) {
if (!YamlConfiguration.contains(path)) { if (!YamlConfiguration.contains(path)) {
YamlConfiguration.set(path, value); YamlConfiguration.set(path, value);
} }
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static void set(String path, Object value, YamlConfiguration YamlConfiguration) { public static void set(String path, Object value, YamlConfiguration YamlConfiguration) {
if (!YamlConfiguration.contains(path)) { if (!YamlConfiguration.contains(path)) {
YamlConfiguration.set(path, value); YamlConfiguration.set(path, value);
} }
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static void set(String path, YamlConfiguration YamlConfiguration) { public static void set(String path, YamlConfiguration YamlConfiguration) {
YamlConfiguration.set(path, null); YamlConfiguration.set(path, null);
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static void set(String path, Integer value, YamlConfiguration YamlConfiguration) { public static void set(String path, Integer value, YamlConfiguration YamlConfiguration) {
if (!YamlConfiguration.contains(path)) { if (!YamlConfiguration.contains(path)) {
YamlConfiguration.set(path, value); YamlConfiguration.set(path, value);
} }
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static void set(String path, Double value, YamlConfiguration YamlConfiguration) { public static void set(String path, Double value, YamlConfiguration YamlConfiguration) {
if (!YamlConfiguration.contains(path)) { if (!YamlConfiguration.contains(path)) {
YamlConfiguration.set(path, value); YamlConfiguration.set(path, value);
} }
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static void set(String path, Boolean value, YamlConfiguration YamlConfiguration) { public static void set(String path, Boolean value, YamlConfiguration YamlConfiguration) {
if (!YamlConfiguration.contains(path)) { if (!YamlConfiguration.contains(path)) {
YamlConfiguration.set(path, value); YamlConfiguration.set(path, value);
} }
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static void set(String path, List<String> value, YamlConfiguration YamlConfiguration) { public static void set(String path, List<String> value, YamlConfiguration YamlConfiguration) {
if (!YamlConfiguration.contains(path)) { if (!YamlConfiguration.contains(path)) {
YamlConfiguration.set(path, value); YamlConfiguration.set(path, value);
} }
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static void set(String path, ItemStack value, YamlConfiguration YamlConfiguration) { public static void set(String path, ItemStack value, YamlConfiguration YamlConfiguration) {
if (!YamlConfiguration.contains(path)) { if (!YamlConfiguration.contains(path)) {
YamlConfiguration.set(path, value); YamlConfiguration.set(path, value);
} }
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static void setSound(String soundName, String sound1_8, String sound1_9, String sound1_13, YamlConfiguration yamlConfiguration) { public static void setSound(String soundName, String sound1_8, String sound1_9, String sound1_13, YamlConfiguration yamlConfiguration) {
set("Sound." + soundName + ".Enable", true, yamlConfiguration); set("Sound." + soundName + ".Enable", true, yamlConfiguration);
String sound; String sound;
@ -68,6 +97,9 @@ public class T2Cconfig {
set("Sound." + soundName + ".Sound", sound, yamlConfiguration); set("Sound." + soundName + ".Sound", sound, yamlConfiguration);
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static void setSound(String soundName, String sound1_8, String sound1_13, YamlConfiguration yamlConfiguration) { public static void setSound(String soundName, String sound1_8, String sound1_13, YamlConfiguration yamlConfiguration) {
set("Sound." + soundName + ".Enable", true, yamlConfiguration); set("Sound." + soundName + ".Enable", true, yamlConfiguration);
String sound; String sound;
@ -77,19 +109,31 @@ public class T2Cconfig {
set("Sound." + soundName + ".Sound", sound, yamlConfiguration); set("Sound." + soundName + ".Sound", sound, yamlConfiguration);
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static void setSound(String soundName, String sound, YamlConfiguration yamlConfiguration) { public static void setSound(String soundName, String sound, YamlConfiguration yamlConfiguration) {
set("Sound." + soundName + ".Enable", true, yamlConfiguration); set("Sound." + soundName + ".Enable", true, yamlConfiguration);
set("Sound." + soundName + ".Sound", sound.toString(), yamlConfiguration); set("Sound." + soundName + ".Sound", sound.toString(), yamlConfiguration);
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static boolean selectSoundEnable(String soundName, YamlConfiguration yamlConfiguration) { public static boolean selectSoundEnable(String soundName, YamlConfiguration yamlConfiguration) {
return selectBoolean("Sound." + soundName + ".Enable", yamlConfiguration); return selectBoolean("Sound." + soundName + ".Enable", yamlConfiguration);
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static String selectSound(String prefix, String soundName, YamlConfiguration yamlConfiguration) { public static String selectSound(String prefix, String soundName, YamlConfiguration yamlConfiguration) {
return select(prefix, "Sound." + soundName + ".Sound", yamlConfiguration); return select(prefix, "Sound." + soundName + ".Sound", yamlConfiguration);
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static Sound checkSound(String sound1_8, String sound1_9, String sound1_13, String selectSoundFromConfig, String prefix) { public static Sound checkSound(String sound1_8, String sound1_9, String sound1_13, String selectSoundFromConfig, String prefix) {
String SOUND; String SOUND;
if (T2CmcVersion.isMc1_8()) { if (T2CmcVersion.isMc1_8()) {
@ -101,6 +145,9 @@ public class T2Cconfig {
return checkSound(SOUND, selectSoundFromConfig, prefix); return checkSound(SOUND, selectSoundFromConfig, prefix);
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static Sound checkSound(String sound1_8, String sound1_13, String selectSoundFromConfig, String prefix) { public static Sound checkSound(String sound1_8, String sound1_13, String selectSoundFromConfig, String prefix) {
String SOUND; String SOUND;
if (T2CmcVersion.isMc1_8()) { if (T2CmcVersion.isMc1_8()) {
@ -110,6 +157,9 @@ public class T2Cconfig {
return checkSound(SOUND, selectSoundFromConfig, prefix); return checkSound(SOUND, selectSoundFromConfig, prefix);
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static Sound checkSound(String sound, String selectSoundFromConfig, String prefix) { public static Sound checkSound(String sound, String selectSoundFromConfig, String prefix) {
try { try {
return Sound.valueOf(selectSoundFromConfig); return Sound.valueOf(selectSoundFromConfig);
@ -120,34 +170,58 @@ public class T2Cconfig {
} }
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static String select(String prefix, String path, YamlConfiguration yamlConfiguration) { public static String select(String prefix, String path, YamlConfiguration yamlConfiguration) {
return T2Creplace.replace(prefix, yamlConfiguration.getString(path)); return T2Creplace.replace(prefix, yamlConfiguration.getString(path));
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static Object selectObject(String prefix, String path, YamlConfiguration yamlConfiguration) { public static Object selectObject(String prefix, String path, YamlConfiguration yamlConfiguration) {
return T2Creplace.replaceObject(prefix, yamlConfiguration.get(path)); return T2Creplace.replaceObject(prefix, yamlConfiguration.get(path));
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static Integer selectInt(String path, YamlConfiguration yamlConfiguration) { public static Integer selectInt(String path, YamlConfiguration yamlConfiguration) {
return (yamlConfiguration.getInt(path)); return (yamlConfiguration.getInt(path));
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static Boolean selectBoolean(String path, YamlConfiguration yamlConfiguration) { public static Boolean selectBoolean(String path, YamlConfiguration yamlConfiguration) {
return (yamlConfiguration.getBoolean(path)); return (yamlConfiguration.getBoolean(path));
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static Double selectDouble(String path, YamlConfiguration yamlConfiguration) { public static Double selectDouble(String path, YamlConfiguration yamlConfiguration) {
return (yamlConfiguration.getDouble(path)); return (yamlConfiguration.getDouble(path));
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static List<String> selectList(String path, YamlConfiguration yamlConfiguration) { public static List<String> selectList(String path, YamlConfiguration yamlConfiguration) {
return (yamlConfiguration.getStringList(path)); return (yamlConfiguration.getStringList(path));
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static ItemStack selectItemStack(String path, YamlConfiguration yamlConfiguration) { public static ItemStack selectItemStack(String path, YamlConfiguration yamlConfiguration) {
return (yamlConfiguration.getItemStack(path)); return (yamlConfiguration.getItemStack(path));
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static List<String> selectList(String prefix, String path, YamlConfiguration yamlConfiguration) { public static List<String> selectList(String prefix, String path, YamlConfiguration yamlConfiguration) {
List<String> output = new ArrayList<>(); List<String> output = new ArrayList<>();
List<String> input = yamlConfiguration.getStringList(path); List<String> input = yamlConfiguration.getStringList(path);
@ -157,6 +231,9 @@ public class T2Cconfig {
return output; return output;
} }
/**
* @deprecated since version 16.7, please use the new T2CconfigWriter.
*/
public static void select(String prefix, List<String> value, String path, YamlConfiguration yamlConfiguration) { public static void select(String prefix, List<String> value, String path, YamlConfiguration yamlConfiguration) {
List<String> output = new ArrayList<>(); List<String> output = new ArrayList<>();
List<String> input = yamlConfiguration.getStringList(path); List<String> input = yamlConfiguration.getStringList(path);

View File

@ -20,6 +20,7 @@ public class T2CconfigWriter {
public static void createConfig(File configFile, T2CconfigItem[] values, String... header) { public static void createConfig(File configFile, T2CconfigItem[] values, String... header) {
boolean exist = false;
if (!configFile.exists()) { if (!configFile.exists()) {
configFile.getParentFile().mkdirs(); configFile.getParentFile().mkdirs();
try { try {
@ -28,18 +29,21 @@ public class T2CconfigWriter {
e.printStackTrace(); e.printStackTrace();
return; return;
} }
} } else exist = true;
config = YamlConfiguration.loadConfiguration(configFile); config = YamlConfiguration.loadConfiguration(configFile);
Map<String, List<String>> comments = new LinkedHashMap<>(); Map<String, List<String>> comments = new LinkedHashMap<>();
for (T2CconfigItem value : values) { for (T2CconfigItem value : values) {
if ((value.getForceSet() && exist)||!exist && !value.getForceSet()){
config.addDefault(value.getPath(), value.getValue()); config.addDefault(value.getPath(), value.getValue());
comments.put(value.getPath(), value.getComments()); comments.put(value.getPath(), value.getComments());
} }
}
// Copy default values if they are missing // Copy default values if they are missing
config.options().copyDefaults(true); config.options().copyDefaults(true);
saveConfigWithComments(configFile, comments, header); saveConfigWithComments(configFile, comments, header);
readConfig(config, values); readConfig(config, values);
} }

View File

@ -16,45 +16,47 @@ public class T2CLibConfig {
public enum VALUES implements T2CconfigItem { public enum VALUES implements T2CconfigItem {
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."), updateCheckOnJoin("plugin.updateCheck.onJoin", true, 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."), updateCheckTimeInterval("plugin.updateCheck.timeInterval", 60, true,"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."), seePreReleaseUpdates("plugin.updateCheck.seePreReleaseUpdates", true, 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."), updateCheckFullDisable("plugin.updateCheck.allPlugins.fullDisable", false, true,"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!"), debug("plugin.debug.debugModus", false,true, "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!"), developerTool("plugin.debug.developerTool", false, true,"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."), language("plugin.language", "english", true,"In this option you can set the language of the plugin."),
space_proxy("proxy", null, ""), space_proxy("proxy", null, true,""),
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." proxy("proxy.enable", T2CodeLibMain.getIsBungee(), true,"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!"), , "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!"), serverUUID("proxy.serverUUID", UUID.randomUUID(),true, "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, ""), space_player("player", null, true,""),
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.", inventoriesCloseByServerStop("player.inventories.closeByServerStop", true, 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."), "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, ""), space_command("command", null, true,""),
commandPermToggleCommand("command.permToggle.permissionSetCommand", "lp user [player] permission set [perm] [value]", 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>'."), true,"This option specifies which command is to be used for the T2CodeLib command '/t2code permtoggle <player> <permission>'."),
; ;
private final String path; private final String path;
private Object value; private Object value;
private final boolean forceSet;
private final List<String> comments; private final List<String> comments;
VALUES(String path, Object value, String... comments) { VALUES(String path, Object value,boolean forceSet, String... comments) {
this.path = path; this.path = path;
this.value = value; this.value = value;
this.forceSet = forceSet;
this.comments = new ArrayList<>(Arrays.asList(comments)); this.comments = new ArrayList<>(Arrays.asList(comments));
} }
@ -68,6 +70,11 @@ public class T2CLibConfig {
return value; return value;
} }
@Override
public boolean getForceSet() {
return forceSet;
}
@Override @Override
public List<String> getComments() { public List<String> getComments() {
return comments; return comments;

View File

@ -4,8 +4,32 @@ package net.t2code.t2codelib;
import java.util.List; import java.util.List;
public interface T2CconfigItem { public interface T2CconfigItem {
/**
* Returns the path of the option for the config
* @return Config path of the option
*/
String getPath(); String getPath();
/**
* Returns the default value of the option and, after reading the config, the value from the config
* @return Value of the option
*/
Object getValue(); Object getValue();
/**
* Here you determine whether the value should always be set (true) or only when the config is first created (false)
*/
boolean getForceSet();
/**
* Set the description of the option here, the '# ' is automatically set in front of it
*/
List<String> getComments(); List<String> getComments();
void setValue(Object newValue);
/**
* This @void is used to reset the value of @getValue()
*/
default void setValue(Object newValue){
}
} }