InventoryClickEvent Help

Discussion in 'Plugin Development' started by Ambamore2000, May 3, 2015.

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

    Ambamore2000

    http://pastebin.com/usVLBHpw

    I have struggled with this for ~20 minutes straight finding no solution. I know WHY it doesn't work, but can't seem to figure out HOW to fix it. Basically, there's no error. It's just something Java does that is pissing me off.

    What I want the event to do? I want it so when you click your head on the inventory, if it is empty and your cursor is 1 piece of glass, it sets your cursor to nothing and puts the glass onto your helmet. Now, the issue here is being that the helmet depends on the cursor item, so when I set the cursor to null, the helmet also becomes null. I need a solution to bypass this somehow.
     
  2. Offline

    _Cookie_

    Check if the slot is null first, and have your registered your events?
     
  3. Offline

    Ambamore2000

    ... Have you read my issue.
     
  4. check if inventory type equals InventoryType.PLAYER
    slot 5 = helmet, slot 6 = chestplate , slot 7 = leggings and slot 8 = boots
    player.getInventory().setHelmet(item);
     
    Last edited: May 3, 2015
  5. Offline

    Ambamore2000

    But thats not the issue...
     
  6. I didnt read the end , try adding a delay before set the cursor null & player.getInventory().setHelmet(item) try with that instead of setting the current item.
     
  7. Offline

    Ambamore2000

    Doesn't work. Player drops item after setting the delay.
     
  8. Offline

    sourcec0de

    Try this to make the player wear the helmet:

    Code:
    public void onInventoryClick(InventoryClickEvent event) {
        Player player = event.getPlayer();
        PlayerInventory inv = player.getInventory();
    ItemStack item = new ItemStack(Material.getMaterial.DIAMOND_HELMET, 1, (short) amount);
    inv.setItem(103, item);
    event.setCancelled(true);
    //the 103 is the helmet slot. This will make the user wear the helmet.
    }
    And use event.setCancelled(true), instead of setting the cursor to null.
     
  9. Offline

    Ambamore2000

    Does not work. I didn't even expect it to to be honest.
     
  10. Offline

    Zombie_Striker

    Did you debug? What part does it get stuck at? Does it even register if you click that slot? Do you know for sure that the slot you clicked is for the helmet?
     
  11. Offline

    Konato_K

    @Ambamore2000 Why don't you set the helmet with #setHelmet(ItemStack)?
     
  12. Offline

    RawCode

    before wasting 20 minutes, add debug messages to code in order to track all fields at play.

    you dont ever know is very first condition passed or not...
     
  13. Offline

    Ambamore2000

    Yes, It goes all the way through, Yes, and Yes.
    Tried that already.
    Already have... It goes all the way through.
     
  14. Offline

    Zombie_Striker

    @Ambamore2000 I also asked if you debugged. Is slot 39 the slot you wanted? Is the curserItem Air? Is the new ItemStack that you created have ItemMeta/ exists?

    [edit] From what your code looks like, you have not either updated your code, or you have not implemented the .setHelmet(); Can you show us what you have now?
     
Thread Status:
Not open for further replies.

Share This Page