Solved GUI problem

Discussion in 'Spigot Plugin Development' started by TryHart, Jun 13, 2021.

  1. I would want this to work only for the slot 11, but it does for every other slot as well.
    Code (Text):
    public class ClickEventDevice implements Listener {
       

        @EventHandler
        public void onClick(InventoryClickEvent e) {
            if(e.getClickedInventory().getTitle().equalsIgnoreCase(ChatColor.AQUA + "Device")){
            Player player = (Player) e.getWhoClicked();
            Economy econ = GUIPluginDevice.getEconomy();
                if (e.getSlot() == 11) {
                   if (!player.hasPermission("uhc.mlg")){
                    EconomyResponse response = econ.withdrawPlayer(player, 0);
                      if (response.transactionSuccess()) {
                        LuckPermsProvider.get().getUserManager().modifyUser(player.getUniqueId(), user -> {
                            // Add the permission
                            user.data().add(Node.builder("uhc.mlg").build());
                        });
                player.sendMessage(ChatColor.GREEN + "Payment Succesfull");
                player.playSound(player.getLocation(), Sound.LEVEL_UP, 1f, 1f);
                    }
                 }
                    else {
                player.sendMessage(ChatColor.RED + "Payment Cancelled");
                player.playSound(player.getLocation(), Sound.AMBIENCE_CAVE, 1f, 1f);
                    }
                }
                    else {
                player.sendMessage(ChatColor.RED + "Payment Cancelled");
                player.playSound(player.getLocation(), Sound.AMBIENCE_CAVE, 1f, 1f);
                    }
                e.setCancelled(true);
            }
        }
    }
    Does anyone know any way to fix it? thx
     
  2. If it is not slot 11, return; do it