Which event is called when an anvil breaks?

Discussion in 'Plugin Development' started by RainoBoy97, Mar 24, 2013.

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

    RainoBoy97

    Well, title explains the question :3

    -Raino
     
  2. Offline

    Tirelessly

    Try BlockBreakEvent
     
  3. Offline

    Technius

    No, that's when a player breaks a block. There might not be an event for this...
     
  4. Offline

    Tirelessly

    Well it isn't "PlayerBreakBlockEvent" so it could be extended to other things.
     
  5. Offline

    RainoBoy97

    I don't see how I can check if the break was a anvil due to the damage or if a player breaks it by hand :p
     
  6. RainoBoy97
    First you need to know if it actually triggers BlockBreakEvent in that case.
     
  7. Offline

    LazyLemons

    Maybe listen for the sound packet?
     
  8. Offline

    RainoBoy97

    I dont think it will trigger, as BlockBreakEvent is for when a player breaks a block..
     
  9. Offline

    Comphenix

    I gave it a go, and no - BlockBreakEvent is not triggered.

    In fact, there is currently no Bukkit event that can intercept it - just take a look at the source code.

    But you could intercept packet 61 (WORLD_EVENT) and check if its event ID is 1020:
    Code:
    2013-03-24 23:33:04 [INFO] [ProtocolLib] Sent WORLD_EVENT (61) to aadnk:
    { a = 1020, b = 0, c = 58, d = 109, e = 197, f = false }
     
  10. Offline

    TheRecovery007

    @EventHandler
    public void anvil(EntityDamageEvent e){
    if(e.getEntity().equals(Material.ANVIL)){
    e.setCancelled(true);

    }

    }
     
    Paradrakor likes this.
  11. Offline

    Garris0n

    lol what
     
    AoH_Ruthless, MooshViolet and hintss like this.
  12. Offline

    TheRecovery007

    it works
     
  13. Offline

    daavko

    TheRecovery007 Wait WHAT?? EntityDamageEvent works for breaking block?? Bukkit must be crazy...
     
  14. Offline

    Paradrakor

    Runs code when an entity is damaged.
    If the entity that caused the damage is an anvil, the event is cancelled.

    It should be BlockBreakEvent, lol daavko
     
  15. Offline

    Saladoc

    I doubt that. Entity != Material

    Also I think that it would be more like a BlockBreakEvent.
     
  16. Offline

    xize

    You may want to listen to the inventory events and from there getting the holder and check the durability or data of it, however that isn't much good as I haven't seen a way to determine when a item is actually anviled (cause thats needed because it changes the durability) and when the durability changes because it looks more on a random chance, it does not always change the anvils data when anviling a item:p

    Edit

    Alright by just thinking I was just making it complicated.

    you could easily do something like this but it may fails:

    use InventoryOpenEvent and check if the holder is a anvil if thats is true, store that information somewhere.

    now as follows you listen to the InventoryCloseEvent and check if the same holder is still a instance of a anvil if it is then use the getBlock() and check if its air, if its not a anvil there ya go.
     
  17. Offline

    daavko

    Paradrakor I know it should. But as these people stated earlier, BlockBreakEvent is triggered only when player destroys a block. Also, I was responding to TheRecovery007 's silly idea of EntityDamageEvent. If you don't feel like scrolling up a bit, here's what he stated:
     
  18. Offline

    mythbusterma


    Fairly certain that Material.ANVIL (or Material in general for that matter) does not extend Entity, therefore e.getEntity() can never return a Material, which will never be equal to Material.ANVIL.
     
Thread Status:
Not open for further replies.

Share This Page