From 3842824a65fb3d4c4b92418daf448be2587817f5 Mon Sep 17 00:00:00 2001 From: AverageGithub Date: Fri, 2 Aug 2024 14:20:30 +0200 Subject: [PATCH] Fix --- .../axminions/minions/Minion.kt | 2 +- .../axminions/minions/Minions.kt | 47 ++++++++++++++----- .../minions/miniontype/LumberMinionType.kt | 2 +- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt index 77948ac..da6a5d9 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt @@ -653,7 +653,7 @@ class Minion( if (linkedChest == null) return if (ticking) { - Scheduler.get().runAt(linkedChest) { + Scheduler.get().runAt(linkedChest) { a -> if (linkedChest!!.world!!.isChunkLoaded(linkedChest!!.blockX shr 4, linkedChest!!.blockZ shr 4)) { linkedInventory = (linkedChest?.block?.state as? Container)?.inventory } diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minions.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minions.kt index 98350d8..b947fc1 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minions.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minions.kt @@ -2,10 +2,12 @@ package com.artillexstudios.axminions.minions import com.artillexstudios.axminions.api.minions.Minion import com.artillexstudios.axminions.api.minions.utils.ChunkPos +import com.artillexstudios.axapi.scheduler.Scheduler import java.util.Collections import java.util.concurrent.locks.ReentrantReadWriteLock import kotlin.concurrent.read import kotlin.concurrent.write +import org.bukkit.Bukkit import org.bukkit.Chunk object Minions { @@ -17,8 +19,19 @@ object Minions { val chunkZ = chunk.z val world = chunk.world - run breaking@{ - lock.read { + if (!Bukkit.isPrimaryThread()) { + Scheduler.get().run { a -> + run breaking@{ + minions.forEach { + if (world.uid == it.worldUUID && it.x == chunkX && it.z == chunkZ) { + it.setTicking(true) + return@breaking + } + } + } + } + } else { + run breaking@{ minions.forEach { if (world.uid == it.worldUUID && it.x == chunkX && it.z == chunkZ) { it.setTicking(true) @@ -27,6 +40,7 @@ object Minions { } } } + } fun isTicking(chunk: Chunk): Boolean { @@ -34,14 +48,12 @@ object Minions { val chunkZ = chunk.z val world = chunk.world - lock.read { - minions.forEach { - if (world.uid == it.worldUUID && it.x == chunkX && it.z == chunkZ) { - return it.ticking - } + minions.forEach { + if (world.uid == it.worldUUID && it.x == chunkX && it.z == chunkZ) { + return it.ticking } } - + return false } @@ -50,8 +62,19 @@ object Minions { val chunkZ = chunk.z val world = chunk.world - run breaking@{ - lock.read { + if (!Bukkit.isPrimaryThread()) { + Scheduler.get().run { a -> + run breaking@{ + minions.forEach { + if (world.uid == it.worldUUID && it.x == chunkX && it.z == chunkZ) { + it.setTicking(false) + return@breaking + } + } + } + } + } else { + run breaking@{ minions.forEach { if (world.uid == it.worldUUID && it.x == chunkX && it.z == chunkZ) { it.setTicking(false) @@ -68,7 +91,7 @@ object Minions { val world = minion.getLocation().world ?: return if (!Bukkit.isPrimaryThread()) { - lock.write { + Scheduler.get().run { a -> var pos: ChunkPos? = null run breaking@{ minions.forEach { @@ -112,7 +135,7 @@ object Minions { val world = minion.getLocation().world ?: return if (!Bukkit.isPrimaryThread()) { - lock.write { + Scheduler.get().run { a -> val iterator = minions.iterator() while (iterator.hasNext()) { val next = iterator.next() diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/LumberMinionType.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/LumberMinionType.kt index bc1f1c4..cf3eaf4 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/LumberMinionType.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/LumberMinionType.kt @@ -71,7 +71,7 @@ class LumberMinionType : MinionType("lumber", AxMinionsPlugin.INSTANCE.getResour val down = it.getRelative(BlockFace.DOWN).type loot.addAll(it.getDrops(minion.getTool())) - if (down == Material.DIRT || down == Material.GRASS_BLOCK || down == Material.COARSE_DIRT || down == Material.ROOTED_DIRT || down == Material.DIRT_PATH || down == Material.MUD || down == Material.MUDDY_MANGROVE_ROOTS) { + if (down == Material.DIRT || down == Material.GRASS_BLOCK || down == Material.COARSE_DIRT || down == Material.ROOTED_DIRT || down == Material.DIRT_PATH || down == Material.MUD || down == Material.MUDDY_MANGROVE_ROOTS || down == Material.PODZOL) { it.type = getSaplingType(it.type) } else { it.type = Material.AIR