Darker Minecraft
Darker Minecraft

Reputation: 25

Clicking on item two times instead on one

I got a gui and when I click on material coal I need to click on it again to get it to activate the code. Here is my inventoryclickevent

    String stripname = ChatColor.stripColor(e.getClickedInventory().getName());
    if(stripname.equals("Upgrade Spawner".toUpperCase())) 
    {
        if(e.getCursor()!=null) 
        {
            if(e.getCursor().getType()!=null) 
            {
                Material item = e.getCursor().getType();
                if(item.equals(Material.STAINED_GLASS_PANE)) e.setCursor(null);
                else if(item.equals(Material.COAL))
                {
                    if(checkBalance(e.getWhoClicked(), config.getInt("Coal Cost"))) 
                    {
                        takeAwayMoney(e.getWhoClicked(), config.getInt("Coal Cost"));
                        e.getWhoClicked().closeInventory();
                        e.getWhoClicked().sendMessage(ChatColor.GREEN + "Iron Golems now drop coal!");
                    } else 
                    {
                        e.getWhoClicked().closeInventory();
                        e.getWhoClicked().sendMessage(ChatColor.RED + "You do not have the requirment amount of money! You need " + getMoneyNeeded(e.getWhoClicked(), config.getInt("Coal Cost")) + " more!");
                    }
                }
            }
        }
    }

Upvotes: 0

Views: 55

Answers (1)

GotoFinal
GotoFinal

Reputation: 3695

Because getCursor returns item that player is holding in the cursor and you are checking if it is not null - so first click will move that item to cursor, and then on next click cursor will not be null and code will execute.
Use getCurrentItem instead.

Upvotes: 1

Related Questions