Listen to island kick

This commit is contained in:
TomTom 2024-07-08 11:57:19 +02:00
parent ee2cda7a97
commit f96668a838

View File

@ -2,6 +2,8 @@ package com.artillexstudios.axminions.listeners
import com.artillexstudios.axminions.minions.Minions
import com.bgsoftware.superiorskyblock.api.events.IslandDisbandEvent
import com.bgsoftware.superiorskyblock.api.events.IslandKickEvent
import org.bukkit.Bukkit
import org.bukkit.World.Environment
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
@ -20,6 +22,30 @@ class SuperiorSkyBlock2Listener : Listener {
val ch = minion.getLocation().chunk
if (ch.x == chunk.x && ch.z == chunk.z && ch.world == chunk.world) {
minion.remove()
Bukkit.getPlayer(minion.getOwnerUUID())?.inventory?.addItem(minion.getAsItem())
}
}
}
} catch (_: NullPointerException) {
// SuperiorSkyBlock api does it this way aswell
}
}
}
@EventHandler
fun onIslandKickEvent(event: IslandKickEvent) {
val kicked = event.target.uniqueId
val kickedPlayer = Bukkit.getPlayer(kicked)
val minions = Minions.getMinions()
Environment.entries.forEach { entry ->
try {
event.island.getAllChunksAsync(entry, true) { chunk ->
minions.forEach { minion ->
val ch = minion.getLocation().chunk
if (minion.getOwnerUUID() == kicked && ch.x == chunk.x && ch.z == chunk.z && ch.world == chunk.world) {
minion.remove()
kickedPlayer?.inventory?.addItem(minion.getAsItem())
}
}
}