spigot kill entity
@EventHandler public void onEntitySpawn(EntitySpawnEvent event) { if (event.getEntityType() == EntityType.CREEPER) { if (event.getEntity() instanceof Damageable) { Damageable creeper = (Damageable) event.getEntity(); creeper.damage(1000); } } }
Here is what the above code is Doing:
1. We’re creating a new class called “CreeperListener” that extends the Java class “Listener”.
2. We’re creating a new method called “onEntitySpawn” that takes an “EntitySpawnEvent” as a parameter.
3. We’re checking if the entity that spawned is a creeper.
4. If it is, we’re checking if the entity is damageable.
5. If it is, we’re damaging the creeper by 1000 hearts.
Now, let’s add the listener to our plugin.yml file: