This commit is contained in:
TomTom 2023-10-28 14:58:23 +02:00
parent 5553ef3744
commit 2806afb7d9
9 changed files with 28 additions and 7 deletions

View File

@ -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<Minion>()
val worldUUID = world.uid
fun addMinion(minion: Minion) {
minions.add(minion)

View File

@ -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()
}

View File

@ -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

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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

View File

@ -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) {