T2C-CommandGUI/CommandGUI V2/src/main/java/net/t2code/commandguiv2/Spigot/gui/GUIListener.java

375 lines
18 KiB
Java
Raw Normal View History

2022-11-01 12:20:53 +00:00
package net.t2code.commandguiv2.Spigot.gui;
2021-12-21 04:57:29 +00:00
import net.t2code.commandguiv2.Spigot.cmdManagement.Help;
2022-11-01 12:20:53 +00:00
import net.t2code.commandguiv2.Spigot.listener.ServerChange;
import net.t2code.commandguiv2.Spigot.useItem.Events;
import net.t2code.commandguiv2.Spigot.objects.functions.Function;
import net.t2code.commandguiv2.Spigot.cmdManagement.Commands;
import net.t2code.commandguiv2.Spigot.objects.slots.Slot;
import net.t2code.commandguiv2.Spigot.listener.Bungee_Sender_Reciver;
import net.t2code.commandguiv2.Spigot.config.languages.SelectMessages;
import net.t2code.commandguiv2.Spigot.objects.guis.Gui;
import net.t2code.commandguiv2.Spigot.config.config.SelectConfig;
import net.t2code.commandguiv2.Spigot.Main;
import net.t2code.commandguiv2.Spigot.system.Placeholder;
import net.t2code.commandguiv2.Spigot.sound.Sound;
import net.t2code.commandguiv2.Spigot.enums.SoundEnum;
import net.t2code.commandguiv2.Util;
2022-08-10 13:53:01 +00:00
import net.t2code.t2codelib.SPIGOT.api.eco.T2Ceco;
import net.t2code.t2codelib.SPIGOT.api.items.T2CitemVersion;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
2021-12-21 04:57:29 +00:00
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
2022-01-03 17:11:51 +00:00
import org.bukkit.event.inventory.ClickType;
2021-12-21 04:57:29 +00:00
import org.bukkit.event.inventory.InventoryClickEvent;
2022-08-10 13:53:01 +00:00
import org.bukkit.inventory.ItemStack;
2021-12-21 04:57:29 +00:00
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.File;
import java.io.IOException;
public class GUIListener implements Listener {
2021-12-21 04:57:29 +00:00
2022-01-01 02:40:54 +00:00
private static String prefix = Util.getPrefix();
2021-12-21 04:57:29 +00:00
public static String GUICode;
private static Plugin plugin = Main.getPlugin();
2021-12-21 04:57:29 +00:00
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
Player player = (Player) e.getWhoClicked();
if (e.getInventory() == null) return;
if (e.getCurrentItem() == null) return;
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
for (Gui gui : Main.guiHashMap.values()) {
2022-08-10 13:53:01 +00:00
if (player.getOpenInventory().getTitle().equals(T2Creplace.replace(prefix, GUICode + gui.guiName))
|| (Main.PaPi && player.getOpenInventory().getTitle().equals(T2Creplace.replace(prefix, player, GUICode + gui.guiName)))) {
e.setCancelled(true);
if (player.getOpenInventory().getTopInventory() != e.getClickedInventory()) {
continue;
}
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
for (Slot slot : gui.slots) {
execute(e, slot, player, gui);
}
}
}
}
private static void execute(InventoryClickEvent e, Slot slot, Player player, Gui gui) {
if (e.getSlot() != slot.slot) return;
Function function = Main.functionHashMap.get(slot.function);
if (slot.permission && !player.hasPermission(slot.permissionToSee)) return;
if (slot.permission && !player.hasPermission(slot.permissionToUse)) {
if (function.noPermMessageEnable) {
if (function.customNoPermMessage == null || function.customNoPermMessage.equals("")) {
2022-08-10 13:53:01 +00:00
T2Csend.player(player, SelectMessages.NoPermissionForItem.replace("[item]", T2Creplace.replace(prefix, function.name))
.replace("[perm]", slot.permissionToUse));
2022-08-10 13:53:01 +00:00
} else T2Csend.player(player, function.customNoPermMessage.replace("[item]", T2Creplace.replace(prefix, function.name))
.replace("[perm]", slot.permissionToUse));
}
return;
}
2022-08-10 13:53:01 +00:00
if (e.getCurrentItem().getType() == T2CitemVersion.getHead() || e.getCurrentItem().getType() == T2CitemVersion.getGreenWool().getType() ||
e.getCurrentItem().getType() == T2CitemVersion.getRedWool().getType() ||
e.getCurrentItem().getType() == Material.valueOf(function.item.toUpperCase().replace(".", "_"))) {
if (!slot.enable) return;
if (function.cost_Enable) {
if (functions(function)) {
eco(e, slot, player, gui, function);
}
} else {
execute(function, slot, player, e, gui);
}
}
}
2021-12-21 04:57:29 +00:00
private static boolean functions(Function function) {
if (function.togglePermission) return true;
if (function.toggleUseItem) return true;
if (function.command_Enable) return true;
if (function.openGUI_Enable) return true;
if (function.message_Enable) return true;
if (function.serverChange) return true;
if (function.setConfigEnable) return true;
if (function.functionVotePoints) return true;
return function.functionItem;
}
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 execute(Function function, Slot slot, Player player, InventoryClickEvent e, Gui gui) {
if (function.togglePermission) togglePerm(function, gui, player);
if (function.toggleUseItem) toggleUseItem(player, gui);
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
if (function.command_Enable) command(function, player);
if (function.openGUI_Enable) openGUI(function, player);
if (function.message_Enable) message(function, player);
if (function.serverChange) serverChange(function, player);
if (function.setConfigEnable) setConfig(function, player, e);
if (function.functionVotePoints) votePoints(e, function, player);
if (function.functionItem) item(function, player);
Sound.play(player, SoundEnum.Click, function, slot, gui);
}
2021-12-21 04:57:29 +00:00
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 command(Function slot, Player player) {
player.closeInventory();
new BukkitRunnable() {
@Override
public void run() {
2022-04-16 12:32:22 +00:00
if (slot.command_BungeeCommand) {
if (SelectLibConfig.getBungee()) {
2022-04-16 12:32:22 +00:00
for (String cmd : slot.command) {
Bungee_Sender_Reciver.sendToBungee(player, cmd.replace("[player]", player.getName()), slot.commandAsConsole);
}
} else {
2022-08-10 13:53:01 +00:00
T2Csend.console(prefix + " §4To use bungee commands, enable the Bungee option in the config.");
T2Csend.player(player, prefix + " §4To use bungee commands, enable the Bungee option in the config.");
}
} else {
2022-04-16 12:32:22 +00:00
for (String cmd : slot.command) {
if (slot.commandAsConsole) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd.replace("[player]", player.getName()));
} else player.chat("/" + cmd.replace("[player]", player.getName()));
}
}
}
}.runTaskLater(plugin, 2L);
}
2021-12-21 04:57:29 +00:00
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 openGUI(Function slot, Player player) {
2022-04-18 21:12:50 +00:00
player.closeInventory();
new BukkitRunnable() {
@Override
public void run() {
OpenGUI.openGUI(player, slot.openGUI, true);
}
}.runTaskLater(plugin, 1L);
}
2021-12-21 04:57:29 +00:00
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 message(Function slot, Player player) {
player.closeInventory();
2022-04-16 12:32:22 +00:00
for (String msg : slot.message) {
if (Main.PaPi) {
2022-04-16 12:32:22 +00:00
if (slot.cost_Enable) {
2022-08-10 13:53:01 +00:00
T2Csend.player(player, T2Creplace.replacePrice(prefix, player, Placeholder.replace(msg, player), slot.price + " " + SelectConfig.getCurrency()));
} else T2Csend.player(player, T2Creplace.replace(prefix, player, Placeholder.replace(msg, player)));
} else {
2022-04-16 12:32:22 +00:00
if (slot.cost_Enable) {
2022-08-10 13:53:01 +00:00
T2Csend.player(player, T2Creplace.replacePrice(prefix, Placeholder.replace(msg, player), slot.price + " " + SelectConfig.getCurrency()));
} else T2Csend.player(player, T2Creplace.replace(prefix, Placeholder.replace(msg, player)));
}
}
}
2021-12-21 04:57:29 +00:00
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 serverChange(Function slot, Player player) {
new BukkitRunnable() {
@Override
public void run() {
player.closeInventory();
}
}.runTaskLater(plugin, 1L);
2022-08-10 13:53:01 +00:00
T2Csend.player(player, SelectMessages.onServerChange.replace("[server]", slot.serverChangeServer));
new BukkitRunnable() {
@Override
public void run() {
2022-04-16 12:32:22 +00:00
ServerChange.send(player, slot.serverChangeServer);
}
}.runTaskLater(Main.getPlugin(), 20L);
}
2021-12-21 04:57:29 +00:00
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 setConfig(Function slot, Player player, InventoryClickEvent e) {
2022-04-16 12:32:22 +00:00
File config = new File(slot.configFilePath);
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
2022-04-16 12:32:22 +00:00
if (e.getClick() == ClickType.LEFT) {
switch (slot.configOptionPremat) {
case "String":
yamlConfiguration.set(slot.configOptionPath.replace("/", "."), slot.configStringValueLeft);
break;
case "Boolean":
yamlConfiguration.set(slot.configOptionPath.replace("/", "."), slot.configBooleanValueLeft);
break;
case "Integer":
yamlConfiguration.set(slot.configOptionPath.replace("/", "."), slot.configIntegerValueLeft);
break;
case "Double":
yamlConfiguration.set(slot.configOptionPath.replace("/", "."), slot.configDoubleValueLeft);
break;
case "List":
yamlConfiguration.set(slot.configOptionPath.replace("/", "."), slot.configListValueLeft);
break;
default:
2022-08-10 13:53:01 +00:00
T2Csend.player(player, "§cCheck the Option §6SetConfig/Option/Premat"); //todo
break;
}
}
if (e.getClick() == ClickType.RIGHT) {
switch (slot.configOptionPremat) {
case "String":
yamlConfiguration.set(slot.configOptionPath.replace("/", "."), slot.configStringValueRight);
break;
case "Boolean":
yamlConfiguration.set(slot.configOptionPath.replace("/", "."), slot.configBooleanValueRight);
break;
case "Integer":
yamlConfiguration.set(slot.configOptionPath.replace("/", "."), slot.configIntegerValueRight);
break;
case "Double":
yamlConfiguration.set(slot.configOptionPath.replace("/", "."), slot.configDoubleValueRight);
break;
case "List":
yamlConfiguration.set(slot.configOptionPath.replace("/", "."), slot.configListValueRight);
break;
default:
2022-08-10 13:53:01 +00:00
T2Csend.player(player, "§cCheck the Option §6SetConfig/Option/Premat"); //todo
break;
}
}
try {
yamlConfiguration.save(config);
} catch (IOException tac) {
tac.printStackTrace();
}
2022-04-16 12:32:22 +00:00
if (slot.pluginReloadEnable) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), slot.pluginReloadCommand);
}
new BukkitRunnable() {
@Override
public void run() {
player.closeInventory();
}
}.runTaskLater(plugin, 1L);
}
2021-12-21 04:57:29 +00:00
private static void togglePerm(Function function, Gui gui, Player player) {
if (player.hasPermission(function.togglePermissionPerm)) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), SelectConfig.getTogglePermFalse().replace("[player]", player.getName()).replace("[perm]", function.togglePermissionPerm));
new BukkitRunnable() {
@Override
public void run() {
player.closeInventory();
OpenGUI.openGUI(player, gui.key, false);
}
}.runTaskLater(plugin, 4L);
2022-04-16 12:32:22 +00:00
} else
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), SelectConfig.getTogglePermTrue().replace("[player]", player.getName()).replace("[perm]", function.togglePermissionPerm));
new BukkitRunnable() {
@Override
public void run() {
player.closeInventory();
OpenGUI.openGUI(player, gui.key, false);
}
}.runTaskLater(plugin, 4L);
2022-04-16 12:32:22 +00:00
}
private static void toggleUseItem(Player player, Gui gui) {
if (!SelectConfig.getUseItem_AllowToggle()) {
T2Csend.sender(player, "§4UseItem toggle is disabled!");
return;
}
if (Events.useItemHashMap.get(player.getName())) {
2022-04-16 12:32:22 +00:00
Commands.itemOff(player);
} else {
Commands.itemOn(player);
}
new BukkitRunnable() {
@Override
public void run() {
player.closeInventory();
OpenGUI.openGUI(player, gui.key, false);
}
}.runTaskLater(plugin, 2L);
2021-12-21 04:57:29 +00:00
}
private static void votePoints(InventoryClickEvent e, Function function, Player player) {
player.closeInventory();
switch (function.functionVotePointsMode) {
case ADD:
2022-08-10 13:53:01 +00:00
T2Ceco.votePointsAdd(prefix, player, function.functionVotePointsAmount);
T2Csend.player(player, SelectMessages.functionVoteAdd.replace("[amount]", function.functionVotePointsAmount.toString()));
break;
case REMOVE:
2022-08-10 13:53:01 +00:00
if (T2Ceco.votePointsRemove(prefix, player, function.functionVotePointsAmount)) {
T2Csend.player(player, SelectMessages.functionVoteRemove.replace("[amount]", function.functionVotePointsAmount.toString()));
} else T2Csend.player(player, SelectMessages.functionVoteRemoveError.replace("[amount]", function.functionVotePointsAmount.toString()));
break;
}
}
private static void item(Function function, Player player) {
String[] item = function.functionItemItem.split(";");
player.closeInventory();
switch (function.functionItemMode) {
case ADD:
2022-08-10 13:53:01 +00:00
T2Ceco.itemAdd(player, new ItemStack(Material.valueOf(item[0])), Integer.parseInt(item[1]));
T2Csend.player(player, SelectMessages.functionItemAdd.replace("[amount]", item[1]).replace("[item]", item[0]));
break;
case REMOVE:
2022-08-10 13:53:01 +00:00
if (T2Ceco.itemRemove(player, item[0], Integer.parseInt(item[1]))) {
T2Csend.player(player, SelectMessages.functionItemRemove.replace("[amount]", item[1]).replace("[item]", item[0]));
2022-08-10 13:53:01 +00:00
} else T2Csend.player(player, SelectMessages.functionItemRemoveError.replace("[amount]", item[1]));
break;
}
}
private static void eco(InventoryClickEvent e, Slot slot, Player player, Gui gui, Function function) {
switch (function.ecoModule) {
case ITEM:
String[] item = function.ecoItem.split(";");
2022-08-10 13:53:01 +00:00
if (!T2Ceco.itemRemove(player, item[0], Integer.parseInt(item[1]))) {
new BukkitRunnable() {
@Override
public void run() {
player.closeInventory();
}
}.runTaskLater(plugin, 1L);
2022-08-10 13:53:01 +00:00
T2Csend.player(player, SelectMessages.noMoneyItem.replace("[item]", item[0]).replace("[amount]", item[1]));
Sound.play(player, SoundEnum.NoMoney);
} else {
2022-08-10 13:53:01 +00:00
T2Csend.player(player, SelectMessages.Buy_msg.replace("[itemname]", T2Creplace.replace(prefix, function.name))
.replace("[price]", item[1] + " " + item[0]));
execute(function, slot, player, e, gui);
}
break;
case VOTEPOINTS:
2022-08-10 13:53:01 +00:00
if (!T2Ceco.votePointsRemove(prefix, player, function.votePoints)) {
new BukkitRunnable() {
@Override
public void run() {
player.closeInventory();
}
}.runTaskLater(plugin, 1L);
2022-08-10 13:53:01 +00:00
T2Csend.player(player, SelectMessages.noMoneyVote.replace("[amount]", function.votePoints.toString()));
Sound.play(player, SoundEnum.NoMoney);
} else {
2022-08-10 13:53:01 +00:00
T2Csend.player(player, SelectMessages.Buy_msg.replace("[itemname]", T2Creplace.replace(prefix, function.name))
.replace("[price]", function.votePoints + " VotePoints"));
execute(function, slot, player, e, gui);
}
break;
case VAULT:
case MONEY:
2022-08-10 13:53:01 +00:00
if (!T2Ceco.moneyRemove(prefix, player, function.price)) {
new BukkitRunnable() {
@Override
public void run() {
player.closeInventory();
}
}.runTaskLater(plugin, 1L);
2022-08-10 13:53:01 +00:00
T2Csend.player(player, T2Creplace.replacePrice(prefix, SelectMessages.noMoney, String.valueOf(function.price)));
Sound.play(player, SoundEnum.NoMoney);
} else {
2022-08-10 13:53:01 +00:00
T2Csend.player(player, SelectMessages.Buy_msg.replace("[itemname]", T2Creplace.replace(prefix, function.name))
.replace("[price]", function.price + " " + SelectConfig.getCurrency()));
execute(function, slot, player, e, gui);
}
break;
}
}
2022-04-18 21:12:50 +00:00
}