help with gui

Discussion in 'Spigot Plugin Help' started by Britizz, Jan 13, 2020.

  1. Hi everyone, I made a plugin for a player gui/list but when i click on a skull nothing appens and i don't see my error help ?

    Code (Java):
        @EventHandler
        public void onClick (InventoryClickEvent event) {
            Inventory invc = event.getInventory();
            Player player = (Player) event.getWhoClicked();
            ItemStack current = event.getCurrentItem();
           
           
            if(invc.getName().equalsIgnoreCase("Admin Panel"))
            {
                event.setCancelled(true);
                if(current == null) return;
                if(current.getType() == Material.IRON_SWORD)
                {
                    Inventory inv = Bukkit.createInventory(null, 27, "Player list");
                   
                    byte invl = 0;
               
           
                    for (Player p : Bukkit.getOnlinePlayers())
                    {
                        ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1);
                        SkullMeta meta = (SkullMeta) skull.getItemMeta();
                        meta.setOwner(p.getName());
                        meta.setDisplayName(p.getName());
                        skull.setItemMeta(meta);
                       
                       
                        inv.setItem(invl, skull);
                        invl++;
                   
                        player.openInventory(inv);
                    if(invc.getName().equalsIgnoreCase("Player list"))
                    {
                        player.chat("ban Britizz");
                        if(current == null) return;
                        if(current.getType() == Material.SKULL_ITEM)
                        {
                            player.chat("ban Britizz");
                        }
                       
                    }
                    }
                   
                }
            }
                   
        }
     
  2. Well, you have nested your check for the head-item inside the if-statement that checks if the item is a sword. In other words, you first check if the current item is a sword and then you check as well if it's a player-head. The latter one will always be false, thus not the expected result
     
  3. Okay thank you i see my error now but i don't know how to correct the problem
     
  4. Well, simply move your check for the other inventory name to after the initial inventory name-check:

    Code (Java):
    if(invc.getName().equalsIgnoreCase("Admin Panel"))
    {
        // ...
    } else if(invc.getName().equalsIgnoreCase("Player list")) {
        // player list was clicked
    }
    Also, don't make your GUI dependent on the name (someone could just rename a chest and suddenly it's you that's getting banned)
     
  5. Instead of checking the name of the inventory they click in you need to get the inventory directly.
    Code (Java):
    if (e.getInventory().equals(inventory)) {
    Also, you are putting your if statement inside of the forloop so it never gets called when you click in the inventory.