2021-12-21 04:57:29 +00:00
|
|
|
package de.jatitv.commandguiv2.Spigot.Listener;
|
|
|
|
|
|
|
|
import de.jatitv.commandguiv2.Spigot.Objekte.Slot;
|
|
|
|
import de.jatitv.commandguiv2.Spigot.system.Bungee_Sender_Reciver;
|
2022-01-06 01:21:27 +00:00
|
|
|
import de.jatitv.commandguiv2.Spigot.config.languages.SelectMessages;
|
2021-12-21 04:57:29 +00:00
|
|
|
import de.jatitv.commandguiv2.Spigot.Objekte.Object;
|
|
|
|
import de.jatitv.commandguiv2.Spigot.gui.OpenGUI;
|
2022-01-06 01:21:27 +00:00
|
|
|
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
|
2021-12-21 04:57:29 +00:00
|
|
|
import de.jatitv.commandguiv2.Spigot.Main;
|
2022-01-01 02:40:54 +00:00
|
|
|
import de.jatitv.commandguiv2.Util;
|
2021-12-21 04:57:29 +00:00
|
|
|
import net.t2code.lib.Spigot.Lib.items.ItemVersion;
|
|
|
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
|
|
|
import net.t2code.lib.Spigot.Lib.replace.Replace;
|
|
|
|
import net.t2code.lib.Spigot.Lib.vault.Vault;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.Sound;
|
|
|
|
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;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
2022-03-28 19:56:57 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2021-12-21 04:57:29 +00:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
public class GUI_Listener implements Listener {
|
|
|
|
|
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.plugin;
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onInventoryClick(InventoryClickEvent e) {
|
|
|
|
Player player = (Player) e.getWhoClicked();
|
2022-03-28 19:56:57 +00:00
|
|
|
JavaPlugin plugin = Main.plugin;
|
|
|
|
if (e.getInventory() == null) return;
|
|
|
|
if (e.getCurrentItem() == null) return;
|
|
|
|
for (Object gui : Main.guiHashMap.values()) {
|
|
|
|
if (player.getOpenInventory().getTitle().equals(Replace.replace(prefix, GUICode + gui.GUI_Name))
|
|
|
|
|| (Main.PaPi && player.getOpenInventory().getTitle().equals(Replace.replace(prefix, player, GUICode + gui.GUI_Name)))) {
|
|
|
|
e.setCancelled(true);
|
|
|
|
for (Slot slot : gui.GUI_Slots) {
|
|
|
|
if (e.getSlot() != slot.Slot) continue;
|
2022-04-06 18:21:19 +00:00
|
|
|
if (e.getCurrentItem().getType() == ItemVersion.getHead() || e.getCurrentItem().getType() == Material.valueOf(slot.Item.toUpperCase().replace(".", "_"))) {
|
|
|
|
if (!slot.Perm
|
|
|
|
|| player.hasPermission("commandgui.gui." + gui.Command_Command + ".slot." + (slot.Slot + 1))
|
|
|
|
|| player.hasPermission("commandgui.gui." + gui.Command_Command + ".slot." + (slot.Slot + 1) + ".use")
|
|
|
|
|| player.hasPermission("commandgui.admin")) {
|
|
|
|
if (!slot.Enable) continue;
|
|
|
|
if (!e.getCurrentItem().getItemMeta().getDisplayName().equals(Replace.replace(prefix, slot.Name))) continue;
|
2022-03-28 19:56:57 +00:00
|
|
|
if (slot.Cost_Enable) {
|
|
|
|
if (slot.Command_Enable || slot.Message_Enable || slot.OpenGUI_Enable || slot.ServerChange) {
|
|
|
|
if (!Vault.buy(prefix, player, slot.Price)) {
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
player.closeInventory();
|
|
|
|
}
|
|
|
|
}.runTaskLater(plugin, 1L);
|
|
|
|
player.sendMessage(SelectMessages.No_money);
|
2022-04-06 18:21:19 +00:00
|
|
|
if (SelectConfig.Sound_NoMoney_Enable && SelectConfig.Sound_Enable)
|
|
|
|
player.playSound(player.getLocation(), SelectConfig.Sound_NoMoney, 3, 1);
|
2022-03-28 19:56:57 +00:00
|
|
|
} else {
|
|
|
|
player.sendMessage(SelectMessages.Buy_msg.replace("[itemname]", Replace.replace(prefix, slot.Name))
|
|
|
|
.replace("[price]", slot.Price + " " + SelectConfig.Currency));
|
|
|
|
execute(slot, player, e, gui);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else execute(slot, player, e, gui);
|
2022-04-06 18:21:19 +00:00
|
|
|
} else player.sendMessage(SelectMessages.NoPermissionForItem.replace("[item]", Replace.replace(prefix, slot.Name))
|
2022-03-28 19:56:57 +00:00
|
|
|
.replace("[perm]", "commandgui.gui." + gui.Command_Command + ".slot." + (slot.Slot + 1)));
|
2022-04-06 18:21:19 +00:00
|
|
|
}
|
2022-03-28 19:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-21 04:57:29 +00:00
|
|
|
|
2022-03-28 19:56:57 +00:00
|
|
|
private static void execute(Slot slot, Player player, InventoryClickEvent e, Object gui) {
|
|
|
|
if (slot.Command_Enable) command(slot, player);
|
|
|
|
if (slot.OpenGUI_Enable) openGUI(slot, player);
|
|
|
|
if (slot.Message_Enable) message(slot, player);
|
|
|
|
if (slot.ServerChange) serverChange(slot, player);
|
|
|
|
if (slot.SetConfigEnable) setConfig(slot, player, e);
|
|
|
|
if (SelectConfig.Sound_Enable && SelectConfig.Sound_Click_Enable) sound(slot, player, gui);
|
|
|
|
}
|
2021-12-21 04:57:29 +00:00
|
|
|
|
2022-03-28 19:56:57 +00:00
|
|
|
private static void command(Slot slot, Player player) {
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
player.closeInventory();
|
|
|
|
}
|
|
|
|
}.runTaskLater(plugin, 1L);
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (slot.Command_BungeeCommand) {
|
|
|
|
if (SelectConfig.Bungee) {
|
|
|
|
for (String cmd : slot.Command) {
|
|
|
|
Bungee_Sender_Reciver.sendToBungee(player, cmd.replace("[player]", player.getName()), slot.CommandAsConsole);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
send.console(prefix + " §4To use bungee commands, enable the Bungee option in the config.");
|
|
|
|
send.player(player, prefix + " §4To use bungee commands, enable the Bungee option in the config.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
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
|
|
|
|
2022-03-28 19:56:57 +00:00
|
|
|
private static void openGUI(Slot slot, Player player) {
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
player.closeInventory();
|
|
|
|
}
|
|
|
|
}.runTaskLater(plugin, 1L);
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
OpenGUI.openGUI(player, Main.guiHashMap.get(slot.OpenGUI), slot.OpenGUI);
|
|
|
|
}
|
|
|
|
}.runTaskLater(plugin, 2L);
|
|
|
|
}
|
2021-12-21 04:57:29 +00:00
|
|
|
|
2022-03-28 19:56:57 +00:00
|
|
|
private static void message(Slot slot, Player player) {
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
player.closeInventory();
|
|
|
|
}
|
|
|
|
}.runTaskLater(plugin, 1L);
|
|
|
|
for (String msg : slot.Message) {
|
|
|
|
if (Main.PaPi) {
|
|
|
|
if (slot.Cost_Enable) {
|
|
|
|
player.sendMessage(Replace.replacePrice(prefix, player, msg, slot.Price + " " + SelectConfig.Currency));
|
|
|
|
} else player.sendMessage(Replace.replace(prefix, player, msg.replace("[prefix]", prefix)));
|
|
|
|
} else {
|
|
|
|
if (slot.Cost_Enable) {
|
|
|
|
player.sendMessage(Replace.replacePrice(prefix, msg, slot.Price + " " + SelectConfig.Currency));
|
|
|
|
} else player.sendMessage(Replace.replace(prefix, msg.replace("[prefix]", prefix)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-21 04:57:29 +00:00
|
|
|
|
2022-03-28 19:56:57 +00:00
|
|
|
private static void serverChange(Slot slot, Player player) {
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
player.closeInventory();
|
|
|
|
}
|
|
|
|
}.runTaskLater(plugin, 1L);
|
|
|
|
send.player(player, SelectMessages.onServerChange.replace("[server]", slot.ServerChangeServer));
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
ServerChange.send(player, slot.ServerChangeServer);
|
|
|
|
}
|
|
|
|
}.runTaskLater(Main.plugin, 20L);
|
|
|
|
}
|
2021-12-21 04:57:29 +00:00
|
|
|
|
2022-03-28 19:56:57 +00:00
|
|
|
private static void setConfig(Slot slot, Player player, InventoryClickEvent e) {
|
|
|
|
File config = new File(slot.ConfigFilePath);
|
|
|
|
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
2021-12-21 04:57:29 +00:00
|
|
|
/*if (slot.ConfigChatInput){
|
|
|
|
ConfigChat.EditChat.put(player, slot.ConfigOptionPath);
|
|
|
|
player.sendMessage(DefaultValue.SettingsGUIchatSet.replace("[setting]", "Shop Name Chest small"));
|
|
|
|
player.sendMessage(DefaultValue.SettingsGUIchatCancel);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
*/
|
2022-03-28 19:56:57 +00:00
|
|
|
if (e.getClick() == ClickType.LEFT) {
|
|
|
|
if (slot.ConfigOptionPremat.equals("String")) {
|
|
|
|
yamlConfiguration.set(slot.ConfigOptionPath.replace("/", "."), slot.ConfigStringValueLeft);
|
|
|
|
} else if (slot.ConfigOptionPremat.equals("Boolean")) {
|
|
|
|
yamlConfiguration.set(slot.ConfigOptionPath.replace("/", "."), slot.ConfigBooleanValueLeft);
|
|
|
|
} else if (slot.ConfigOptionPremat.equals("Integer")) {
|
|
|
|
yamlConfiguration.set(slot.ConfigOptionPath.replace("/", "."), slot.ConfigIntegerValueLeft);
|
|
|
|
} else if (slot.ConfigOptionPremat.equals("Double")) {
|
|
|
|
yamlConfiguration.set(slot.ConfigOptionPath.replace("/", "."), slot.ConfigDoubleValueLeft);
|
|
|
|
} else if (slot.ConfigOptionPremat.equals("List")) {
|
|
|
|
yamlConfiguration.set(slot.ConfigOptionPath.replace("/", "."), slot.ConfigListValueLeft);
|
|
|
|
} else {
|
|
|
|
player.sendMessage("§cCheck the Option §6SetConfig/Option/Premat"); //todo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (e.getClick() == ClickType.RIGHT) {
|
|
|
|
if (slot.ConfigOptionPremat.equals("String")) {
|
|
|
|
yamlConfiguration.set(slot.ConfigOptionPath.replace("/", "."), slot.ConfigStringValueRight);
|
|
|
|
} else if (slot.ConfigOptionPremat.equals("Boolean")) {
|
|
|
|
yamlConfiguration.set(slot.ConfigOptionPath.replace("/", "."), slot.ConfigBooleanValueRight);
|
|
|
|
} else if (slot.ConfigOptionPremat.equals("Integer")) {
|
|
|
|
yamlConfiguration.set(slot.ConfigOptionPath.replace("/", "."), slot.ConfigIntegerValueRight);
|
|
|
|
} else if (slot.ConfigOptionPremat.equals("Double")) {
|
|
|
|
yamlConfiguration.set(slot.ConfigOptionPath.replace("/", "."), slot.ConfigDoubleValueRight);
|
|
|
|
} else if (slot.ConfigOptionPremat.equals("List")) {
|
|
|
|
yamlConfiguration.set(slot.ConfigOptionPath.replace("/", "."), slot.ConfigListValueRight);
|
|
|
|
} else {
|
|
|
|
player.sendMessage("§cCheck the Option §6SetConfig/Option/Premat"); //todo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
yamlConfiguration.save(config);
|
|
|
|
} catch (IOException tac) {
|
|
|
|
tac.printStackTrace();
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2022-03-28 19:56:57 +00:00
|
|
|
private static void sound(Slot slot, Player player, Object gui) {
|
|
|
|
if (slot.CustomSound_Enable) {
|
|
|
|
if (!slot.CustomSound_NoSound) {
|
|
|
|
try {
|
|
|
|
player.playSound(player.getLocation(), Sound.valueOf(slot.CustomSound_Sound.toUpperCase().replace(".", "_")), 3, 1);
|
2021-12-21 04:57:29 +00:00
|
|
|
|
2022-03-28 19:56:57 +00:00
|
|
|
} catch (Exception e1) {
|
|
|
|
send.console("§4\n§4\n§4\n" + SelectMessages.SoundNotFound.replace("[prefix]", prefix)
|
|
|
|
.replace("[sound]", "§6GUI: §e" + Replace.replace(prefix, gui.GUI_Name) + "§r §6Slot: §e" + slot.Slot + " §6CustomSound: §9" + slot.CustomSound_Sound));
|
|
|
|
player.playSound(player.getLocation(), SelectConfig.Sound_Click, 3, 1);
|
2021-12-21 04:57:29 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-28 19:56:57 +00:00
|
|
|
} else player.playSound(player.getLocation(), SelectConfig.Sound_Click, 3, 1);
|
2021-12-21 04:57:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|