Solved Can't detect if player stands on pressure plate.

Discussion in 'Plugin Development' started by CrazyGuy3000, Nov 2, 2013.

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

    CrazyGuy3000

    Hi there,
    this code doesn't seem to work, can somebody please tell me why? (I know im not putting anything inside for the thing to do but when I do it doesn't work either)

    Code:
    @EventHandler
    public void onIneract(PlayerInteractEvent e){
        if(e.getAction() == Action.PHYSICAL){
            if(e.getClickedBlock().getType() == Material.STONE_PLATE && e.getClickedBlock().getRelative(BlockFace.DOWN).getType() == Material.STONE){
                //do stuff
            }
        }
    }
     
  2. Offline

    iBCoLLiN

    Code:java
    1. @EventHandler
    2. public void onPlayerMove(PlayerMoveEvent e) {
    3. Player p = (Player) e.getPlayer();
    4. if (e.getTo().getBlock().getRelative(BlockFace.DOWN).getType() == Material.STONE_PLATE) {
    5. //do stuff
    6. }
    7.  
     
  3. Offline

    CrazyGuy3000

    Can you show some code where I can check the block below the stone_plate too ? Sorry im not to sure about minusing a X cord .-.
     
  4. Offline

    amhokies

  5. Offline

    CrazyGuy3000

  6. Offline

    TheUpdater

    Player p = e.getPlayer();
    Block b = p.getLocation().getBlock();
    Block b1 = b.getRelative(BlockFace.DOWN);
    if (b1.getType() == Material.STONE) {
     
  7. Offline

    hanahouhanah

    This
    Code:java
    1. @EventHandler
    2. public void onIneract(PlayerInteractEvent e){
    3. if(e.getAction() == Action.PHYSICAL){
    4. if(e.getClickedBlock().getType() == Material.STONE_PLATE && e.getClickedBlock().getRelative(BlockFace.DOWN).getType() == Material.STONE){
    5. //do stuff
    6. }
    7. }
    8. }

    Is right, but don't use Action.PHYSICAL. You could get rid of that line.
    Try this:
    Code:java
    1. @EventHandler
    2. public void onIneract(PlayerInteractEvent e){
    3. if(e.getClickedBlock().getType() == Material.STONE_PLATE && e.getClickedBlock().getRelative(BlockFace.DOWN).getType() == Material.STONE){
    4. //do stuff
    5. }
    6. }

    However, if a player clicks (right or left) on the pressure plate and blockface.down is stone, it'll still trigger the event. So you should check if the player right or left clicked the pressure plate.
     
  8. Offline

    CrazyGuy3000

    hanahouhanah
    Thanks, I fixed up my code to run off this.

    TheUpdater
    That code doesn't look right somehow, strange. Anyway I got this working

    If anybody wants the code posted please PM me.
     
Thread Status:
Not open for further replies.

Share This Page