How to test what block is under a player?

Discussion in 'Plugin Development' started by ledship, Mar 14, 2014.

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

    ledship

    Hi, I need to see what block is under a player when they move and test to see if its a certain block, this is all Ive got right now:


    Code:java
    1. @EventHandler
    2. public void onPlayerMove(PlayerMoveEvent event) {
    3. Player player = event.getPlayer();
    4. Block block = player.getLocation().getBlock();
    5. Bukkit.broadcastMessage("Players location: " + block);
    6. if(block.equals()) {
    7.  
    8. }
    9. }



    But it returns the block where the player is standing not the one below them so how to I get it to return the block under them and test to see if its a certain block? please help
     
  2. Offline

    Bionicrm Retired Staff

    Get the block relative to the one they're standing on... so something like Block.getRelative(BlockFace.DOWN), I think. Also the code is not showing...
     
  3. Offline

    ledship

    it should show now.

    thanks that worked, but how would I test what block it is?

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

    Bionicrm Retired Staff

    ledship That method ("getRelative()") should return a Block.
     
  5. Offline

    ledship

    it does but how would I see what the block is? like this?
    Code:java
    1. @EventHandler
    2. public void onPlayerMove(PlayerMoveEvent event) {
    3. Player player = event.getPlayer();
    4. Block block = player.getLocation().getBlock();
    5. Bukkit.broadcastMessage("Players location: " + block);
    6. Block block1 = block.getRelative(BlockFace.DOWN);
    7. Bukkit.broadcastMessage("Block under player: " + block1);
    8. if(block1.getType().equals(Material.GLOWSTONE)) {
    9. Bukkit.broadcastMessage("SUCCESS!");
    10. }
    11. }
     
  6. Offline

    Bionicrm Retired Staff

    Did you test it? Test it before you come here :p
     
    Mattkx4 and MrAwellstein like this.
  7. Offline

    ledship

    It worked, thanks for your help
     
  8. Offline

    MrAwellstein

    Oh heyyy TJ
     
Thread Status:
Not open for further replies.

Share This Page