Skip to content

Commit

Permalink
tweak stuff and potentially fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jul 31, 2022
1 parent 662e3d8 commit 5566b22
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions src/main/kotlin/com/mineinabyss/bonfire/extensions/Campfire.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArmorStand>()
.find { it.uniqueId == uuid } ?: return createModel()
Expand All @@ -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")
Expand Down Expand Up @@ -102,9 +103,8 @@ fun Campfire.updateDisplay() {

fun Campfire.createModel(): ArmorStand? {
@Suppress("RemoveExplicitTypeArguments")
return transaction<ArmorStand?> {
val bonfireRow =
Bonfire.select { Bonfire.entityUUID eq this@createModel.uuid }.firstOrNull() ?: return@transaction null
return transaction<ArmorStand?>(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(
Expand Down Expand Up @@ -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()
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/kotlin/com/mineinabyss/bonfire/extensions/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ fun OfflinePlayer.setRespawnLocation(bonfireUUID: UUID) {

if(oldBonfireBlock != null) {
BonfireLogger.logRespawnUnset(oldBonfireBlock.location, this@setRespawnLocation)

oldBonfireBlock.markStateChanged()
}
} else if (playerRow == null) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArmorStand>().filter { it.isMarker && it.isBonfireModel() }.forEach {
val campfire = it.location.block.state as? Campfire ?: return it.remove()
Expand Down

0 comments on commit 5566b22

Please sign in to comment.