Check if player is touching iron bars

Discussion in 'Plugin Development' started by Chipmunk9998, Feb 8, 2012.

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

    Chipmunk9998

    Hey, I'm writing a plugin for a my server that hurts players if they touch the iron bars block with their body. Is there any way I can do this?
     
  2. Offline

    Wundark

    You could use onPlayerMove. Then get the player and check for the block the player is standing in. As iron bars are thin but you can walk into their block space you should be able to get the block they are standing in.
     
  3. Offline

    MrMag518

  4. Offline

    Chipmunk9998

    How would I do this?
     
  5. Offline

    Wundark

    Something like this. Its untested so don't rely on it.

    PHP:
    public void onPlayerMove(PlayerMoveEvent e){
        if(
    e.getTo().getBlock().getType() == Material.IRON_FENCE){
            
    e.getPlayer().damage(1);
        }
    }
     
  6. Offline

    Chipmunk9998

    I know how to do that, and it only works if your legs are touching it, not your entire body. I tried a few other ways of checking but none of them worked, so do you know a way that I could do this?
     
  7. Offline

    Aetherspawn

    Add 1 to the Z position of the player and check the block there too.
     
  8. no, thats wrong, you need to add 1 to the Y postion
     
    colony88 likes this.
Thread Status:
Not open for further replies.

Share This Page