config convert v6

This commit is contained in:
JaTiTV 2022-12-31 02:59:15 +01:00
parent 052d2393aa
commit 6fefa8701e
6 changed files with 122 additions and 108 deletions

View File

@ -18,7 +18,7 @@ public class ConfigSelect {
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
if (yamlConfiguration.contains("ConfigVersion")) {
if (yamlConfiguration.getInt("ConfigVersion") < Util.getConfigVersion() && new File(Main.getPath(), "config.yml").exists()) {
if (yamlConfiguration.getInt("ConfigVersion") < (Integer) Config.configVersion.value && new File(Main.getPath(), "config.yml").exists()) {
T2Csend.console(Util.getPrefix() + " §4----------------------");
T2Csend.console(Util.getPrefix() + " ");
T2Csend.console(Util.getPrefix() + " §6New features have been added to CommandGUI. The Config is adapted!");
@ -26,13 +26,13 @@ public class ConfigSelect {
T2Csend.console(Util.getPrefix() + " §4----------------------");
if (yamlConfiguration.getInt("ConfigVersion") < 5) {
ConfigConverterV5.convert();
selectConfig();
return;
config = new File(Main.getPath(), "config.yml");
yamlConfiguration = YamlConfiguration.loadConfiguration(config);
}
if (yamlConfiguration.getInt("ConfigVersion") < 6) {
ConfigConverterV6.convert();
selectConfig();
return;
new ConfigConverterV6();
config = new File(Main.getPath(), "config.yml");
yamlConfiguration = YamlConfiguration.loadConfiguration(config);
}
}
}

View File

@ -26,7 +26,7 @@ public class ConfigCreate {
File config = new File(Main.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
if (!config.exists()) T2Cconfig.set("ConfigVersion", Util.getConfigVersion(), yamlConfiguration);
// if (!config.exists()) T2Cconfig.set("ConfigVersion", Util.getConfigVersion(), yamlConfiguration);
T2Cconfig.set("Plugin.Debug", false, yamlConfiguration);
T2Cconfig.set("Plugin.updateCheck.onJoin", true, yamlConfiguration);

View File

@ -19,16 +19,16 @@ public class SelectConfig {
File config = new File(Main.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
if (yamlConfiguration.getInt("ConfigVersion") < Util.getConfigVersion() && new File(Main.getPath(), "config.yml").exists()) {
T2Csend.console(Util.getPrefix() + " §4----------------------");
T2Csend.console(Util.getPrefix() + " ");
T2Csend.console(Util.getPrefix() + " §6New features have been added to CommandGUI. The Config is adapted!");
T2Csend.console(Util.getPrefix() + " ");
T2Csend.console(Util.getPrefix() + " §4----------------------");
if (yamlConfiguration.getInt("ConfigVersion") < 5) {
ConfigConverterV5.convert();
}
}
// if (yamlConfiguration.getInt("ConfigVersion") < Util.getConfigVersion() && new File(Main.getPath(), "config.yml").exists()) {
// T2Csend.console(Util.getPrefix() + " §4----------------------");
// T2Csend.console(Util.getPrefix() + " ");
// T2Csend.console(Util.getPrefix() + " §6New features have been added to CommandGUI. The Config is adapted!");
// T2Csend.console(Util.getPrefix() + " ");
// T2Csend.console(Util.getPrefix() + " §4----------------------");
// if (yamlConfiguration.getInt("ConfigVersion") < 5) {
// ConfigConverterV5.convert();
// }
// }
Debug = yamlConfiguration.getBoolean("Plugin.Debug");
updateCheckOnJoin = yamlConfiguration.getBoolean("Plugin.updateCheck.onJoin");
@ -253,7 +253,7 @@ public class SelectConfig {
public static void setConfigVersion() {
File config = new File(Main.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
yamlConfiguration.set("ConfigVersion", Util.getConfigVersion());
// yamlConfiguration.set("ConfigVersion", Util.getConfigVersion());
try {
yamlConfiguration.save(config);
} catch (IOException e) {

View File

@ -8,12 +8,31 @@ import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class ConfigConverterV6 {
private static final File configOld = new File(Main.getPath(), "config.yml");
private static final YamlConfiguration yamlConfigurationOld = YamlConfiguration.loadConfiguration(configOld);
public static void convert() throws IOException {
public ConfigConverterV6() {
try {
convert();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private File configOldRename;
private YamlConfiguration yamlConfigurationOld;
private void convert() throws IOException {
File oldF = new File("plugins/T2C-CommandGUI/config.yml");
File newF = new File("plugins/T2C-CommandGUI/configV5.yml");
oldF.renameTo(newF);
configOldRename = new File(Main.getPath(), "configV5.yml");
yamlConfigurationOld = YamlConfiguration.loadConfiguration(configOldRename);
set(Config.debug, "Plugin.Debug");
set(Config.updateCheckOnJoin, "Plugin.updateCheck.onJoin");
@ -107,12 +126,9 @@ public class ConfigConverterV6 {
set(Config.useItemItemBlockBlacklist, "Advanced.UseItem.ItemBlockBlacklist");
configOld.renameTo(new File(Main.getPath(), "configV5.yml"));
}
private static void set(Config obj, String path) {
private void set(Config obj, String path) {
if (!yamlConfigurationOld.contains(path)) return;
obj.value = yamlConfigurationOld.get(path);
}

View File

@ -58,11 +58,7 @@ public class Load {
if (!new File(Main.getPath(), "config.yml").exists()) {
try {
plugin.saveResource("configDeclaration.yml", false);
} catch (Exception e) {
e.printStackTrace();
}
try {
CreateGUI.configCreate();
} catch (Exception e) {
@ -80,6 +76,11 @@ public class Load {
} catch (Exception e) {
e.printStackTrace();
}
try {
plugin.saveResource("configDeclaration.yml", true);
} catch (Exception e) {
e.printStackTrace();
}
try {
plugin.saveResource("GUIs/guiDeclaration.yml", true);
} catch (Exception e) {

View File

@ -34,7 +34,4 @@ public class Util {
return net.t2code.t2codelib.Util.getDiscord();
}
public static Integer getConfigVersion() {
return 5;
}
}