Deny to put stuff on a chest

Discussion in 'Plugin Development' started by CraftBang, Nov 6, 2013.

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

    CraftBang

    How would I like make that yuo can't put TNT in a chest?
    There are 3 ways :
    Way 1 :
    - Click on the item (so than you have it in your hand) and put it in the chest
    Way 2:
    - Shift click on the item
    Way 3:
    Put item liek on item slot 1 (so if yuo press 1 you go to that item)
    Open up the chest, get on a slot in the chest with your mouse, and press 1.

    Which events should I use?, I thought something like oninventory click but I only want it if the inventory is a chest, a furnace or a brewing stand
     
  2. Offline

    sgavster

    PHP:
    @EventHandler
    public void onClick(InventoryClickEvent e) {
    if(
    e.getCurrentItem() != null) {
    if(
    e.getCurrentItem().getType() != null) {
    if(
    e.getCurrentItem().getType() == Material.TNT) {
    e.setCancelled(true);
    }
    }
    }
    }
     
    CraftBang likes this.
  3. Offline

    sd5

    CraftBang
    Yes I would use the InventoryClickEvent, you can check whether the inventory is a chest with:
    Code:java
    1. if(event.getInventory().getHolder() instanceof Chest) {
    2. ...
    3. }

    Maybe also try to use some other events like the InventoryDragEvent, then check for the item and cancel the event if it's TNT
     
    CraftBang likes this.
Thread Status:
Not open for further replies.

Share This Page