171 lines
11 KiB
Java
171 lines
11 KiB
Java
package de.jatitv.commandguiv2.Spigot.objects;
|
|
|
|
import de.jatitv.commandguiv2.Spigot.Main;
|
|
import de.jatitv.commandguiv2.Spigot.cmdManagement.CmdExecuter_GUITab;
|
|
import de.jatitv.commandguiv2.Spigot.objects.functions.Function;
|
|
import de.jatitv.commandguiv2.Spigot.objects.guis.Gui;
|
|
import de.jatitv.commandguiv2.Spigot.objects.slots.Slot;
|
|
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.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
public class Obj_Select {
|
|
public static void onSelect() {
|
|
onSelectFunction();
|
|
onSelectGui();
|
|
}
|
|
|
|
public static void onSelectGui() {
|
|
Main.guiHashMap.clear();
|
|
Main.allAliases.clear();
|
|
File f = new File(Main.getPath() + "/GUIs/");
|
|
File[] fileArray = f.listFiles();
|
|
|
|
for (File config_gui : fileArray) {
|
|
String sub = config_gui.getName().substring(config_gui.getName().length() - 4);
|
|
if (sub.equals(".yml")) {
|
|
String key = config_gui.getName().replace(".yml", "");
|
|
Main.allAliases.add(key);
|
|
YamlConfiguration yamlConfiguration_gui = YamlConfiguration.loadConfiguration(config_gui);
|
|
|
|
Boolean guiEnable = yamlConfiguration_gui.getBoolean("GUI.Enable");
|
|
Integer guiLines = yamlConfiguration_gui.getInt("GUI.Lines");
|
|
if (yamlConfiguration_gui.getInt("GUI.Lines") > 6) {
|
|
yamlConfiguration_gui.set("GUI.Lines", 6);
|
|
}
|
|
if (yamlConfiguration_gui.getInt("GUI.Lines") < 1) {
|
|
yamlConfiguration_gui.set("GUI.Lines", 1);
|
|
}
|
|
|
|
String guiName = yamlConfiguration_gui.getString("GUI.Name");
|
|
Boolean guiFillItemEnable = yamlConfiguration_gui.getBoolean("GUI.FillItem.Enable");
|
|
String guiFillItemItem;
|
|
if (MCVersion.minecraft1_8 || MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12) {
|
|
guiFillItemItem = yamlConfiguration_gui.getString("GUI.FillItem.GlassPaneColor");
|
|
} else guiFillItemItem = yamlConfiguration_gui.getString("GUI.FillItem.Item");
|
|
|
|
Boolean commandAliasEnable = yamlConfiguration_gui.getBoolean("Command.Alias");
|
|
Boolean commandPermission = yamlConfiguration_gui.getBoolean("Command.Permission.Required");
|
|
|
|
ArrayList<Slot> slots = new ArrayList<>();
|
|
for (String slotKey : yamlConfiguration_gui.getConfigurationSection("Slots").getKeys(false)) {
|
|
Integer slotNumber = yamlConfiguration_gui.getInt("Slots." + slotKey + ".Slot") - 1;
|
|
Boolean enable = yamlConfiguration_gui.getBoolean("Slots." + slotKey + ".Enable");
|
|
String function = yamlConfiguration_gui.getString("Slots." + slotKey + ".Function");
|
|
Function functionCheck = Main.functionHashMap.get(function);
|
|
if (functionCheck == null) {
|
|
send.error(Main.plugin, "The Function " + function + " in the GUI " + key + " does not exist!");
|
|
}
|
|
Boolean permRequired = yamlConfiguration_gui.getBoolean("Slots." + slotKey + ".Permission.Required");
|
|
String permSee = yamlConfiguration_gui.getString("Slots." + slotKey + ".Permission.See");
|
|
String permUse = yamlConfiguration_gui.getString("Slots." + slotKey + ".Permission.Use");
|
|
|
|
Slot slot = new Slot(slotNumber, enable, function, permRequired,
|
|
Objects.requireNonNull(permSee).replace("[function]", key).replace("[slot]", String.valueOf(slotNumber + 1))
|
|
.replace("[slotname]", slotKey.toLowerCase()),
|
|
Objects.requireNonNull(permUse).replace("[function]", key).replace("[slot]", String.valueOf(slotNumber + 1))
|
|
.replace("[slotname]", slotKey.toLowerCase()));
|
|
slots.add(slot);
|
|
}
|
|
Gui gui = new Gui(guiEnable, guiLines, guiName, guiFillItemEnable, guiFillItemItem,
|
|
key, commandAliasEnable, commandPermission, slots);
|
|
|
|
Main.guiHashMap.put(key, gui);
|
|
CmdExecuter_GUITab.arg1.put(config_gui.getName()
|
|
.replace(".yml", ""), "commandgui.gui." + key);
|
|
|
|
try {
|
|
yamlConfiguration_gui.save(config_gui);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void onSelectFunction() {
|
|
Main.functionHashMap.clear();
|
|
File f = new File(Main.getPath() + "/Functions/");
|
|
File[] fileArray = f.listFiles();
|
|
|
|
for (File config : fileArray) {
|
|
String sub = config.getName().substring(config.getName().length() - 4);
|
|
if (sub.equals(".yml")) {
|
|
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
|
|
|
String key = config.getName().replace(".yml", "");
|
|
Boolean empty = yamlConfiguration.getBoolean("Slots.Function.Item.Empty");
|
|
Integer itemAmount = yamlConfiguration.getInt("Slots.Function.Item.Amount");
|
|
Boolean playerHead_Enable = yamlConfiguration.getBoolean("Slots.Function.Item.PlayerHead.Enable");
|
|
Boolean base64_Enable = yamlConfiguration.getBoolean("Slots.Function.Item.PlayerHead.Base64.Enable");
|
|
String base64Value = yamlConfiguration.getString("Slots.Function.Item.PlayerHead.Base64.Base64Value");
|
|
Boolean playerWhoHasOpenedTheGUI = yamlConfiguration.getBoolean("Slots.Function.Item.PlayerHead.PlayerWhoHasOpenedTheGUI");
|
|
String playerName = yamlConfiguration.getString("Slots.Function.Item.PlayerHead.PlayerName");
|
|
String item = yamlConfiguration.getString("Slots.Function.Item.Material");
|
|
String name = yamlConfiguration.getString("Slots.Function.Item.Name");
|
|
List<String> lore = yamlConfiguration.getStringList("Slots.Function.Item.Lore");
|
|
Boolean customSound_Enable = yamlConfiguration.getBoolean("Slots.Function.CustomSound.Enable");
|
|
Boolean customSound_NoSound = yamlConfiguration.getBoolean("Slots.Function.CustomSound.NoSound");
|
|
String customSound_Sound = yamlConfiguration.getString("Slots.Function.CustomSound.Sound");
|
|
Boolean cost_Enable = yamlConfiguration.getBoolean("Slots.Function.Cost.Enable");
|
|
Double price = yamlConfiguration.getDouble("Slots.Function.Cost.Price");
|
|
Boolean command_Enable = yamlConfiguration.getBoolean("Slots.Function.Command.Enable");
|
|
Boolean command_BungeeCommand = yamlConfiguration.getBoolean("Slots.Function.Command.BungeeCommand");
|
|
Boolean commandAsConsole = yamlConfiguration.getBoolean("Slots.Function.Command.CommandAsConsole");
|
|
List<String> command = yamlConfiguration.getStringList("Slots.Function.Command.Command");
|
|
Boolean serverChange = yamlConfiguration.getBoolean("Slots.Function.ServerChange.Enable");
|
|
String serverChangeServer = yamlConfiguration.getString("Slots.Function.ServerChange.Server");
|
|
Boolean openGUI_Enable = yamlConfiguration.getBoolean("Slots.Function.OpenGUI.Enable");
|
|
String openGUI = yamlConfiguration.getString("Slots.Function.OpenGUI.GUI");
|
|
Boolean togglePermission = yamlConfiguration.getBoolean("Slots.Function.Toggle.Permission.Enable");
|
|
String togglePermissionPerm = yamlConfiguration.getString("Slots.Function.Toggle.Permission.Permission");
|
|
Boolean toggleUseItem = yamlConfiguration.getBoolean("Slots.Function.Toggle.UseItem.Enable");
|
|
Boolean message_Enable = yamlConfiguration.getBoolean("Slots.Function.Message.Enable");
|
|
List<String> message = yamlConfiguration.getStringList("Slots.Function.Message.Message");
|
|
Boolean setConfigEnable = yamlConfiguration.getBoolean("Slots.Function.SetConfig.Enable");
|
|
String configFilePath = yamlConfiguration.getString("Slots.Function.SetConfig.File.Path");
|
|
String configOptionPath = yamlConfiguration.getString("Slots.Function.SetConfig.Option.Path");
|
|
String configOptionPremat = yamlConfiguration.getString("Slots.Function.SetConfig.Option.Premat");
|
|
// Boolean ConfigChatInput = ;
|
|
|
|
String configStringValueLeft = yamlConfiguration.getString("Slots.Function.SetConfig.Value.LeftClick.String");
|
|
Boolean configBooleanValueLeft = yamlConfiguration.getBoolean("Slots.Function.SetConfig.Value.LeftClick.Boolean");
|
|
Integer configIntegerValueLeft = yamlConfiguration.getInt("Slots.Function.SetConfig.Value.LeftClick.Integer");
|
|
Double configDoubleValueLeft = yamlConfiguration.getDouble("Slots.Function.SetConfig.Value.LeftClick.Double");
|
|
List<String> configListValueLeft = yamlConfiguration.getStringList("Slots.Function.SetConfig.Value.LeftClick.List");
|
|
|
|
String configStringValueRight = yamlConfiguration.getString("Slots.Function.SetConfig.Value.RightClick.String");
|
|
Boolean configBooleanValueRight = yamlConfiguration.getBoolean("Slots.Function.SetConfig.Value.RightClick.Boolean");
|
|
Integer configIntegerValueRight = yamlConfiguration.getInt("Slots.Function.SetConfig.Value.RightClick.Integer");
|
|
Double configDoubleValueRight = yamlConfiguration.getDouble("Slots.Function.SetConfig.Value.RightClick.Double");
|
|
List<String> configListValueRight = yamlConfiguration.getStringList("Slots.Function.SetConfig.RightClick.Value.List");
|
|
|
|
|
|
Boolean pluginReloadEnable = yamlConfiguration.getBoolean("Slots.Function.SetConfig.PluginReload.Enable");
|
|
String pluginReloadCommand = yamlConfiguration.getString("Slots.Function.SetConfig.PluginReload.Command");
|
|
|
|
|
|
Function function = new Function(key, empty, itemAmount, playerHead_Enable, base64_Enable, base64Value, playerWhoHasOpenedTheGUI, playerName, item, name, lore,
|
|
customSound_Enable, customSound_NoSound, customSound_Sound, cost_Enable, price, command_Enable, command_BungeeCommand, commandAsConsole, command,
|
|
serverChange, serverChangeServer, openGUI_Enable, openGUI, togglePermission, togglePermissionPerm, toggleUseItem, message_Enable, message,
|
|
setConfigEnable, configFilePath, configOptionPath, configOptionPremat, configStringValueLeft, configBooleanValueLeft, configIntegerValueLeft,
|
|
configDoubleValueLeft, configListValueLeft, configStringValueRight, configBooleanValueRight, configIntegerValueRight, configDoubleValueRight,
|
|
configListValueRight, pluginReloadEnable, pluginReloadCommand);
|
|
Main.functionHashMap.put(key, function);
|
|
|
|
try {
|
|
yamlConfiguration.save(config);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|