T2C-CommandGUI/CommandGUI V2/src/main/java/de/jatitv/commandguiv2/Spigot/config/configConverter/ConfigConverterUnderV5.java

177 lines
12 KiB
Java
Raw Normal View History

2.7.0 Snapshot 1 In this update some functions were rewritten, changed and added. Also some minor bugs have been fixed. The GUIs files have been split into GUI files and function files, this provides more clarity in the complete plugin structure and offers the possibility to access a function from multiple GUIs. Thus, for example, you can create a back button as a function and open it from 3 GUIs, the item, the function can also be in different places, because the slot is set in the GUI file. In the GUI files is thus specified on which slot which function should be located. In addition, the permission for See and for Use of the functions can now be set individually in the GUI Config. In the functions also 2 new functions were added, with which players can switch permissions on and off and an option to switch the UseItem on and off. Placeholders have been added. This update includes a converter that builds the new structure from the old config structure. Your options should be taken over. For security reasons your old GUI files are saved under the path 'plugins/CommandGUI/OldConfig/GUIs/Version4'. Bug fixes: - Fixed a bug that prevented GUIs from opening. - The OpenGUI option, the command '/cgui <guiname>' did not work. The GUI that was set as default GUI in UseItem was always opened. This was fixed New features: - Placeholders - %commandgui_useitem% - Shows if you have activated or deactivated the UseItem (in color, customizable in config.yml) - %commandgui_useitem_boolean% - Shows if you have enabled or disabled the UseItem - %commandgui_useitem_slot% - shows on which slot you have set the UseItem - ToggleUseItem as new option for slots - TogglePermission as new option for slots Changes: - The config structure has been revised.
2022-04-19 05:08:33 +00:00
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<String> 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<String> 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<String> 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<String> 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<String> 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);
2.7.0 Snapshot 1 In this update some functions were rewritten, changed and added. Also some minor bugs have been fixed. The GUIs files have been split into GUI files and function files, this provides more clarity in the complete plugin structure and offers the possibility to access a function from multiple GUIs. Thus, for example, you can create a back button as a function and open it from 3 GUIs, the item, the function can also be in different places, because the slot is set in the GUI file. In the GUI files is thus specified on which slot which function should be located. In addition, the permission for See and for Use of the functions can now be set individually in the GUI Config. In the functions also 2 new functions were added, with which players can switch permissions on and off and an option to switch the UseItem on and off. Placeholders have been added. This update includes a converter that builds the new structure from the old config structure. Your options should be taken over. For security reasons your old GUI files are saved under the path 'plugins/CommandGUI/OldConfig/GUIs/Version4'. Bug fixes: - Fixed a bug that prevented GUIs from opening. - The OpenGUI option, the command '/cgui <guiname>' did not work. The GUI that was set as default GUI in UseItem was always opened. This was fixed New features: - Placeholders - %commandgui_useitem% - Shows if you have activated or deactivated the UseItem (in color, customizable in config.yml) - %commandgui_useitem_boolean% - Shows if you have enabled or disabled the UseItem - %commandgui_useitem_slot% - shows on which slot you have set the UseItem - ToggleUseItem as new option for slots - TogglePermission as new option for slots Changes: - The config structure has been revised.
2022-04-19 05:08:33 +00:00
}
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);
}
}
}