small code changes
This commit is contained in:
parent
90f899cb16
commit
d8f0752ea7
4
pom.xml
4
pom.xml
@ -27,8 +27,8 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -3,7 +3,7 @@ package net.t2code.t2codelib.SPIGOT.api.yaml;
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
public static Boolean getInventoriesCloseByServerStop() {
|
||||
|
@ -12,51 +12,80 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class T2Cconfig {
|
||||
|
||||
/**
|
||||
* @deprecated since version 16.7, please use the new T2CconfigWriter.
|
||||
*/
|
||||
public static void set(String path, String value, YamlConfiguration YamlConfiguration) {
|
||||
if (!YamlConfiguration.contains(path)) {
|
||||
YamlConfiguration.set(path, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 16.7, please use the new T2CconfigWriter.
|
||||
*/
|
||||
public static void set(String path, Object value, YamlConfiguration YamlConfiguration) {
|
||||
if (!YamlConfiguration.contains(path)) {
|
||||
YamlConfiguration.set(path, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 16.7, please use the new T2CconfigWriter.
|
||||
*/
|
||||
public static void set(String path, YamlConfiguration YamlConfiguration) {
|
||||
YamlConfiguration.set(path, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 16.7, please use the new T2CconfigWriter.
|
||||
*/
|
||||
public static void set(String path, Integer value, YamlConfiguration YamlConfiguration) {
|
||||
if (!YamlConfiguration.contains(path)) {
|
||||
YamlConfiguration.set(path, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 16.7, please use the new T2CconfigWriter.
|
||||
*/
|
||||
public static void set(String path, Double value, YamlConfiguration YamlConfiguration) {
|
||||
if (!YamlConfiguration.contains(path)) {
|
||||
YamlConfiguration.set(path, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 16.7, please use the new T2CconfigWriter.
|
||||
*/
|
||||
public static void set(String path, Boolean value, YamlConfiguration YamlConfiguration) {
|
||||
if (!YamlConfiguration.contains(path)) {
|
||||
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) {
|
||||
if (!YamlConfiguration.contains(path)) {
|
||||
YamlConfiguration.set(path, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 16.7, please use the new T2CconfigWriter.
|
||||
*/
|
||||
public static void set(String path, ItemStack value, YamlConfiguration YamlConfiguration) {
|
||||
if (!YamlConfiguration.contains(path)) {
|
||||
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) {
|
||||
set("Sound." + soundName + ".Enable", true, yamlConfiguration);
|
||||
String sound;
|
||||
@ -68,6 +97,9 @@ public class T2Cconfig {
|
||||
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) {
|
||||
set("Sound." + soundName + ".Enable", true, yamlConfiguration);
|
||||
String sound;
|
||||
@ -77,19 +109,31 @@ public class T2Cconfig {
|
||||
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) {
|
||||
set("Sound." + soundName + ".Enable", true, 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) {
|
||||
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) {
|
||||
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) {
|
||||
String SOUND;
|
||||
if (T2CmcVersion.isMc1_8()) {
|
||||
@ -101,6 +145,9 @@ public class T2Cconfig {
|
||||
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) {
|
||||
String SOUND;
|
||||
if (T2CmcVersion.isMc1_8()) {
|
||||
@ -110,6 +157,9 @@ public class T2Cconfig {
|
||||
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) {
|
||||
try {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
return (yamlConfiguration.getInt(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 16.7, please use the new T2CconfigWriter.
|
||||
*/
|
||||
public static Boolean selectBoolean(String path, YamlConfiguration yamlConfiguration) {
|
||||
return (yamlConfiguration.getBoolean(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 16.7, please use the new T2CconfigWriter.
|
||||
*/
|
||||
public static Double selectDouble(String path, YamlConfiguration yamlConfiguration) {
|
||||
return (yamlConfiguration.getDouble(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 16.7, please use the new T2CconfigWriter.
|
||||
*/
|
||||
public static List<String> selectList(String path, YamlConfiguration yamlConfiguration) {
|
||||
return (yamlConfiguration.getStringList(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 16.7, please use the new T2CconfigWriter.
|
||||
*/
|
||||
public static ItemStack selectItemStack(String path, YamlConfiguration yamlConfiguration) {
|
||||
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) {
|
||||
List<String> output = new ArrayList<>();
|
||||
List<String> input = yamlConfiguration.getStringList(path);
|
||||
@ -157,6 +231,9 @@ public class T2Cconfig {
|
||||
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) {
|
||||
List<String> output = new ArrayList<>();
|
||||
List<String> input = yamlConfiguration.getStringList(path);
|
||||
|
@ -20,6 +20,7 @@ public class T2CconfigWriter {
|
||||
|
||||
|
||||
public static void createConfig(File configFile, T2CconfigItem[] values, String... header) {
|
||||
boolean exist = false;
|
||||
if (!configFile.exists()) {
|
||||
configFile.getParentFile().mkdirs();
|
||||
try {
|
||||
@ -28,24 +29,27 @@ public class T2CconfigWriter {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else exist = true;
|
||||
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
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());
|
||||
comments.put(value.getPath(), value.getComments());
|
||||
}
|
||||
}
|
||||
|
||||
// Copy default values if they are missing
|
||||
config.options().copyDefaults(true);
|
||||
|
||||
saveConfigWithComments(configFile, comments, header);
|
||||
readConfig(config,values);
|
||||
readConfig(config, values);
|
||||
}
|
||||
|
||||
private static void readConfig(FileConfiguration config, T2CconfigItem[] values) {
|
||||
for(T2CconfigItem value : values){
|
||||
for (T2CconfigItem value : values) {
|
||||
value.setValue(config.get(value.getPath()));
|
||||
}
|
||||
}
|
||||
@ -53,7 +57,7 @@ public class T2CconfigWriter {
|
||||
private static void saveConfigWithComments(File file, Map<String, List<String>> comments, String... headers) {
|
||||
try {
|
||||
StringBuilder configContent = new StringBuilder();
|
||||
for(String h : headers){
|
||||
for (String h : headers) {
|
||||
configContent.append(h).append("\n");
|
||||
}
|
||||
configContent.append("\n");
|
||||
@ -77,7 +81,7 @@ public class T2CconfigWriter {
|
||||
// Add comment if it exists for this key
|
||||
List<String> commentList = comments.get(fullKey);
|
||||
if (commentList != null) {
|
||||
for(String c : commentList){
|
||||
for (String c : commentList) {
|
||||
builder.append(indent).append("# ").append(c).append("\n");
|
||||
}
|
||||
}
|
||||
|
@ -16,45 +16,47 @@ public class T2CLibConfig {
|
||||
|
||||
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!"),
|
||||
|
||||
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."),
|
||||
|
||||
space_command("command", null, ""),
|
||||
space_command("command", null, true,""),
|
||||
|
||||
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 Object value;
|
||||
private final boolean forceSet;
|
||||
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.value = value;
|
||||
this.forceSet = forceSet;
|
||||
this.comments = new ArrayList<>(Arrays.asList(comments));
|
||||
}
|
||||
|
||||
@ -68,6 +70,11 @@ public class T2CLibConfig {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getForceSet() {
|
||||
return forceSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getComments() {
|
||||
return comments;
|
||||
|
@ -4,8 +4,32 @@ package net.t2code.t2codelib;
|
||||
import java.util.List;
|
||||
|
||||
public interface T2CconfigItem {
|
||||
/**
|
||||
* Returns the path of the option for the config
|
||||
* @return Config path of the option
|
||||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
void setValue(Object newValue);
|
||||
|
||||
/**
|
||||
* This @void is used to reset the value of @getValue()
|
||||
*/
|
||||
default void setValue(Object newValue){
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user