Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Detect when fireworks explode.
package com.comphenix.example;
import org.bukkit.World;
import org.bukkit.entity.Firework;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ConnectionSide;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
public class DetectFireworks extends JavaPlugin implements Listener {
@Override
public void onEnable() {
ProtocolLibrary.getProtocolManager().addPacketListener(
new PacketAdapter(this, ConnectionSide.SERVER_SIDE, Packets.Server.ENTITY_STATUS) {
@Override
public void onPacketSending(PacketEvent event) {
PacketContainer packet = event.getPacket();
byte status = packet.getBytes().read(0);
if (status == 17) {
World world = event.getPlayer().getWorld();
Firework firework = (Firework) event.getPacket().getEntityModifier(world).read(0);
System.out.println(firework + " just exploded.");
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment