Reputation: 11
I just started making my first bukkit plugin. I wanted to make eggs that explode when they hit the ground, and I successfully made this. But now I want to have normal eggs and eggs that explode when they hit the ground. How can I create this? I tried naming them differently, but entities don't have item names. How can I detect which thrown egg was is an egg that should explode and which is a normal egg?
If anything wasn't clear enough please ask me to explain it better, Thanks!
Upvotes: 1
Views: 1468
Reputation: 7143
You can have an EventHandler
for when a player throws the Egg
you want, and add some MetaData to it:
@EventHandler
public void onProjectileLaunch(ProjectileLaunchEvent e){
Projectile projectile = e.getEntity();
if (//This projectile should be an explosive egg) {
projectile.setMetadata("explosiveegg", new FixedMetadataValue(plugin, "explosiveegg";
}
}
Then recover your Metadata whenever the Egg
hits an Entity
or the Floor and check if it's Metadata is "explosiveegg"
if (projectile.hasMetadata("explosiveegg")) //Explode
Upvotes: 3