So I'm working on a plugin and one of the annoyances is that Blaze mobs take damage from rain and water. I haven't found a way to cancel this yet and I've tried several damage checks (EntityDamageEvent, EntityDamageByEntityEvent, EntityDamageByBlockEvent) with no success. Anyone care to share advice?
look at the source code of bukkit where the blaze gets damage by the weather, and see what event it calls there
Reply Check out Line 56 of EntityBlaze, that might be it (https://github.com/Bukkit/CraftBukk...in/java/net/minecraft/server/EntityBlaze.java) I'm not really sure on this (the source code is obfuscated), but that looks like an interesting place to start at the least.
No luck there. It's not firing a Damage event nor does it fire a death event when the Blaze dies. I appreciate your help though.
It's not firing an EntityDamageEvent. At all. There's nothing to check. Code: @EventHandler(priority = EventPriority.MONITOR) public void onEntityDamage(final EntityDamageEvent e) { Entity ent = e.getEntity(); if (ent instanceof Blaze) { Bukkit.broadcastMessage("Blaze hurt:" + e.getCause().name()); } } I punch it, it's triggered (ENTITY_ATTACK) but in the situation I need to cancel, it doesn't trigger. Not from rain, not from water. Thanks though.
@Scizzr Actually, if you check inside an entitydamage event for every type of damage cause and none of them matches, you can probably assume that they are being hurt by water contact.
Do me a favor and test it out. You'll see what I'm talking about. As my code is, I am literally checking for any and every DamageCause (since I am not filtering them out with an 'if' statement). This should result in any damage the Blaze takes being broadcast. It doesn't. Edit: If water contact damages the Blaze, shouldn't that fire at least a DamageCause.CONTACT? If so, why doesn't it?
@Scizzr I think they forgot to add that feature in the bukkit api. A workaround for this would be to listen in on a move event, check if the entity is a blaze, then get the location of the blaze and check if it's in water or if the light level of the location is above 10, which would indicate that the blaze is out in the open if the world is raining. Then you can schedule a repeating task every 1 second to broadcast the damage until you cancel it when the blaze dies in an entity death event.
That's another thing: The Blaze dying from the rain or water doesn't fire an EntityDeathEvent. So, yeah. Lol Edit: Code Code: @EventHandler(priority = EventPriority.MONITOR) public void onEntityDeath(final EntityDeathEvent e) { Entity ent = e.getEntity(); if (ent instanceof Blaze) { Bukkit.broadcastMessage("Blaze dead"); } } Edit 2: Added a ticket. Hopefully it'll be fixed in the 1.3 release.
@Scizzr Hmm. That means that you would have to schedule a repeating task and check if the blaze is dead or the entity is removed.
Exactly what I've done. If you're curious why I want this, it's for 'pets' in a plugin I'm working on. They just respawn so its not a big deal. Just annoying having them respawn-loop in the rain. ^_^
Respawning every 3 seconds? Yeah. I'm storing the entity's UUID in a hashMap and checking every 3 seconds for its existence. If it doesn't exist, I'm removing the UUID from the HashMap and re-spawning another Blaze. I've been doing that all day, I was just stuck on this issue all the while. ^_^