Search in sources :

Example 1 with SpawnerSpawnEvent

use of org.bukkit.event.entity.SpawnerSpawnEvent in project Denizen-For-Bukkit by DenizenScript.

the class EntitySpawnScriptEvent method onEntitySpawn.

@EventHandler
public void onEntitySpawn(EntitySpawnEvent event) {
    Entity entity = event.getEntity();
    this.entity = new EntityTag(entity);
    location = new LocationTag(event.getLocation());
    if (event instanceof CreatureSpawnEvent) {
        CreatureSpawnEvent.SpawnReason creatureReason = ((CreatureSpawnEvent) event).getSpawnReason();
        if (creatureReason == CreatureSpawnEvent.SpawnReason.SPAWNER) {
            // Let the SpawnerSpawnEvent happen and handle it instead
            return;
        }
        reason = new ElementTag(creatureReason.name());
    } else if (event instanceof SpawnerSpawnEvent) {
        reason = new ElementTag("SPAWNER");
    } else {
        reason = new ElementTag("ENTITY_SPAWN");
    }
    this.event = event;
    EntityTag.rememberEntity(entity);
    fire(event);
    EntityTag.forgetEntity(entity);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Entity(org.bukkit.entity.Entity) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) SpawnerSpawnEvent(org.bukkit.event.entity.SpawnerSpawnEvent) EventHandler(org.bukkit.event.EventHandler)

Aggregations

EntityTag (com.denizenscript.denizen.objects.EntityTag)1 LocationTag (com.denizenscript.denizen.objects.LocationTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 Entity (org.bukkit.entity.Entity)1 EventHandler (org.bukkit.event.EventHandler)1 CreatureSpawnEvent (org.bukkit.event.entity.CreatureSpawnEvent)1 SpawnerSpawnEvent (org.bukkit.event.entity.SpawnerSpawnEvent)1