Detect when a player steps on a stone pressure plate that is on a redstone block

Discussion in 'Plugin Development' started by JohnXTRP, Dec 8, 2013.

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

    JohnXTRP

    I want to detect if a player is triggering a stone pressure plate on a redstone block.
    My code seems fine but is not working:
    Code:java
    1. public class MyPluginListener implements Listener {
    2. @EventHandler
    3. public void onPlayerInteract(PlayerInteractEvent event) {
    4. if (event.getAction().equals(Action.PHYSICAL)) {
    5. if (event.getClickedBlock().getType().equals(Material.STONE_PLATE)) {
    6. Location location = event.getClickedBlock().getLocation();
    7. location.setY(location.getY()-1);
    8. if(location.getBlock().equals(Material.REDSTONE_BLOCK)){
    9. Player player = event.getPlayer();
    10. player.sendMessage("You are on a stone pressure plate on a redstone block.");
    11. }
    12. }
    13. }
    14. }
    15. }
     
  2. Offline

    Njol

    You forgot .getType() after location.getBlock() - You're currently comparing a block to a Material.

    BTW: you can simply use event.getClickedBlock().getRelative(BlockFace.DOWN) to get the block below the pressure plate.
     
    JohnXTRP likes this.
  3. Offline

    JohnXTRP

    That worked out great! Thanks alot =)
     
Thread Status:
Not open for further replies.

Share This Page