stopping players from getting item from "false" inventory?

Discussion in 'Plugin Development' started by cowchickcen, May 24, 2015.

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

    cowchickcen

    So, I am making a RP plugin and I am creating a skill tree. But the problem is, when the user has the "false" inventory open to upgrade a skill and they drop the item, they get that item in their inventory.

    Here is the code that I used to try and stop it. But it still happens
    Code:
        @EventHandler
        public void onItemDrop(PlayerDropItemEvent e){
            e.setCancelled(true);
        }
     
    Last edited: May 24, 2015
  2. Offline

    MisterErwin

    Shortninja66 and seanliam2000 like this.
  3. Offline

    Shortninja66

    @MisterErwin All you have to do is set the event as cancelled with the InventoryClickEvent because if you click on an item in the inventory it is in their "hand". When you cancel the event, the item is put back no matter what.
     
  4. That won't work at all.
    The best way (for me) is create a class which extends InventoryHolder, when you create the inventory do this:
    Code:
    Inventory inventory = Bukkit.createInventory(new CustomHolder(), size, name);
    
    With a inventory created like that we could just do
    Code:
    if(inventory.getHolder() instanceof CustomHolder) {
       event.setCancelled(true);
    }
    
     
  5. Offline

    cowchickcen

    @MaTaMoR_
    So when I create a class that extends InventoryHolder, I get a error. Here is the code

    Code:
    public class CustomHolder extends InventoryHolder{
    
    }
    
    Edit -
    But I then went ahead and implemented InventoryHolder to CustomHolder.

    Code:
    public class CustomHolder implements InventoryHolder{
    
        @Override
        public Inventory getInventory() {
            // TODO Auto-generated method stub
            return null;
        }
    
    }
    It seems to be working now
     
    Last edited: May 25, 2015
  6. You have to implement all abstract methods :
    Code:
    public class CustomHolder extends InventoryHolder{
    
    private final int size;
    
    public CustomHolder(int size) {
       this.size = size;
    }
    
    @Override
    public Inventory getInventory() {
       return Bukkit.createInventory(null, size);
    }
    }
    
    CustomHolder holder = new CustomHolder(9);
    
     
    Last edited: May 25, 2015
Thread Status:
Not open for further replies.

Share This Page