PlayerItemPickupEvent not called with full inventory?

Discussion in 'Plugin Help/Development/Requests' started by Anonomoose, Apr 29, 2015.

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

    Anonomoose

    Hi all,

    I'm looking how to make it so that when a player attempts to pick up items while their inventory is full, it alerts them of it so that they can empty their inventory. I assumed this would be fairly easy through using the PlayerItemPickupEvent, except I found that the event isn't called at all when the players inventory is full and they try to pick up the item (hopefully someone can prove me wrong).

    Is there any other event/method that is triggered when the inventory is full and the item pick up is cancelled?

    Thanks!
     
  2. Offline

    HungerCraftNL

    I created this method once to check free places:
    Code:
        /*
        * Created by Niels Hamelink
        * 19-04-2015 | 04:30
        */
        public int checkFree(Inventory inv, Material mat){
            int f = 0;
            int t = 0;
            for(int i = 0; i<inv.getSize(); i++){
                if(inv.getItem(i) == null){
                    f++;
                }
            }
            int m = mat.getMaxStackSize();
            t = f*m;
    
            for(ItemStack c : inv.getContents()){
                if(c != null){
                    if(c.getType().equals(mat)){
                        if(!c.hasItemMeta()
                                || (c.hasItemMeta() && c.getItemMeta().getDisplayName() == null) ){
                            int max = c.getMaxStackSize();
                            t = t + (max-c.getAmount());
                        }
                    }
                }
            }
            return t;
        }
    
    I think you'll need the PlayerPickupItemEvent to cancel the picking up.
     
  3. Offline

    Msrules123

    I believe it does... Just set ignoreCancelled to false.
     
  4. Offline

    Konato_K

  5. Offline

    SuperOriginal

  6. Offline

    Msrules123

    I use Spigot for my builds, it's default is true. Sometimes users may be using another alternative, so I just throw suggestions that I see could work, depending on the build.
     
  7. Offline

    SuperOriginal

    @Msrules123 Well, theoretically this forum section is for Bukkit only, but we all know that's not always the case so I see where you're coming from.
     
  8. Offline

    HungerCraftNL

  9. Offline

    Anonomoose

    Not what I was asking for at all, haha.

    I'll try playing around with ignoreCancelled and see if that makes any difference.

    Yeah no luck, the event doesn't seem to be called at all regardless of what ignoreCancelled is set to.
     
    Last edited by a moderator: May 4, 2015
  10. Offline

    HungerCraftNL

    Sorry my bad, you could try the InventoryPickupItemEvent
     
  11. Offline

    Konato_K

  12. Offline

    Anonomoose

    Yeah, that wouldn't work.

    I'm gonna assume this just isn't possible :/
     
  13. Offline

    567legodude

    @Anonomoose I have also had this problem before, I needed a way to fire the event even if their inventory was full. I don't think that there is a way to fire the event if its full, because it fires when the item is picked up, and if your inventory is full, then you can't pick up anything.
     
Thread Status:
Not open for further replies.

Share This Page