.getSlot() 32-35 (inside inv) registering as Quickbar (0-8)??

Discussion in 'Plugin Development' started by qwiso, May 17, 2013.

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

    qwiso

    In my code, slots 32, 33, 34, 35 register .... what?!

    Code:
    public void onInv(InventoryClickEvent event){
     
        if (event.isRightClick()){
            if (event.getSlotType() == SlotType.QUICKBAR){
                if ((event.getCursor().getType() == Material.AIR) && (event.getCurrentItem().hasItemMeta())){
                    if(event.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("pocket")){
                       
                        ((Player) event.getWhoClicked()).sendMessage("Slot#: " +event.getSlot());
                        ((Player) event.getWhoClicked()).sendMessage("SlotType: " +event.getSlotType());
     
                    }
                }
            }
        }
    }
    I hope the .getDisplayName doesn't give away what I'm working on. :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. qwiso
    Use getRawSlot() if getSlotType() returns invalid stuff.

    And about your displayname, you'll get a NPE if the item doesn't have a displayname.
     
  3. Offline

    qwiso

    Digi yea I realized I had to use RawSlot and Slot ((>= 0) && (<= 8)) rather than SlotType because that seems to have very weird behavior between gametypes and the bottom right 4 container slots registering as quickbar...

    I also added nullchecks
     
Thread Status:
Not open for further replies.

Share This Page