T2C-CommandGUI/CommandGUI V2/src/main/java/de/jatitv/commandguiv2/Spigot/config/functions/CreateFunctions.java

147 lines
9.5 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.functions;
import de.jatitv.commandguiv2.Spigot.Main;
import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class CreateFunctions {
public static void create() {
createFunction("UseItem", false, 1, false, false, "", false, "", "",
"&6Toggle UseItem", Arrays.asList("&bYou currently have the UseItem set to: %commandgui_useitem%"), false, false,
"", false, 0.0, false, false, false, Arrays.asList(), false,
"", false, "", false, "", true, true,
Arrays.asList("&bYour UseItem was set to: %commandgui_useitem%&b."), false, "", "", "String",
"", false, 0, 0.0, Arrays.asList(), "", false,
0, 0.0, Arrays.asList(), false, "");
createFunction("SupportDiscord", false, 1, true, true, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzg3M2MxMmJmZmI1MjUxYTBiODhkNWFlNzVjNzI0N2NiMzlhNzVmZjFhODFjYmU0YzhhMzliMzExZGRlZGEifX19",
false, "", "",
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
"&3Support Discord", Arrays.asList("&8-----------------", "&bIf you need help setting up the plugin,", "&bfeel free to contact me on the Suport Discord.",
"&8-----------------", "&eIf you find any errors or bugs,", "&eplease contact me so I can fix them.", "&8-----------------", "&5Discord: §7http://dc.t2code.net"),
false, false, "", false, 0.0, false, false,
false, Arrays.asList(), false, "", false, "", false, "",
false, true, Arrays.asList("&6You can find more information on Discord: &ehttp://dc.t2code.net"), false, "",
"", "String", "", false, 0, 0.0, Arrays.asList(),
"", false, 0, 0.0, Arrays.asList(), false, "");
}
public static void createFunction(String fileName, Boolean empty, Integer itemAmount, Boolean playerHeadEnable, Boolean base64Enable, String base64Value, Boolean playerWhoHasOpenedTheGUI,
String playerName, String itemMaterial, String name, List<String> lore, Boolean customSoundEnable, Boolean customSoundNoSound, String customSoundSound,
Boolean costEnable, Double price, Boolean commandEnable, Boolean commandBungeeCommand, Boolean commandAsConsole, List<String> command,
Boolean serverChange, String serverChangeServer, Boolean openGUIEnable, String openGUI, Boolean togglePermission, String togglePermissionPerm,
Boolean toggleUseItem, Boolean messageEnable, List<String> message, Boolean setConfigEnable, String configFilePath, String configOptionPath,
String configOptionPremat, String configStringValueLeft, Boolean configBooleanValueLeft, Integer configIntegerValueLeft, Double configDoubleValueLeft,
List<String> configListValueLeft, String configStringValueRight, Boolean configBooleanValueRight, Integer configIntegerValueRight, Double configDoubleValueRight,
List<String> configListValueRight, Boolean pluginReloadEnable, String pluginReloadCommand) {
long long_ = System.currentTimeMillis();
File config = new File(Main.getPath(), "Functions/" + fileName + ".yml");
int i = 1;
while (config.exists()) {
config = new File(Main.getPath(), "Functions/" + fileName + "-" + i + ".yml");
i++;
}
send.console(Main.prefix + " §4Function GUI file (Functions/" + config.getName() + ") is loaded...");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
set("Slots.Function.Item.Empty", empty, yamlConfiguration);
set("Slots.Function.Item.Amount", itemAmount, yamlConfiguration);
// if (!(MCVersion.minecraft1_8 || MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12)) {
set("Slots.Function.Item.PlayerHead.Enable", playerHeadEnable, yamlConfiguration);
set("Slots.Function.Item.PlayerHead.Base64.Enable", base64Enable, yamlConfiguration);
set("Slots.Function.Item.PlayerHead.Base64.Base64Value", base64Value, yamlConfiguration);
set("Slots.Function.Item.PlayerHead.PlayerWhoHasOpenedTheGUI", playerWhoHasOpenedTheGUI, yamlConfiguration);
set("Slots.Function.Item.PlayerHead.PlayerName", playerName, yamlConfiguration);
// }
set("Slots.Function.Item.Material", itemMaterial == null ? "" : itemMaterial, yamlConfiguration);
set("Slots.Function.Item.Name", name == null ? "" : name, yamlConfiguration);
set("Slots.Function.Item.Lore", lore, yamlConfiguration);
set("Slots.Function.CustomSound.Enable", customSoundEnable, yamlConfiguration);
set("Slots.Function.CustomSound.NoSound", customSoundNoSound, yamlConfiguration);
set("Slots.Function.CustomSound.Sound", customSoundSound == null ? "" : customSoundSound, yamlConfiguration);
set("Slots.Function.Cost.Enable", costEnable, yamlConfiguration);
set("Slots.Function.Cost.Price", price, yamlConfiguration);
set("Slots.Function.Command.Enable", commandEnable, yamlConfiguration);
set("Slots.Function.Command.BungeeCommand", commandBungeeCommand, yamlConfiguration);
set("Slots.Function.Command.CommandAsConsole", commandAsConsole, yamlConfiguration);
set("Slots.Function.Command.Command", command, yamlConfiguration);
set("Slots.Function.ServerChange.Enable", serverChange, yamlConfiguration);
set("Slots.Function.ServerChange.Server", serverChangeServer == null ? "" : serverChangeServer, yamlConfiguration);
set("Slots.Function.OpenGUI.Enable", openGUIEnable, yamlConfiguration);
set("Slots.Function.OpenGUI.GUI", openGUI == null ? "" : openGUI, yamlConfiguration);
set("Slots.Function.Toggle.Permission.Enable", togglePermission, yamlConfiguration);
set("Slots.Function.Toggle.Permission.Permission", togglePermissionPerm == null ? "" : togglePermissionPerm, yamlConfiguration);
set("Slots.Function.Toggle.UseItem.Enable", toggleUseItem, yamlConfiguration);
set("Slots.Function.Message.Enable", messageEnable, yamlConfiguration);
set("Slots.Function.Message.Message", message, yamlConfiguration);
set("Slots.Function.SetConfig.Enable", setConfigEnable, yamlConfiguration);
set("Slots.Function.SetConfig.File.Path", configFilePath == null ? "" : configFilePath, yamlConfiguration);
set("Slots.Function.SetConfig.Option.Path", configOptionPath == null ? "" : configOptionPath, yamlConfiguration);
set("Slots.Function.SetConfig.Option.Premat", configOptionPremat == null ? "" : configOptionPremat, yamlConfiguration);
set("Slots.Function.SetConfig.Value.LeftClick.String", configStringValueLeft == null ? "" : configStringValueLeft, yamlConfiguration);
set("Slots.Function.SetConfig.Value.LeftClick.Boolean", configBooleanValueLeft, yamlConfiguration);
set("Slots.Function.SetConfig.Value.LeftClick.Integer", configIntegerValueLeft, yamlConfiguration);
set("Slots.Function.SetConfig.Value.LeftClick.Double", configDoubleValueLeft, yamlConfiguration);
set("Slots.Function.SetConfig.Value.LeftClick.List", configListValueLeft, yamlConfiguration);
set("Slots.Function.SetConfig.Value.RightClick.String", configStringValueRight == null ? "" : configStringValueRight, yamlConfiguration);
set("Slots.Function.SetConfig.Value.RightClick.Boolean", configBooleanValueRight, yamlConfiguration);
set("Slots.Function.SetConfig.Value.RightClick.Integer", configIntegerValueRight, yamlConfiguration);
set("Slots.Function.SetConfig.Value.RightClick.Double", configDoubleValueRight, yamlConfiguration);
set("Slots.Function.SetConfig.Value.RightClick.List", configListValueRight, yamlConfiguration);
set("Slots.Function.SetConfig.PluginReload.Enable", pluginReloadEnable, yamlConfiguration);
set("Slots.Function.SetConfig.PluginReload.Command", pluginReloadCommand == null ? "" : pluginReloadCommand, yamlConfiguration);
try {
yamlConfiguration.save(config);
} catch (IOException e) {
e.printStackTrace();
}
send.console(Main.prefix + " §2Function file (Functions/" + config.getName() + ") was loaded." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
}
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);
}
}
private static void set(String path, List value, YamlConfiguration config) {
if (!config.contains(path)) {
config.set(path, value);
}
}
private static void set(String path, Double value, YamlConfiguration config) {
if (!config.contains(path)) {
config.set(path, value);
}
}
}