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); YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
if (yamlConfiguration.contains("ConfigVersion")) { 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() + " §4----------------------");
T2Csend.console(Util.getPrefix() + " "); T2Csend.console(Util.getPrefix() + " ");
T2Csend.console(Util.getPrefix() + " §6New features have been added to CommandGUI. The Config is adapted!"); 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----------------------"); T2Csend.console(Util.getPrefix() + " §4----------------------");
if (yamlConfiguration.getInt("ConfigVersion") < 5) { if (yamlConfiguration.getInt("ConfigVersion") < 5) {
ConfigConverterV5.convert(); ConfigConverterV5.convert();
selectConfig(); config = new File(Main.getPath(), "config.yml");
return; yamlConfiguration = YamlConfiguration.loadConfiguration(config);
} }
if (yamlConfiguration.getInt("ConfigVersion") < 6) { if (yamlConfiguration.getInt("ConfigVersion") < 6) {
ConfigConverterV6.convert(); new ConfigConverterV6();
selectConfig(); config = new File(Main.getPath(), "config.yml");
return; yamlConfiguration = YamlConfiguration.loadConfiguration(config);
} }
} }
} }

View File

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

View File

@ -8,111 +8,127 @@ import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class ConfigConverterV6 { 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.debug, "Plugin.Debug");
set(Config.updateCheckOnJoin, "Plugin.updateCheck.onJoin"); set(Config.updateCheckOnJoin, "Plugin.updateCheck.onJoin");
set(Config.updateCheckSeePreReleaseUpdates , "Plugin.updateCheck.seePreReleaseUpdates"); set(Config.updateCheckSeePreReleaseUpdates, "Plugin.updateCheck.seePreReleaseUpdates");
set(Config.updateCheckTimeInterval , "Plugin.updateCheck.timeInterval"); set(Config.updateCheckTimeInterval, "Plugin.updateCheck.timeInterval");
set(Config.helpAlias , "Plugin.HelpAlias"); set(Config.helpAlias, "Plugin.HelpAlias");
set(Config.adminSubCommand , "Plugin.AdminSubCommand"); set(Config.adminSubCommand, "Plugin.AdminSubCommand");
set(Config. language, "Plugin.language"); set(Config.language, "Plugin.language");
set(Config. currency, "Plugin.Currency"); set(Config.currency, "Plugin.Currency");
set(Config.defaultGUI , "Plugin.DefaultGUI"); set(Config.defaultGUI, "Plugin.DefaultGUI");
set(Config.storage , "Storage.Type"); set(Config.storage, "Storage.Type");
set(Config. mysqlIp, "Storage.MySQL.IP"); set(Config.mysqlIp, "Storage.MySQL.IP");
set(Config. mysqlPort, "Storage.MySQL.Port"); set(Config.mysqlPort, "Storage.MySQL.Port");
set(Config.mysqlDatabase , "Storage.MySQL.Database"); set(Config.mysqlDatabase, "Storage.MySQL.Database");
set(Config. mysqlUser, "Storage.MySQL.User"); set(Config.mysqlUser, "Storage.MySQL.User");
set(Config. mysqlPassword, "Storage.MySQL.Password"); set(Config.mysqlPassword, "Storage.MySQL.Password");
set(Config. mysqlSSL, "Storage.MySQL.SSL"); set(Config.mysqlSSL, "Storage.MySQL.SSL");
set(Config. useItemEnable, "UseItem.Enable"); set(Config.useItemEnable, "UseItem.Enable");
set(Config.useItemAllowToggle , "UseItem.AllowToggle"); set(Config.useItemAllowToggle, "UseItem.AllowToggle");
set(Config.useItemAllowSetSlot , "UseItem.AllowSetSlot"); set(Config.useItemAllowSetSlot, "UseItem.AllowSetSlot");
set(Config. useItemBlockMoveAndDrop, "UseItem.BlockMoveAndDrop"); set(Config.useItemBlockMoveAndDrop, "UseItem.BlockMoveAndDrop");
set(Config. useItemOpenGUI, "UseItem.OpenGUI"); set(Config.useItemOpenGUI, "UseItem.OpenGUI");
set(Config. useItemPermission, "UseItem.Permission.NeededToUse"); set(Config.useItemPermission, "UseItem.Permission.NeededToUse");
set(Config. useItemKeepAtCommandClear, "UseItem.KeepAtCommandClear"); set(Config.useItemKeepAtCommandClear, "UseItem.KeepAtCommandClear");
set(Config. useItemInventorySlotFreeSlot, "UseItem.InventorySlot.FreeSlot"); set(Config.useItemInventorySlotFreeSlot, "UseItem.InventorySlot.FreeSlot");
set(Config. useItemInventorySlot, "UseItem.InventorySlot.Slot"); set(Config.useItemInventorySlot, "UseItem.InventorySlot.Slot");
set(Config.useItemInventorySlotEnforce , "UseItem.InventorySlot.SlotEnforce"); set(Config.useItemInventorySlotEnforce, "UseItem.InventorySlot.SlotEnforce");
set(Config.useItemMaterial , "UseItem.Item.Material"); set(Config.useItemMaterial, "UseItem.Item.Material");
set(Config.useItemPlayerHeadEnable , "UseItem.Item.PlayerHead.Enable"); set(Config.useItemPlayerHeadEnable, "UseItem.Item.PlayerHead.Enable");
set(Config. useItemBase64Enable, "UseItem.Item.PlayerHead.Base64.Enable"); set(Config.useItemBase64Enable, "UseItem.Item.PlayerHead.Base64.Enable");
set(Config.useItemBase64value , "UseItem.Item.PlayerHead.Base64.Base64Value"); set(Config.useItemBase64value, "UseItem.Item.PlayerHead.Base64.Base64Value");
set(Config.useItemPlayerWhoHasOpenedTheGUI , "UseItem.Item.PlayerHead.PlayerWhoHasOpenedTheGUI"); set(Config.useItemPlayerWhoHasOpenedTheGUI, "UseItem.Item.PlayerHead.PlayerWhoHasOpenedTheGUI");
set(Config. useItemPlayerName, "UseItem.Item.PlayerHead.PlayerName"); set(Config.useItemPlayerName, "UseItem.Item.PlayerHead.PlayerName");
set(Config. useItemName, "UseItem.Item.Name"); set(Config.useItemName, "UseItem.Item.Name");
set(Config.useItemLore , "UseItem.Item.Lore"); set(Config.useItemLore, "UseItem.Item.Lore");
set(Config. useItemGiveOnEveryJoin, "UseItem.Join.GiveOnEveryJoin"); set(Config.useItemGiveOnEveryJoin, "UseItem.Join.GiveOnEveryJoin");
set(Config. useItemGiveOnlyOnFirstJoin, "UseItem.Join.GiveOnlyOnFirstJoin"); set(Config.useItemGiveOnlyOnFirstJoin, "UseItem.Join.GiveOnlyOnFirstJoin");
set(Config. cursorToGUIItemOnLogin, "UseItem.Join.Cursor.ToGUIItem.OnLogin.Enable"); set(Config.cursorToGUIItemOnLogin, "UseItem.Join.Cursor.ToGUIItem.OnLogin.Enable");
set(Config. cursorToGUIItemOnlyOnFirstLogin, "UseItem.Join.Cursor.ToGUIItem.Spigot.OnlyOnFirstLogin"); set(Config.cursorToGUIItemOnlyOnFirstLogin, "UseItem.Join.Cursor.ToGUIItem.Spigot.OnlyOnFirstLogin");
set(Config. useItemServerChange, "UseItem.Join.Cursor.ToGUIItem.Bungee.OnServerChange"); set(Config.useItemServerChange, "UseItem.Join.Cursor.ToGUIItem.Bungee.OnServerChange");
set(Config. toggleItemOnOrYesBase64, "Toggle.Items.OnOrYes.Item.Base64.Enable"); set(Config.toggleItemOnOrYesBase64, "Toggle.Items.OnOrYes.Item.Base64.Enable");
set(Config.toggleItemOnOrYesBase64Value , "Toggle.Items.OnOrYes.Item.Base64.Base64Value"); set(Config.toggleItemOnOrYesBase64Value, "Toggle.Items.OnOrYes.Item.Base64.Base64Value");
set(Config.toggleItemOnOrYesMaterial , "Toggle.Items.OnOrYes.Item.Material"); set(Config.toggleItemOnOrYesMaterial, "Toggle.Items.OnOrYes.Item.Material");
set(Config.toggleItemOffOrNoBase64 , "Toggle.Items.OffOrNo.Item.Base64.Enable"); set(Config.toggleItemOffOrNoBase64, "Toggle.Items.OffOrNo.Item.Base64.Enable");
set(Config. toggleItemOffOrNoBase64Value, "Toggle.Items.OffOrNo.Item.Base64.Base64Value"); set(Config.toggleItemOffOrNoBase64Value, "Toggle.Items.OffOrNo.Item.Base64.Base64Value");
set(Config.toggleItemOffOrNoMaterial , "Toggle.Items.OffOrNo.Item.Material"); set(Config.toggleItemOffOrNoMaterial, "Toggle.Items.OffOrNo.Item.Material");
set(Config.togglePermTrue , "Toggle.Permission.Commands.True"); set(Config.togglePermTrue, "Toggle.Permission.Commands.True");
set(Config.togglePermFalse , "Toggle.Permission.Commands.False"); set(Config.togglePermFalse, "Toggle.Permission.Commands.False");
set(Config. placeholderTrue, "Placeholder.True"); set(Config.placeholderTrue, "Placeholder.True");
set(Config. placeholderFalse, "Placeholder.False"); set(Config.placeholderFalse, "Placeholder.False");
set(Config. soundEnable, "Sound.Enable"); set(Config.soundEnable, "Sound.Enable");
set(Config. soundOpenInventoryEnable, "Sound.OpenInventory.Enable"); set(Config.soundOpenInventoryEnable, "Sound.OpenInventory.Enable");
set(Config. soundOpenInventoryInput, "Sound.OpenInventory.Sound"); set(Config.soundOpenInventoryInput, "Sound.OpenInventory.Sound");
set(Config. soundClickEnable, "Sound.Click.Enable"); set(Config.soundClickEnable, "Sound.Click.Enable");
set(Config. soundClickInput, "Sound.Click.Sound"); set(Config.soundClickInput, "Sound.Click.Sound");
set(Config.soundNoMoneyEnable , "Sound.NoMoney.Enable"); set(Config.soundNoMoneyEnable, "Sound.NoMoney.Enable");
set(Config.soundNoMoneyInput , "Sound.NoMoney.Sound"); set(Config.soundNoMoneyInput, "Sound.NoMoney.Sound");
set(Config. soundNoInventorySpaceEnable, "Sound.NoInventorySpace.Enable"); set(Config.soundNoInventorySpaceEnable, "Sound.NoInventorySpace.Enable");
set(Config.soundNoInventorySpaceInput , "Sound.NoInventorySpace.Sound"); set(Config.soundNoInventorySpaceInput, "Sound.NoInventorySpace.Sound");
set(Config.soundGiveEnable , "Sound.Give.Enable"); set(Config.soundGiveEnable, "Sound.Give.Enable");
set(Config.soundGiveInput , "Sound.Give.Sound"); set(Config.soundGiveInput, "Sound.Give.Sound");
set(Config. soundPlayerNotFoundEnable, "Sound.PlayerNotFound.Enable"); set(Config.soundPlayerNotFoundEnable, "Sound.PlayerNotFound.Enable");
set(Config. soundPlayerNotFoundInput, "Sound.PlayerNotFound.Sound"); set(Config.soundPlayerNotFoundInput, "Sound.PlayerNotFound.Sound");
set(Config. useItemGameModeChangeEnable, "Advanced.UseItem.GameMode.Change.Enable"); set(Config.useItemGameModeChangeEnable, "Advanced.UseItem.GameMode.Change.Enable");
set(Config. useItemGameModeChangeDelayInTicks, "Advanced.UseItem.GameMode.Change.DelayInTicks"); set(Config.useItemGameModeChangeDelayInTicks, "Advanced.UseItem.GameMode.Change.DelayInTicks");
set(Config. useItemGameModeProtection, "Advanced.UseItem.GameMode.Protection.Enable"); set(Config.useItemGameModeProtection, "Advanced.UseItem.GameMode.Protection.Enable");
set(Config.useItemGameModeRemoveItemWhenItIsDisabled , "Advanced.UseItem.GameMode.Protection.RemoveItemWhenItIsDisabled"); set(Config.useItemGameModeRemoveItemWhenItIsDisabled, "Advanced.UseItem.GameMode.Protection.RemoveItemWhenItIsDisabled");
set(Config. useItemGameModeMode, "Advanced.UseItem.GameMode.Protection.Mode"); set(Config.useItemGameModeMode, "Advanced.UseItem.GameMode.Protection.Mode");
set(Config.useItemGameModeList , "Advanced.UseItem.GameMode.Protection.List"); set(Config.useItemGameModeList, "Advanced.UseItem.GameMode.Protection.List");
set(Config.useItemWorldChangeEnable , "Advanced.UseItem.World.Change.Enable"); set(Config.useItemWorldChangeEnable, "Advanced.UseItem.World.Change.Enable");
set(Config.useItemWorldChangeDelayInTicks , "Advanced.UseItem.World.Change.DelayInTicks"); set(Config.useItemWorldChangeDelayInTicks, "Advanced.UseItem.World.Change.DelayInTicks");
set(Config.useItemWorldProtection , "Advanced.UseItem.World.Protection.Enable"); set(Config.useItemWorldProtection, "Advanced.UseItem.World.Protection.Enable");
set(Config.useItemWorldRemoveItemWhenItIsDisabled , "Advanced.UseItem.World.Protection.RemoveItemWhenItIsDisabled"); set(Config.useItemWorldRemoveItemWhenItIsDisabled, "Advanced.UseItem.World.Protection.RemoveItemWhenItIsDisabled");
set(Config. useItemWorldMode, "Advanced.UseItem.World.Protection.Mode"); set(Config.useItemWorldMode, "Advanced.UseItem.World.Protection.Mode");
set(Config. useItemWorldList, "Advanced.UseItem.World.Protection.List"); set(Config.useItemWorldList, "Advanced.UseItem.World.Protection.List");
set(Config.disableInfoBySneak , "Advanced.UseItem.DisableInfoBySneak"); set(Config.disableInfoBySneak, "Advanced.UseItem.DisableInfoBySneak");
set(Config.useItemItemBlockBlacklist , "Advanced.UseItem.ItemBlockBlacklist"); 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; if (!yamlConfigurationOld.contains(path)) return;
obj.value = yamlConfigurationOld.get(path); obj.value = yamlConfigurationOld.get(path);
} }

View File

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

View File

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