Detect if a player walks

Discussion in 'Plugin Development' started by _Error, Jul 2, 2015.

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

    _Error

    I want to detect if a player walks from a block to another, PlayerMoveEvent is not the awnser i'm looking for, I'm looking for detecting is a player walks from a block to another.

    Thanks for your help.
     
  2. Offline

    Hawktasard

    @_Error
    Check if getTo().getBlock() is not at the same place as getFrom().getBlock() is.
     
    Maxx_Qc likes this.
  3. Yes, PlayerMoveEvent IS the answer you're looking for.
    Code:
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent event) {
        if ((int) event.getFrom().getX() != (int) event.getTo().getX() || (int) event.getFrom().getY() != (int) event.getTo().getY() || (int) event.getFrom().getZ() != (int) event.getTo().getZ()) { // Check if the X, Y or Z has changed as an integer, meaning they've changed blocks.
            // They moved a block.
        }
    }
    
    The reason I don't use getBlockX(), or compare getBlock(), etc. instead is because there's no need to use floor operations for something like this.
     
    Last edited: Jul 2, 2015
Thread Status:
Not open for further replies.

Share This Page