mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-11-23 11:45:36 +01:00
Fixes
This commit is contained in:
parent
5553ef3744
commit
2806afb7d9
@ -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)
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user