[SOLVED] Can't cancel player opening both sides of a chest.

Discussion in 'Plugin Development' started by Taco, Jul 15, 2012.

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

    Taco

    For some reason, this code only seems to cancel the event when one side of the chest is clicked. The other side just opens as if the player wasn't hidden.

    Code:
        @EventHandler //Thanks to the source of VanishNoPacket for insight on this.
        public void onChestOpen(PlayerInteractEvent event)
        {
            Player p = (Player) event.getPlayer();
            if(plugin.vanished.contains(p.getName()))
            {
                Block b = event.getClickedBlock();
                if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && b != null)
                {
                    if(b.getState() instanceof Chest || b.getState() instanceof DoubleChest)
                    {
                        event.setCancelled(true);
                        Chest chest = (Chest) b.getState();
                        Inventory inv = chest.getBlockInventory();
                        p.openInventory(inv);
                        p.sendMessage(ChatColor.DARK_AQUA + "[MadMinerMech] Opening chest quietly.");
                    }
                 
                }
            }
        }
    Edit: It seems it doesn't prevent the right clicking of single chests either. Any insight?
     
  2. Offline

    Firefly

    I use event.getAction() == Action.RIGHT_CLICK_BLOCK, although this may not be the issue.
     
  3. Offline

    Taco

    It's not. I tried cancelling the event regardless of other conditions if they were vanished and that still yielded the same issue.

    Ahh, nevermind. I see how VanishNoPacket did it. I derped. They made another inventory, separate from the chest's inventory, and then used that to send to the player.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  4. Offline

    CorrieKay

    Creating another inventory.. Doesnt that make it impossible to edit the inventory while hidden?
     
  5. Offline

    evilmidget38 Retired Staff

    If you were to sync the inventories again, then it's possible to do.
     
  6. Offline

    CorrieKay

    Ah well, no easy way to do it, i guess!
     
  7. Offline

    Taco

    I did try to do this, but the chest inventories seem to have issues updating properly.
     
  8. Offline

    evilmidget38 Retired Staff

    I think there might be an inventory.update() method or something like that. I haven't done much with inventories.
     
  9. Offline

    Taco

    I tried going so far as to update every open chest (I kept them in a hashmap) every second with a timer as well as all player's inventories, but it still refused to properly update.
     
Thread Status:
Not open for further replies.

Share This Page