diff --git a/src/main/kotlin/com/mineinabyss/bonfire/ecs/systems/BonfireEffectSystem.kt b/src/main/kotlin/com/mineinabyss/bonfire/ecs/systems/BonfireEffectSystem.kt index deb40fe..ae32ec6 100644 --- a/src/main/kotlin/com/mineinabyss/bonfire/ecs/systems/BonfireEffectSystem.kt +++ b/src/main/kotlin/com/mineinabyss/bonfire/ecs/systems/BonfireEffectSystem.kt @@ -22,12 +22,7 @@ class BonfireEffectSystem : TickingSystem(1.ticks) { }?.let { player.location.world.spawnParticle( listOf(Particle.SOUL, Particle.SOUL_FIRE_FLAME).random(), - player.location, - 1, - 0.5, - 1.0, - 0.5, - 0.0 + player.location, 1, 0.5, 1.0, 0.5, 0.0 ) player.saturation = BonfireConfig.data.effectStrength diff --git a/src/main/kotlin/com/mineinabyss/bonfire/extensions/Campfire.kt b/src/main/kotlin/com/mineinabyss/bonfire/extensions/Campfire.kt index 9e3c1a5..19090fd 100644 --- a/src/main/kotlin/com/mineinabyss/bonfire/extensions/Campfire.kt +++ b/src/main/kotlin/com/mineinabyss/bonfire/extensions/Campfire.kt @@ -45,6 +45,7 @@ var Campfire.uuid: UUID set(value) = bonfireData()?.updateUUID(value) ?: error() fun Campfire.getModel(): ArmorStand? { + if (!block.location.isWorldLoaded && !block.location.isChunkLoaded) return null return block.chunk.entities .filterIsInstance() .find { it.uniqueId == uuid } ?: return createModel() @@ -69,7 +70,7 @@ fun Campfire.createBonfire(newBonfireUUID: UUID, playerUUID: UUID) { fun Campfire.updateDisplay() { val location = block.location - if (!location.isWorldLoaded || !location.world.isChunkLoaded(location.chunk)) return + if (!location.isWorldLoaded || !location.isChunkLoaded) return if (!block.chunk.isEntitiesLoaded) return val model = getModel() ?: error("Couldn't get model") @@ -102,9 +103,8 @@ fun Campfire.updateDisplay() { fun Campfire.createModel(): ArmorStand? { @Suppress("RemoveExplicitTypeArguments") - return transaction { - val bonfireRow = - Bonfire.select { Bonfire.entityUUID eq this@createModel.uuid }.firstOrNull() ?: return@transaction null + return transaction(BonfireContext.db) { + val bonfireRow = Bonfire.select { Bonfire.entityUUID eq this@createModel.uuid }.firstOrNull() ?: return@transaction null // Spawn armor stand val armorStand = (bonfireRow[Bonfire.location].world.spawnEntity( @@ -153,8 +153,7 @@ fun Campfire.markStateChanged() { } fun Campfire.updateBonfire() { - val location = block.location - if (!location.isWorldLoaded || !location.world.isChunkLoaded(location.chunk)) return + if (!block.location.isWorldLoaded || !block.location.isChunkLoaded) return if (!block.chunk.isLoaded && !block.chunk.isEntitiesLoaded) return updateDisplay() @@ -163,8 +162,8 @@ fun Campfire.updateBonfire() { fun Campfire.updateFire() { val bonfireData = this.block.blockData as CampfireBlockData - val soulCampfire = - (Material.SOUL_CAMPFIRE.createBlockData() as CampfireBlockData).apply { this.facing = bonfireData.facing } + val soulCampfire = (Material.SOUL_CAMPFIRE.createBlockData() as CampfireBlockData).apply { this.facing = bonfireData.facing } + bonfirePlugin.launch(bonfirePlugin.asyncDispatcher) { delay(2.ticks) transaction(BonfireContext.db) { @@ -179,7 +178,6 @@ fun Campfire.updateFire() { fun Campfire.destroy(destroyBlock: Boolean) { val model = Bukkit.getEntity(this.uuid) as? ArmorStand - var blockLocation = model?.location transaction(BonfireContext.db) { diff --git a/src/main/kotlin/com/mineinabyss/bonfire/extensions/Player.kt b/src/main/kotlin/com/mineinabyss/bonfire/extensions/Player.kt index 48727db..7c05be7 100644 --- a/src/main/kotlin/com/mineinabyss/bonfire/extensions/Player.kt +++ b/src/main/kotlin/com/mineinabyss/bonfire/extensions/Player.kt @@ -59,7 +59,6 @@ fun OfflinePlayer.setRespawnLocation(bonfireUUID: UUID) { if(oldBonfireBlock != null) { BonfireLogger.logRespawnUnset(oldBonfireBlock.location, this@setRespawnLocation) - oldBonfireBlock.markStateChanged() } } else if (playerRow == null) { @@ -86,9 +85,8 @@ fun OfflinePlayer.removeBonfireSpawnLocation(bonfireUUID: UUID): Boolean { .select{Players.playerUUID eq this@removeBonfireSpawnLocation.uniqueId} .firstOrNull() ?: return@transaction true - if(dbPlayer[Players.bonfireUUID] != bonfireUUID){ + if(dbPlayer[Players.bonfireUUID] != bonfireUUID) return@transaction false - } val deleteCode = Players.deleteWhere { (Players.playerUUID eq this@removeBonfireSpawnLocation.uniqueId) and diff --git a/src/main/kotlin/com/mineinabyss/bonfire/listeners/BlockListener.kt b/src/main/kotlin/com/mineinabyss/bonfire/listeners/BlockListener.kt index 98979bb..e6963d2 100644 --- a/src/main/kotlin/com/mineinabyss/bonfire/listeners/BlockListener.kt +++ b/src/main/kotlin/com/mineinabyss/bonfire/listeners/BlockListener.kt @@ -104,7 +104,7 @@ object BlockListener : Listener { @EventHandler fun EntitiesLoadEvent.load() { val location = entities.firstOrNull()?.location ?: return - if (!location.isWorldLoaded || !location.world.isChunkLoaded(location.chunk)) return + if (!location.isWorldLoaded || !location.isChunkLoaded) return if (chunk.isLoaded && chunk.isEntitiesLoaded) { entities.filterIsInstance().filter { it.isMarker && it.isBonfireModel() }.forEach { val campfire = it.location.block.state as? Campfire ?: return it.remove()