How to stop a player from pressing a button or tuning a note block?

Discussion in 'Plugin Development' started by Borch, Jan 21, 2011.

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

    Borch

    Hey,

    has anyone found out yet how to stop a player from interacting with things like buttons or note blocks? I tried cancelling pretty much everything there is with no success.

    Thanks!
     
  2. Offline

    Borch

    halp
     
  3. Offline

    JoeMaximum

    Just an idea, what about getting the bloc right clicked.
    Then if the rightclicked block is a noteblock, you cancel the action.

    Would that work?
     
  4. Offline

    Fifteen

    That might be possible by cancelling a BlockInteractEvent. This code hasn't been tested, but may work.

    Code:
    public void onBlockInteract(BlockInteractEvent event)
    {
            //Get the player
            Player p = (Player)event.getEntity();
            //Get the block
            Block b = event.getBlock();
            //If the player isn't op and is interacting with a button or a note block, cancel the event.
            if (!p.isOp() && b.getTypeId() == 77 || b.getTypeId() == 25)
                    event.setCancelled(true);
    }
     
  5. Offline

    Borch

    The problem is, onRightClick gets fired, but that event doesn't have a setCancelled() method.
    onBlockInteract() won't be fired when I right-click a note block. :-(
    --- merged: Jan 27, 2011 12:54 AM ---
    In case anyone is ever gonna need it:
    Code:
        @Override
        public void onBlockRightClick(BlockRightClickEvent event)
        {
            if (event.getBlockAgainst().getTypeId() == 25) {
                byte note = ((NoteBlock)event.getBlockAgainst().getState()).getNote();
                ((NoteBlock)event.getBlockAgainst().getState()).setNote((byte)((note + 24) % 25));
            }
        }
    Quite ugly huh?
     
Thread Status:
Not open for further replies.

Share This Page