diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/SuperiorSkyBlock2Listener.kt b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/SuperiorSkyBlock2Listener.kt index d5a4b83..7fe7615 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/SuperiorSkyBlock2Listener.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/SuperiorSkyBlock2Listener.kt @@ -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()) } } }