Solved detect item not working

Discussion in 'Plugin Development' started by Ko7R3X, Jun 20, 2018.

Thread Status:
Not open for further replies.
  1. Offline

    Ko7R3X

    When i click to "SPEED" in inventory i must have 8 gold in 1st slot in EQ [toolbar], or line not work..
    When i click to "SPEED" in inventory i wanna have 8+ gold whatever where it is and line work
    (maybe it's fault of item dectect)

    Please help

    Code:
    @EventHandler
        public void onInventoryClick(InventoryClickEvent e) {
            if (!e.getInventory().getName().equalsIgnoreCase(effectmenu.getName())) return;
            if(e.getCurrentItem().getItemMeta().getDisplayName().contains("CLOSE")) {
                e.setCancelled(true);
                e.getWhoClicked().closeInventory();
            }
            if(e.getCurrentItem().getItemMeta().getDisplayName().contains("SPEED")) {
                e.setCancelled(true);
                for(ItemStack item : e.getWhoClicked().getInventory()) {
                    if(item.getType() == Material.GOLD_INGOT && item.getAmount() == 8 ) {
                        e.getWhoClicked().sendMessage("Hello");
                        e.getWhoClicked().getInventory().removeItem(new ItemStack(Material.GOLD_INGOT, 8)); return ;
                       
                    }
                }
                   
            }
        }
     
  2. Offline

    CommonSenze

    @Ko7R3X

    You must realize
    Code:java
    1. e.getInventory()
    is not the same as
    Code:java
    1. e.getWhoClicked().getInventory()


    In your for loop make sure you do
    Code:java
    1. e.getInventory()


    Also, please define your problem better. It currently isn't making much sense to me. Is it the player that needs to have the item in THEIR inventory or is it suppose to be in the top inventory?
     
  3. Offline

    Ko7R3X

    so what should i do to make 8 items remove when i have it, and next make anything, for example: e.getWhoClicked().sendMessage("Hello");
     
  4. Offline

    CommonSenze

    @Ko7R3X
    I did answer this exact question in this thread on how to remove certain amount of items.

    and while you're removing the 8 items just do everything else you want to do.
     
Thread Status:
Not open for further replies.

Share This Page