Cancelling a chest open event, having some trouble...

Discussion in 'Plugin Development' started by willeb96, Dec 8, 2012.

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

    willeb96

    When I cancel an IneventoryOpenEvent the chest stays open and I can't figure out a way of closing it, how do I do it?

    Thanks :)
     
  2. Offline

    Tzeentchful

    There is two ways i can think of to solve this problem.
    The first and most simple is to use the onInteract event instead of the inventoryOpen event. And then simply check if the player is right clicking a chest.

    Code:
        @EventHandler(priority = EventPriority.NORMAL)
        public void onPlayerInteract(PlayerInteractEvent event) {
            if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && event.getClickedBlock().getType().equals(Material.CHEST)){
                event.setCancelled(true);
            }
        }
    The other way would be to send a 0x36 packet to the client with the coordinates of the chest and the second bit set to 0 (0 is closed, 1 is open) and just set the first bit to 1 (the first bit has no relevance when dealing with chests).
    for more information on the 0x36 packet have a look here.
     
  3. Offline

    willeb96

    Thanks, the playerinteract event way worked :D
     
Thread Status:
Not open for further replies.

Share This Page