package net.t2code.commandguiv2.Spigot.config.configConverter; import net.t2code.commandguiv2.Spigot.Main; import net.t2code.commandguiv2.Spigot.config.functions.CreateFunctions; import net.t2code.commandguiv2.Spigot.enums.FunctionItemEnum; import net.t2code.commandguiv2.Spigot.enums.FunctionVoteEnum; import net.t2code.commandguiv2.Util; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion; import org.apache.commons.io.FileUtils; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.List; public class ConfigConverter { public static void removeBungeeOption(){ File config = new File(Main.getPath(), "config.yml"); YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); yamlConfiguration.set("BungeeCord", null); try { yamlConfiguration.save(config); } catch (IOException e) { e.printStackTrace(); } } public static void renameMainFolder() { if (new File("plugins/CommandGUI").exists() && !Main.getPath().exists()) { File oldF = new File("plugins/CommandGUI"); File newF = new File("plugins/T2C-CommandGUI"); if (oldF.renameTo(newF)) { T2Csend.error(Main.getPlugin(), "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); T2Csend.error(Main.getPlugin(), ""); T2Csend.warning(Main.getPlugin(), "File renamed successfully"); T2Csend.warning(Main.getPlugin(), "The plugin folder has been renamed from 'CommandGUI' to 'T2C-CommandGUI"); T2Csend.error(Main.getPlugin(), ""); T2Csend.error(Main.getPlugin(), "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } else { T2Csend.error(Main.getPlugin(), "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); T2Csend.error(Main.getPlugin(), ""); T2Csend.error(Main.getPlugin(), "Failed to rename file"); T2Csend.error(Main.getPlugin(), "An error occurred while renaming the plugin folder from 'CommandGUI' to 'T2C-CommandGUI'! Please report on our Discord: " + Util.getDiscord()); T2Csend.error(Main.getPlugin(), ""); T2Csend.error(Main.getPlugin(), "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } } } public static void noPermLore(YamlConfiguration yamlConfiguration, File config) { yamlConfiguration.set("Slots.Function.NoPermission.Message.Enable", true); yamlConfiguration.set("Slots.Function.NoPermission.Message.CustomNoPermMessage", ""); yamlConfiguration.set("Slots.Function.NoPermission.Item.Lore.Enable", true); yamlConfiguration.set("Slots.Function.NoPermission.Item.Lore.Lore", Arrays.asList("&8-----------------", "&4No Permission for this Function", "&8-----------------")); try { yamlConfiguration.save(config); } catch (IOException e) { e.printStackTrace(); } T2Csend.error(Main.getPlugin(), "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); T2Csend.error(Main.getPlugin(), ""); T2Csend.warning(Main.getPlugin(), "'Slots.Function.NoPermission.Message.Enable' was added to the function " + config.getName() + "!"); T2Csend.warning(Main.getPlugin(), "'Slots.Function.NoPermission.Message.CustomNoPermMessage' was added to the function " + config.getName() + "!"); T2Csend.warning(Main.getPlugin(), "'Slots.Function.NoPermission.Item.Lore.Enable' was added to the function " + config.getName() + "!"); T2Csend.warning(Main.getPlugin(), "'Slots.Function.NoPermission.Item.Lore.Lore' was added to the function " + config.getName() + "!"); T2Csend.error(Main.getPlugin(), ""); T2Csend.error(Main.getPlugin(), "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } public static void convert() { renameFolder(); T2Csend.console(Util.getPrefix() + " §7[§5ConfigConvert§7] §4----------------------"); T2Csend.console(Util.getPrefix() + " §7[§5ConfigConvert§7]"); T2Csend.console(Util.getPrefix() + " §7[§5ConfigConvert§7] §4Config conversion to the new config structure starts!"); T2Csend.console(Util.getPrefix() + " §7[§5ConfigConvert§7]"); T2Csend.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 (T2CmcVersion.isMc1_8() || T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_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"); 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, true, "", true, Arrays.asList("&8-----------------", "&4No Permission for this Function", "&8-----------------"), customSoundEnable, customSoundNoSound, customSoundSound, costEnable, "vault", "DIRT;5", 0, 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, false, FunctionVoteEnum.ADD, 0, false, FunctionItemEnum.REMOVE, "DIRT;5"); } try { yamlConfiguration.save(config); } catch (IOException e) { e.printStackTrace(); } } } T2Csend.console(Util.getPrefix() + " §7[§5ConfigConvert§7] §4----------------------"); T2Csend.console(Util.getPrefix() + " §7[§5ConfigConvert§7]"); T2Csend.console(Util.getPrefix() + " §7[§5ConfigConvert§7] §4The conversion to the new config structure is completed!"); T2Csend.console(Util.getPrefix() + " §7[§5ConfigConvert§7]"); T2Csend.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 (T2CmcVersion.isMc1_8() || T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_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); } } }