Remove locking

This commit is contained in:
AverageGithub 2024-08-02 14:02:25 +02:00
parent 3f85df77e5
commit 856a8dbbb8
3 changed files with 43 additions and 6 deletions

View File

@ -9,7 +9,12 @@ class EssentialsIntegration : PricesIntegration {
private lateinit var manager: IEssentials;
override fun getPrice(itemStack: ItemStack): Double {
return manager.worth.getPrice(manager, itemStack).toDouble() * itemStack.amount
val price = manager.worth.getPrice(manager, itemStack)
if (price == null) {
return 0.0
}
return price.toDouble() * itemStack.amount
}
override fun register() {

View File

@ -653,7 +653,7 @@ class Minion(
if (linkedChest == null) return
if (ticking) {
Scheduler.get().executeAt(linkedChest) {
Scheduler.get().runAt(linkedChest) {
if (linkedChest!!.world!!.isChunkLoaded(linkedChest!!.blockX shr 4, linkedChest!!.blockZ shr 4)) {
linkedInventory = (linkedChest?.block?.state as? Container)?.inventory
}

View File

@ -67,7 +67,26 @@ object Minions {
val chunkZ = minion.getLocation().blockZ shr 4
val world = minion.getLocation().world ?: return
lock.write {
if (!Bukkit.isPrimaryThread()) {
lock.write {
var pos: ChunkPos? = null
run breaking@{
minions.forEach {
if (world.uid == it.worldUUID && it.x == chunkX && it.z == chunkZ) {
pos = it
return@breaking
}
}
}
if (pos == null) {
pos = ChunkPos(world, chunkX, chunkZ, false)
minions.add(pos!!)
}
pos!!.addMinion(minion)
}
} else {
var pos: ChunkPos? = null
run breaking@{
minions.forEach {
@ -83,8 +102,7 @@ object Minions {
minions.add(pos!!)
}
pos!!.addMinion(minion)
pos!!.addMinion(minion)
}
}
@ -93,7 +111,21 @@ object Minions {
val chunkZ = minion.getLocation().blockZ shr 4
val world = minion.getLocation().world ?: return
lock.write {
if (!Bukkit.isPrimaryThread()) {
lock.write {
val iterator = minions.iterator()
while (iterator.hasNext()) {
val next = iterator.next()
if (world.uid == next.worldUUID && next.x == chunkX && next.z == chunkZ) {
if (next.removeMinion(minion)) {
iterator.remove()
}
break
}
}
}
} else {
val iterator = minions.iterator()
while (iterator.hasNext()) {
val next = iterator.next()