From 2806afb7d988ab34fe5971a7865151b2c26dcb3f Mon Sep 17 00:00:00 2001 From: TomTom <93038247+AverageGithub@users.noreply.github.com> Date: Sat, 28 Oct 2023 14:58:23 +0200 Subject: [PATCH] Fixes --- .../axminions/api/minions/utils/ChunkPos.kt | 4 +++- .../axminions/minions/Minions.kt | 17 +++++++++++------ .../minions/miniontype/CollectorMinionType.kt | 2 ++ .../minions/miniontype/FarmerMinionType.kt | 2 ++ .../minions/miniontype/FisherMinionType.kt | 2 ++ .../minions/miniontype/LumberMinionType.kt | 2 ++ .../minions/miniontype/MinerMinionType.kt | 2 ++ .../minions/miniontype/SellerMinionType.kt | 2 ++ .../minions/miniontype/SlayerMinionType.kt | 2 ++ 9 files changed, 28 insertions(+), 7 deletions(-) diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/minions/utils/ChunkPos.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/minions/utils/ChunkPos.kt index 60750a6..2f2e2a6 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/minions/utils/ChunkPos.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/minions/utils/ChunkPos.kt @@ -2,9 +2,11 @@ package com.artillexstudios.axminions.api.minions.utils import com.artillexstudios.axminions.api.minions.Minion import com.artillexstudios.axminions.api.utils.fastFor +import org.bukkit.World -data class ChunkPos(var x: Int, var z: Int) { +data class ChunkPos(val world: World, var x: Int, var z: Int) { val minions = arrayListOf() + val worldUUID = world.uid fun addMinion(minion: Minion) { minions.add(minion) 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 9274edd..42b7591 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minions.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minions.kt @@ -12,11 +12,12 @@ object Minions { fun addTicking(chunk: Chunk) { val chunkX = chunk.x val chunkZ = chunk.z + val world = chunk.world run breaking@{ synchronized(mutex) { minions.forEach { - if (it.x == chunkX && it.z == chunkZ) { + if (world.uid == it.worldUUID && it.x == chunkX && it.z == chunkZ) { it.setTicking(true) return@breaking } @@ -28,10 +29,11 @@ object Minions { fun isTicking(chunk: Chunk): Boolean { val chunkX = chunk.x val chunkZ = chunk.z + val world = chunk.world synchronized(mutex) { minions.forEach { - if (it.x == chunkX && it.z == chunkZ) { + if (world.uid == it.worldUUID && it.x == chunkX && it.z == chunkZ) { return true } } @@ -43,11 +45,12 @@ object Minions { fun removeTicking(chunk: Chunk) { val chunkX = chunk.x val chunkZ = chunk.z + val world = chunk.world run breaking@{ synchronized(mutex) { minions.forEach { - if (it.x == chunkX && it.z == chunkZ) { + if (world.uid == it.worldUUID && it.x == chunkX && it.z == chunkZ) { it.setTicking(false) return@breaking } @@ -59,13 +62,14 @@ object Minions { fun load(minion: Minion) { val chunkX = round(minion.getLocation().x) shr 4 val chunkZ = round(minion.getLocation().z) shr 4 + val world = minion.getLocation().world ?: return synchronized(mutex) { var pos: ChunkPos? = null run breaking@{ minions.forEach { - if (it.x == chunkX && it.z == chunkZ) { + if (world.uid == it.worldUUID && it.x == chunkX && it.z == chunkZ) { pos = it return@breaking } @@ -73,7 +77,7 @@ object Minions { } if (pos === null) { - pos = ChunkPos(chunkX, chunkZ) + pos = ChunkPos(world, chunkX, chunkZ) minions.add(pos!!) } @@ -85,13 +89,14 @@ object Minions { fun remove(minion: Minion) { val chunkX = round(minion.getLocation().x) shr 4 val chunkZ = round(minion.getLocation().z) shr 4 + val world = minion.getLocation().world ?: return synchronized(mutex) { val iterator = minions.iterator() while (iterator.hasNext()) { val next = iterator.next() - if (next.x == chunkX && next.z == chunkZ) { + if (world.uid == next.worldUUID && next.x == chunkX && next.z == chunkZ) { if (next.removeMinion(minion)) { iterator.remove() } diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/CollectorMinionType.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/CollectorMinionType.kt index 22ad426..82c70e3 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/CollectorMinionType.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/CollectorMinionType.kt @@ -26,6 +26,8 @@ class CollectorMinionType : MinionType("collector", AxMinionsPlugin.INSTANCE.get } override fun run(minion: Minion) { + Warnings.remove(minion, Warnings.CONTAINER_FULL) + if (minion.getLinkedChest() == null) { Warnings.NO_CONTAINER.display(minion) return diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FarmerMinionType.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FarmerMinionType.kt index e7cfc3a..086dc39 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FarmerMinionType.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FarmerMinionType.kt @@ -29,6 +29,8 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour } override fun run(minion: Minion) { + Warnings.remove(minion, Warnings.CONTAINER_FULL) + if (minion.getLinkedChest() != null) { val type = minion.getLinkedChest()!!.block.type if (type != Material.CHEST && type != Material.TRAPPED_CHEST && type != Material.BARREL) { diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FisherMinionType.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FisherMinionType.kt index 0a13e63..54a0fd9 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FisherMinionType.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FisherMinionType.kt @@ -29,6 +29,8 @@ class FisherMinionType : MinionType("fisher", AxMinionsPlugin.INSTANCE.getResour } override fun run(minion: Minion) { + Warnings.remove(minion, Warnings.CONTAINER_FULL) + if (minion.getLinkedChest() != null) { val type = minion.getLinkedChest()!!.block.type if (type != Material.CHEST && type != Material.TRAPPED_CHEST && type != Material.BARREL) { 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 54a1974..a148686 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 @@ -29,6 +29,8 @@ class LumberMinionType : MinionType("lumber", AxMinionsPlugin.INSTANCE.getResour } override fun run(minion: Minion) { + Warnings.remove(minion, Warnings.CONTAINER_FULL) + if (minion.getLinkedChest() != null) { val type = minion.getLinkedChest()!!.block.type if (type != Material.CHEST && type != Material.TRAPPED_CHEST && type != Material.BARREL) { diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/MinerMinionType.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/MinerMinionType.kt index 11584a0..c9c8846 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/MinerMinionType.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/MinerMinionType.kt @@ -35,6 +35,8 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource } override fun run(minion: Minion) { + Warnings.remove(minion, Warnings.CONTAINER_FULL) + if (minion.getLinkedChest() != null) { val type = minion.getLinkedChest()!!.block.type if (type != Material.CHEST && type != Material.TRAPPED_CHEST && type != Material.BARREL) { diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/SellerMinionType.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/SellerMinionType.kt index c78c515..d0c853c 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/SellerMinionType.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/SellerMinionType.kt @@ -24,6 +24,8 @@ class SellerMinionType : MinionType("seller", AxMinionsPlugin.INSTANCE.getResour } override fun run(minion: Minion) { + Warnings.remove(minion, Warnings.CONTAINER_FULL) + if (minion.getLinkedChest() == null) { Warnings.NO_CONTAINER.display(minion) return diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/SlayerMinionType.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/SlayerMinionType.kt index 3db725e..20b0849 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/SlayerMinionType.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/SlayerMinionType.kt @@ -29,6 +29,8 @@ class SlayerMinionType : MinionType("slayer", AxMinionsPlugin.INSTANCE.getResour } override fun run(minion: Minion) { + Warnings.remove(minion, Warnings.CONTAINER_FULL) + if (minion.getLinkedChest() != null) { val type = minion.getLinkedChest()!!.block.type if (type != Material.CHEST && type != Material.TRAPPED_CHEST && type != Material.BARREL) {