Best way to prevent players from putting things into chests

Discussion in 'Plugin Development' started by Baba43, Aug 12, 2013.

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

    Baba43

    Hi,

    I'm looking for the right event to prevent people from putting a specific item type into any kind of containers

    What is the way to go?
     
  2. Offline

    xTrollxDudex

    Baba43
    Listen for inventory click event, check if the top inventory is a chest.
     
  3. Offline

    Baba43

    But I would also need to listen for shift then.. thats why I'm wondering why there is no "InventoryTransactionEvent" or something like that :(
     
  4. Offline

    xTrollxDudex

    Baba43
    Oh but there's InvenoryInteractEvent and InventoryDragEvent
     
  5. Offline

    Baba43

    I don't get any item from the InventoryInteractEvent.
    Is there really no more comfortable way to handle this?
     
  6. There is a InventoryItemMoveEvent.
    You can use that :>

    Baba43
     
  7. Offline

    Baba43

    For people that might find this thread I'm doing this now and it seems to work fine:

    Code:java
    1. @EventHandler(ignoreCancelled = true)
    2. public void onPlayerInventoryMove(InventoryClickEvent event) {
    3. ItemStack item = event.getCurrentItem();
    4. if(item != null && (item.getType() == Material.ENDER_PORTAL_FRAME || item.getType() == Material.EYE_OF_ENDER)) {
    5. if(!(event.getInventory().getHolder() instanceof Player)) {
    6. event.setCancelled(true);
    7. }
    8. }
    9. }
     
Thread Status:
Not open for further replies.

Share This Page