Solved Event for "breaking" a "FIRE" block?

Discussion in 'Plugin Development' started by CubieX, Jan 4, 2013.

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

    CubieX

    I'm having trouble to detect if a player "breaks" a fire block. (ID 51)
    Which event is beeing fired for this?

    The BlockBreakEvent does not fire for it and I could not find an obvious event for it in the API docs.
    Some kind of "extinguish" event or something.
     
  2. Offline

    zXCaKeXz

    Code:
        public void onPlayerInteract(PlayerInteractEvent event)
        {
            Player player = event.getPlayer();
            if (player.getTargetBlock(null, 5).getType() == Material.FIRE)
                event.setCancelled(true);
        }
    ^ haven't tested it yet, but hopefully it works :D
     
  3. Offline

    MrMysterious

    It's not working, I tried that 10 minutes ago :/

    EDIT: Oh Sorry, it's working your way! I tried it like this:

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent arg0)
    3. {
    4. if(arg0.getClickedBlock() != null)
    5. {
    6. if(arg0.getClickedBlock().getType() == Material.FIRE)
    7. {
    8. //Do something...
    9. }
    10. }
    11. }
     
  4. Just a thought, wouldn't that also cancel a player stepping onto a pressure plate while looking at a fire block? ;)
    So validating the Action might ne necessary.
     
  5. Offline

    lDucks

    Code:
     public void onPlayerInteract(PlayerInteractEvent event)
    {
    Player player = event.getPlayer();
    if(event.getAction() == Action.LEFT_CLICK_BLOCK{
    if (player.getTargetBlock(null, 5).getType() == Material.FIRE)
    event.setCancelled(true);
    }
    }
     
    CubieX likes this.
  6. Offline

    CubieX

    Thanks! It works. :)
     
Thread Status:
Not open for further replies.

Share This Page