onPressurePlatePressed() equivelent

Discussion in 'Plugin Development' started by LRFLEW, Dec 24, 2011.

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

    LRFLEW

    I know there is nothing by that exact name, but what would I do to find the event called when a player (or entity :p) activates a pressure plate?
     
  2. Check if the material of the "clicked" block is a pressure plate in onPlayerInteract like this:
    Code:java
    1. public void onPlayerInteract(PlayerInteractEvent event)
    2. {
    3. if(event.isCancelled())
    4. return;
    5.  
    6. if(event.getClickedBlock().getType() == Material.WOOD_PLATE)
    7. {
    8. //Do stuff here...
    9. }
    10. }
     
  3. Offline

    Darkman2412

    @V10lator : I think he means when a player stands on a pressure plate.

    @LRFLEW : You should use the BlockRedstoneEvent :)
     
  4. Code:java
    1.  
    2. public void onBlockRedstoneChange(BlockRedstoneEvent event) {
    3. final Block b = event.getBlock();
    4.  
    5. if (isPressurePlate(b.getType())) {
    6. if(event.getNewCurrent() == 1) { //current rises, pressure plate is being pressed
    7. //do stuff
    8. }
    9. }
    10. }
    11.  
    12. public static boolean isPressurePlate(Material mat) {
    13. return (mat == Material.STONE_PLATE) || (mat == Material.WOOD_PLATE);
    14. }
     
    hammale likes this.
  5. Use onPlayerInteract and check if getAction() returns Action.PHYSICAL, then the player stepped on a pressure plate!
     
    moo3oo3oo3 likes this.
  6. @Bone008 Your solution doesn't work when entities trigger the pressure plate. ;)
     
  7. Oh, didn't read the part in brackets ;-)

    Then go ahead with RedstoneChangeEvent, but you can't find out exactly what triggered it, then ;)
     
Thread Status:
Not open for further replies.

Share This Page