package de.jatitv.commandguiv2.Spigot.config.configConverter; import de.jatitv.commandguiv2.Spigot.Main; import de.jatitv.commandguiv2.Spigot.config.functions.CreateFunctions; import de.jatitv.commandguiv2.Util; import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion; import org.apache.commons.io.FileUtils; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; import java.io.File; import java.io.IOException; import java.util.List; public class ConfigConverterUnderV5 { public static void convert() { renameFolder(); send.console(Util.getPrefix() + " §7[§5ConfigConvert§7] §4----------------------"); send.console(Util.getPrefix() + " §7[§5ConfigConvert§7]"); send.console(Util.getPrefix() + " §7[§5ConfigConvert§7] §4Config conversion to the new config structure starts!"); send.console(Util.getPrefix() + " §7[§5ConfigConvert§7]"); send.console(Util.getPrefix() + " §7[§5ConfigConvert§7] §4----------------------"); File f = new File(Main.getPath() + "/OldConfig/GUIs/Version4"); File[] fileArray = f.listFiles(); for (File configOld : fileArray) { String sub = configOld.getName().substring(configOld.getName().length() - 4); if (sub.equals(".yml")) { YamlConfiguration yamlConfigurationOld = YamlConfiguration.loadConfiguration(configOld); File config = new File(Main.getPath(), "GUIs/" + configOld.getName().replace(".yml", "") + ".yml"); YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); Boolean enable = yamlConfigurationOld.getBoolean("GUI.Enable"); Integer lines = yamlConfigurationOld.getInt("GUI.Lines"); String name = yamlConfigurationOld.getString("GUI.Name"); Boolean fillItemEnable = yamlConfigurationOld.getBoolean("GUI.FillItem.Enable"); String fillItem; if (MCVersion.minecraft1_8 || MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12) { fillItem = yamlConfigurationOld.getString("GUI.FillItem.GlassPaneColor"); } else fillItem = yamlConfigurationOld.getString("GUI.FillItem.Item"); Boolean alias = yamlConfigurationOld.getBoolean("Command.Alias"); Boolean aliasPerm = yamlConfigurationOld.getBoolean("Command.Permission.Required"); setNew(enable, lines, name, fillItemEnable, fillItem, alias, aliasPerm, yamlConfiguration); for (String key : yamlConfigurationOld.getConfigurationSection("Slots").getKeys(false)) { Integer slotNumber = yamlConfigurationOld.getInt("Slots." + key + ".Slot"); Boolean slotEnable = yamlConfigurationOld.getBoolean("Slots." + key + ".Enable"); Boolean permRequired = yamlConfigurationOld.getBoolean("Slots." + key + ".Permission.Required"); Boolean empty = yamlConfigurationOld.getBoolean("Slots." + key + ".Item.Empty"); Integer itemAmount = yamlConfigurationOld.getInt("Slots." + key + ".Item.Amount"); Boolean playerHeadEnable = yamlConfigurationOld.getBoolean("Slots." + key + ".Item.PlayerHead.Enable"); Boolean base64Enable = yamlConfigurationOld.getBoolean("Slots." + key + ".Item.PlayerHead.Base64.Enable"); String base64Value = yamlConfigurationOld.getString("Slots." + key + ".Item.PlayerHead.Base64.Base64Value"); Boolean playerWhoHasOpenedTheGUI = yamlConfigurationOld.getBoolean("Slots." + key + ".Item.PlayerHead.PlayerWhoHasOpenedTheGUI"); String playerName = yamlConfigurationOld.getString("Slots." + key + ".Item.PlayerHead.PlayerName"); String itemMaterial = yamlConfigurationOld.getString("Slots." + key + ".Item.Material"); String itemName = yamlConfigurationOld.getString("Slots." + key + ".Item.Name"); List lore = yamlConfigurationOld.getStringList("Slots." + key + ".Item.Lore"); Boolean customSoundEnable = yamlConfigurationOld.getBoolean("Slots." + key + ".CustomSound.Enable"); Boolean customSoundNoSound = yamlConfigurationOld.getBoolean("Slots." + key + ".CustomSound.NoSound"); String customSoundSound = yamlConfigurationOld.getString("Slots." + key + ".CustomSound.Sound"); Boolean costEnable = yamlConfigurationOld.getBoolean("Slots." + key + ".Cost.Enable"); Double price = yamlConfigurationOld.getDouble("Slots." + key + ".Cost.Price"); Boolean commandEnable = yamlConfigurationOld.getBoolean("Slots." + key + ".Command.Enable"); Boolean commandBungeeCommand = yamlConfigurationOld.getBoolean("Slots." + key + ".Command.BungeeCommand"); Boolean commandAsConsole = yamlConfigurationOld.getBoolean("Slots." + key + ".Command.CommandAsConsole"); List command = yamlConfigurationOld.getStringList("Slots." + key + ".Command.Command"); Boolean serverChange = yamlConfigurationOld.getBoolean("Slots." + key + ".ServerChange.Enable"); String serverChangeServer = yamlConfigurationOld.getString("Slots." + key + ".ServerChange.Server"); Boolean openGUIEnable = yamlConfigurationOld.getBoolean("Slots." + key + ".OpenGUI.Enable"); String openGUI = yamlConfigurationOld.getString("Slots." + key + ".OpenGUI.GUI"); Boolean togglePermission = yamlConfigurationOld.getBoolean("Slots." + key + ".Toggle.Permission.Enable"); String togglePermissionPerm = yamlConfigurationOld.getString("Slots." + key + ".Toggle.Permission.Permission"); Boolean toggleUseItem = yamlConfigurationOld.getBoolean("Slots." + key + ".Toggle.UseItem.Enable"); Boolean messageEnable = yamlConfigurationOld.getBoolean("Slots." + key + ".Message.Enable"); List message = yamlConfigurationOld.getStringList("Slots." + key + ".Message.Message"); Boolean setConfigEnable = yamlConfigurationOld.getBoolean("Slots." + key + ".SetConfig.Enable"); String configFilePath = yamlConfigurationOld.getString("Slots." + key + ".SetConfig.File.Path"); String configOptionPath = yamlConfigurationOld.getString("Slots." + key + ".SetConfig.Option.Path"); String configOptionPremat = yamlConfigurationOld.getString("Slots." + key + ".SetConfig.Option.Premat"); // Boolean ConfigChatInput = ; String configStringValueLeft = yamlConfigurationOld.getString("Slots." + key + ".SetConfig.Value.LeftClick.String"); Boolean configBooleanValueLeft = yamlConfigurationOld.getBoolean("Slots." + key + ".SetConfig.Value.LeftClick.Boolean"); Integer configIntegerValueLeft = yamlConfigurationOld.getInt("Slots." + key + ".SetConfig.Value.LeftClick.Integer"); Double configDoubleValueLeft = yamlConfigurationOld.getDouble("Slots." + key + ".SetConfig.Value.LeftClick.Double"); List configListValueLeft = yamlConfigurationOld.getStringList("Slots." + key + ".SetConfig.Value.LeftClick.List"); String configStringValueRight = yamlConfigurationOld.getString("Slots." + key + ".SetConfig.Value.RightClick.String"); Boolean configBooleanValueRight = yamlConfigurationOld.getBoolean("Slots." + key + ".SetConfig.Value.RightClick.Boolean"); Integer configIntegerValueRight = yamlConfigurationOld.getInt("Slots." + key + ".SetConfig.Value.RightClick.Integer"); Double configDoubleValueRight = yamlConfigurationOld.getDouble("Slots." + key + ".SetConfig.Value.RightClick.Double"); List configListValueRight = yamlConfigurationOld.getStringList("Slots." + key + ".SetConfig.RightClick.Value.List"); Boolean pluginReloadEnable = yamlConfigurationOld.getBoolean("Slots." + key + ".SetConfig.PluginReload.Enable"); String pluginReloadCommand = yamlConfigurationOld.getString("Slots." + key + ".SetConfig.PluginReload.Command"); setNew(key, slotNumber, slotEnable, key, permRequired, yamlConfiguration); CreateFunctions.createFunction(key, empty, itemAmount, playerHeadEnable, base64Enable, base64Value, playerWhoHasOpenedTheGUI, playerName, itemMaterial, itemName, lore, customSoundEnable, customSoundNoSound, customSoundSound, costEnable, price, commandEnable, commandBungeeCommand, commandAsConsole, command, serverChange, serverChangeServer, openGUIEnable, openGUI, togglePermission, togglePermissionPerm, toggleUseItem, messageEnable, message, setConfigEnable, configFilePath, configOptionPath, configOptionPremat, configStringValueLeft, configBooleanValueLeft, configIntegerValueLeft, configDoubleValueLeft, configListValueLeft, configStringValueRight, configBooleanValueRight, configIntegerValueRight, configDoubleValueRight, configListValueRight, pluginReloadEnable, pluginReloadCommand); } try { yamlConfiguration.save(config); } catch (IOException e) { e.printStackTrace(); } } } send.console(Util.getPrefix() + " §7[§5ConfigConvert§7] §4----------------------"); send.console(Util.getPrefix() + " §7[§5ConfigConvert§7]"); send.console(Util.getPrefix() + " §7[§5ConfigConvert§7] §4The conversion to the new config structure is completed!"); send.console(Util.getPrefix() + " §7[§5ConfigConvert§7]"); send.console(Util.getPrefix() + " §7[§5ConfigConvert§7] §4----------------------"); } private static void renameFolder() { File dir = new File(Main.getPath() + "/GUIs"); File newDir = new File(Main.getPath() + "/OldConfig/GUIs/Version4"); try { FileUtils.moveDirectory(dir, newDir); } catch (IOException e) { e.printStackTrace(); } } private static void setNew(Boolean enable, Integer lines, String name, Boolean fillItemEnable, String fillItem, Boolean alias, Boolean aliasPerm, YamlConfiguration yamlConfiguration) { set("GUI.Enable", enable, yamlConfiguration); set("GUI.Lines", lines, yamlConfiguration); set("GUI.Name", name, yamlConfiguration); set("GUI.FillItem.Enable", fillItemEnable, yamlConfiguration); if (MCVersion.minecraft1_8 || MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12) { set("GUI.FillItem.GlassPaneColor", fillItem, yamlConfiguration); } else set("GUI.FillItem.Item", fillItem, yamlConfiguration); set("Command.Alias", alias, yamlConfiguration); set("Command.Permission.Required", aliasPerm, yamlConfiguration); } private static void setNew(String key, Integer slotNumber, Boolean slotEnable, String function, Boolean permRequired, YamlConfiguration yamlConfiguration) { set("Slots." + key + ".Slot", slotNumber, yamlConfiguration); set("Slots." + key + ".Enable", slotEnable, yamlConfiguration); set("Slots." + key + ".Function", function, yamlConfiguration); set("Slots." + key + ".Permission.Required", permRequired, yamlConfiguration); set("Slots." + key + ".Permission.See", "commandgui.gui.[function].slot.[slot].see", yamlConfiguration); set("Slots." + key + ".Permission.Use", "commandgui.gui.[function].slot.[slot].use", yamlConfiguration); } private static void set(String path, String value, YamlConfiguration config) { if (!config.contains(path)) { config.set(path, value); } } private static void set(String path, Integer value, YamlConfiguration config) { if (!config.contains(path)) { config.set(path, value); } } private static void set(String path, Boolean value, YamlConfiguration config) { if (!config.contains(path)) { config.set(path, value); } } }