onFireWorkExplode event?

Discussion in 'Plugin Development' started by Hanii Puppy, May 14, 2013.

Thread Status:
Not open for further replies.
  1. Part of what I'm doing at the minute has me spawning a firework going in a particular direction, and attaching metadata to it. The metadata should then be acted upon when the firework hits something (a block or an entity) and explodes. I've looked, but I can't find any events for when a firework explodes. I tried ProjectileHitEvent, but that doesn't seem to have anything to do with firework explosions :\

    I could use the ProjectileHitEvent for snowballs and create a firework explosion where it hits - but obviously, being able to use a firework would be more desirable.
     
  2. Offline

    devilquak

    Hanii Puppy

    I might be wrong, but my understanding is that the ProjectileHitEvent only fires for entities that are supposed to do things when they hit something else, i.e. do damage, explode, or create an effect. Ergo, since fireworks weren't designed to do anything when they hit anything else, there's no event to detect that.

    You might find something for it in ProtocolLib, but that's just a wild guess. Good luck.
     
  3. Offline

    Comphenix

    Sure. You can intercept this easily by listening for the "entity status" packet (download):
    Code:java
    1. public class ExampleMod extends JavaPlugin implements Listener {
    2. public void onEnable() {
    3. ProtocolLibrary.getProtocolManager().addPacketListener(
    4. new PacketAdapter(this, ConnectionSide.SERVER_SIDE, Packets.Server.ENTITY_STATUS) {
    5. public void onPacketSending(PacketEvent event) {
    6. PacketContainer packet = event.getPacket();
    7. byte status = packet.getBytes().read(0);
    8.  
    9. if (status == 17) {
    10. World world = event.getPlayer().getWorld();
    11. Firework firework = (Firework) event.getPacket().getEntityModifier(world).read(0);
    12.  
    13. System.out.println(firework + " just exploded.");
    14. }
    15. }
    16. });
    17. }
    18. }
     
    devilquak likes this.
  4. Offline

    chasechocolate

    Maybe EntityExplodeEvent is called? I'm not 100% sure though.
     
  5. Offline

    Comphenix

    Neither EntityExplodeEvent or EntityDeathEvent seems to work. There's no events called in EntityFireworks at all, after all, so it's not really surprising.
     
  6. Offline

    chasechocolate

    That's a shame. I think they should have a FireworkLaunchEvent and FireworkExplodeEvent.
     
Thread Status:
Not open for further replies.

Share This Page