stop player from open chest

Discussion in 'Plugin Development' started by mcgamer99, Jul 5, 2012.

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

    mcgamer99

    How I set that when a player try to open the chest, the chest doesn't opening(stop the player from open the chest)?
    Like: if there was a chest event, set it to cancelled.
     
  2. try the playerinteractevent, and see if he is right clicking a chest
     
    mcgamer99 likes this.
  3. Offline

    LucasEmanuel

    This is what i would do :)

    You might have to edit the code, i havent checked the docs.
    Code:
    public void blockChestInterract(PlayerInteractEvent event) {
        if(event.getAction(ACTION.RIGHT_CLICK_BLOCK) {
            if(event.getBlock().getType().equals(Material.CHEST) event.setCanceled(true);
        }
    }
     
    mcgamer99 likes this.
  4. Just a little change to your code:

    Code:
    public void blockChestInterract(PlayerInteractEvent event) {
        if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if(event.getBlock().getType().equals(Material.CHEST) event.setCanceled(true);
        }
    }
     
    mcgamer99 likes this.
  5. Offline

    Jnorr44

    Code:
    public void blockChestInterract(PlayerInteractEvent event) {
    if (!event.isCancelled()){ 
        if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if(event.getBlock().getType().equals(Material.CHEST){
                event.setCanceled(true);
          }   
        }
    } 
    }
     
    mcgamer99 likes this.
  6. Offline

    LucasEmanuel

    Haha yes, but as i pretty much said, i just grabbed it out of my head and hadnt tested it ;)
     
  7. Offline

    pd9937

    I'd rather do:
    Code:
    public void onInventoryOpen(InventoryOpenEvent event) {
       if (event.getInventory().getType() == InventoryType.CHEST) {
          event.setCancelled(true);
       }
    }
     
    Donald Scott, Firefly and mcgamer99 like this.
Thread Status:
Not open for further replies.

Share This Page