T2C-CommandGUI/CommandGUI V2/src/main/java/net/t2code/commandguiv2/Spigot/config/functions/SelectFunctions.java

143 lines
11 KiB
Java

package net.t2code.commandguiv2.Spigot.config.functions;
import net.t2code.commandguiv2.Spigot.Main;
import net.t2code.commandguiv2.Spigot.config.configConverter.ConfigConverterV5;
import net.t2code.commandguiv2.Spigot.enums.EcoEnum;
import net.t2code.commandguiv2.Spigot.enums.FunctionItemEnum;
import net.t2code.commandguiv2.Spigot.enums.FunctionVoteEnum;
import net.t2code.commandguiv2.Spigot.objects.FunctionObject;
import net.t2code.commandguiv2.cache.Cache;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class SelectFunctions {
public static void onSelectFunction() {
Cache.functionHashMap.clear();
File f = new File(Main.getPath() + "/Functions/");
File[] fileArray = f.listFiles();
for (File config : fileArray) {
if (config.getName().equals("functionDeclaration.yml")) continue;
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");
if (yamlConfiguration.get("Slots.Function.NoPermission") == null) {
ConfigConverterV5.noPermLore(yamlConfiguration, config);
}
Boolean noPermMessageEnable = yamlConfiguration.getBoolean("Slots.Function.NoPermission.Message.Enable");
String customNoPermMessage = yamlConfiguration.getString("Slots.Function.NoPermission.Message.CustomNoPermMessage");
Boolean noPermLoreEnable = yamlConfiguration.getBoolean("Slots.Function.NoPermission.Item.Lore.Enable");
List<String> noPermLore = yamlConfiguration.getStringList("Slots.Function.NoPermission.Item.Lore.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");
EcoEnum ecoModule = null;
if (yamlConfiguration.get("Slots.Function.Cost.EcoModule") != null) {
try {
ecoModule = EcoEnum.valueOf(yamlConfiguration.getString("Slots.Function.Cost.EcoModule").toUpperCase());
} catch (Exception ex) {
T2Csend.error(Main.getPlugin(), "The EcoModule " + yamlConfiguration.getString("Slots.Function.Cost.EcoModule").toUpperCase() + " in the function file "
+ config.getName() + " does not exist. Please use one of the supported modules. (VAULT, ITEM, VOTEPOINTS)");
}
} else ecoModule = EcoEnum.VAULT;
String ecoItem = yamlConfiguration.getString("Slots.Function.Cost.Item");
Integer votePoints = yamlConfiguration.getInt("Slots.Function.Cost.VotePoints");
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");
Boolean functionVotePoints = yamlConfiguration.getBoolean("Slots.Function.FunctionVotePoints.Enable");
FunctionVoteEnum functionVotePointsMode = null;
if (yamlConfiguration.get("Slots.Function.FunctionVotePoints.Mode") != null) {
try {
functionVotePointsMode = FunctionVoteEnum.valueOf(yamlConfiguration.getString("Slots.Function.FunctionVotePoints.Mode").toUpperCase());
} catch (Exception ex) {
T2Csend.error(Main.getPlugin(), "The VotePoints Mode " + yamlConfiguration.getString("Slots.Function.FunctionVotePoints.Mode").toUpperCase() + " in the function file "
+ config.getName() + " does not exist. Please use one of the supported modules. (ADD, REMOVE)");
}
}
Integer functionVotePointsAmount = yamlConfiguration.getInt("Slots.Function.FunctionVotePoints.Amount");
Boolean functionItem = yamlConfiguration.getBoolean("Slots.Function.FunctionItem.Enable");
FunctionItemEnum functionItemMode = null;
if (yamlConfiguration.get("Slots.Function.FunctionItem.Mode") != null) {
try {
functionItemMode = FunctionItemEnum.valueOf(yamlConfiguration.getString("Slots.Function.FunctionItem.Mode").toUpperCase());
} catch (Exception ex) {
T2Csend.error(Main.getPlugin(), "The Item Mode " + yamlConfiguration.getString("Slots.Function.FunctionItem.Mode").toUpperCase() + " in the function file "
+ config.getName() + " does not exist. Please use one of the supported modules. (ADD, REMOVE)");
}
}
String functionItemItem = yamlConfiguration.getString("Slots.Function.FunctionItem.Item");
FunctionObject function = new FunctionObject(key, empty, itemAmount, playerHead_Enable, base64_Enable, base64Value, playerWhoHasOpenedTheGUI, playerName, item, name, lore,
noPermMessageEnable, customNoPermMessage, noPermLoreEnable, noPermLore,
customSound_Enable, customSound_NoSound, customSound_Sound, cost_Enable, ecoModule, ecoItem, votePoints, 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, functionVotePoints, functionVotePointsMode, functionVotePointsAmount,
functionItem, functionItemMode, functionItemItem);
Cache.functionHashMap.put(key, function);
try {
yamlConfiguration.save(config);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}