mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2025-01-20 20:51:23 +01:00
Listen to island kick
This commit is contained in:
parent
ee2cda7a97
commit
f96668a838
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user