From ae1c99e1f0864400392852492958eebe6a4a9396 Mon Sep 17 00:00:00 2001 From: Esoteric Enderman Date: Sat, 2 Nov 2024 17:19:09 +0000 Subject: [PATCH] Apply `toEntity` before properly spawning the mob --- lib/build.gradle.kts | 2 +- .../minecraft/plugins/library/entity/CustomEntity.kt | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index 9c2a54e..28d8621 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "foundation.esoteric" -version = "0.7.2-experimental.1" +version = "0.7.2" repositories { mavenCentral() diff --git a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/entity/CustomEntity.kt b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/entity/CustomEntity.kt index 59cef0d..f29a25b 100644 --- a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/entity/CustomEntity.kt +++ b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/entity/CustomEntity.kt @@ -5,6 +5,7 @@ import org.bukkit.Location import org.bukkit.entity.Entity import org.bukkit.entity.EntityType import org.bukkit.event.Listener +import org.bukkit.event.entity.CreatureSpawnEvent import org.bukkit.persistence.PersistentDataType abstract class CustomEntity protected constructor(protected val plugin: CustomEntityPlugin, private val entityId: String, private val entityType: EntityType) : Listener { @@ -15,10 +16,12 @@ abstract class CustomEntity protected constructor(protected val plug plugin.customEntityManager.addEntity(entityId, this) } - open fun createEntity(spawnLocation: Location): E { - val entity = spawnLocation.world.spawnEntity(spawnLocation, entityType) as E - toEntity(entity) - return entity + fun createEntity(spawnLocation: Location): E { + return spawnLocation.world.spawnEntity(spawnLocation, entityType, CreatureSpawnEvent.SpawnReason.DEFAULT) { entity -> + toEntity( + entity as E + ) + } as E } open fun toEntity(vararg entities: E): Array {