Fix dupes

This commit is contained in:
TomTom 2023-11-05 18:53:16 +01:00
parent d9766511ba
commit e04897cd42
2 changed files with 45 additions and 9 deletions

View File

@ -22,6 +22,7 @@ import com.artillexstudios.axminions.listeners.MinionDamageListener
import com.artillexstudios.axminions.listeners.MinionInventoryListener
import com.artillexstudios.axminions.listeners.MinionPlaceListener
import com.artillexstudios.axminions.listeners.WorldListener
import com.artillexstudios.axminions.minions.Minion
import com.artillexstudios.axminions.minions.MinionTicker
import com.artillexstudios.axminions.minions.Minions
import com.artillexstudios.axminions.minions.miniontype.CollectorMinionType
@ -135,6 +136,18 @@ class AxMinionsPlugin : AxPlugin() {
}
override fun disable() {
Minions.get().fastFor { pos ->
pos.minions.fastFor { minion ->
val minionImp = minion as Minion
minionImp.openInventories.fastFor { inventory ->
inventory.viewers.fastFor { player ->
player.closeInventory()
}
}
}
}
dataHandler.disable()
}

View File

@ -26,6 +26,7 @@ import com.artillexstudios.axminions.api.warnings.Warning
import com.artillexstudios.axminions.api.warnings.Warnings
import com.artillexstudios.axminions.listeners.LinkingListener
import java.util.UUID
import java.util.concurrent.atomic.AtomicBoolean
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
import org.bukkit.Bukkit
import org.bukkit.Location
@ -66,9 +67,10 @@ class Minion(
private var hologram: Hologram? = null
private val extraData = hashMapOf<String, String>()
private var linkedInventory: Inventory? = null
private val openInventories = mutableListOf<Inventory>()
internal val openInventories = mutableListOf<Inventory>()
private var ticking = false
private var debugHologram: Hologram? = null
private var broken = false
init {
spawn()
@ -94,17 +96,37 @@ class Minion(
entity.setHasArms(true)
entity.onClick { event ->
Scheduler.get().run {
if (event.isAttack) {
if (ownerUUID == event.player.uniqueId) {
breakMinion(event)
} else if ((AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.packetEntity.location) && !Config.ONLY_OWNER_BREAK()) || event.player.hasPermission("axminions.*")) {
if (broken) {
return@onClick
}
if (event.isAttack) {
if (ownerUUID == event.player.uniqueId) {
broken = true
Scheduler.get().runAt(location) {
breakMinion(event)
}
} else {
if (ownerUUID == event.player.uniqueId) {
} else if ((AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(
event.player,
event.packetEntity.location
) && !Config.ONLY_OWNER_BREAK()) || event.player.hasPermission("axminions.*")
) {
broken = true
Scheduler.get().runAt(location) {
breakMinion(event)
}
}
} else {
if (ownerUUID == event.player.uniqueId) {
Scheduler.get().runAt(location) {
openInventory(event.player)
} else if ((AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.packetEntity.location) && !Config.ONLY_OWNER_GUI()) || event.player.hasPermission("axminions.*")) {
}
} else if ((AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(
event.player,
event.packetEntity.location
) && !Config.ONLY_OWNER_GUI()) || event.player.hasPermission("axminions.*")
) {
Scheduler.get().runAt(location) {
openInventory(event.player)
}
}
@ -128,6 +150,7 @@ class Minion(
}
private fun breakMinion(event: PacketEntityInteractEvent) {
LinkingListener.linking.remove(event.player.uniqueId)
remove()
setTicking(false)
openInventories.fastFor { it.viewers.fastFor { viewer -> viewer.closeInventory() } }