Skip to content

Commit

Permalink
🐛 fix player quit
Browse files Browse the repository at this point in the history
  • Loading branch information
XiYang6666 committed Aug 7, 2024
1 parent a137057 commit 8ae96cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.bukkit.block.ChiseledBookshelf
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerMoveEvent
import org.bukkit.event.player.PlayerQuitEvent
import org.bukkit.inventory.meta.BookMeta
import org.bukkit.inventory.meta.BookMeta.Generation.*
import xyz.xasmc.hashbook.util.MarkUtil
Expand Down Expand Up @@ -58,4 +59,9 @@ class BookshelfListener : Listener {
}
MarkUtil.updateMark(player, markLocation.toLocation(world), nameSb.toString())
}

@EventHandler
fun onPlayerQuit(event: PlayerQuitEvent) {
MarkUtil.removeMark(event.player)
}
}
3 changes: 0 additions & 3 deletions src/main/kotlin/xyz/xasmc/hashbook/util/MarkUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ object MarkUtil {
val count = textList.size
val interval = 0.2
val offset = -0.4

val marks = playerMark[player] ?: mutableListOf<ArmorStand>().also { playerMark[player] = it }

val currentCount = marks.size
when {
count > currentCount -> repeat(count - currentCount) { marks.add(createArmorStand(world)) }
count < currentCount -> repeat(currentCount - count) { marks.removeLast()?.remove() }
}

val top = location.clone().add(0.0, interval * count / 2 + offset, 0.0)
textList.forEachIndexed { i, it ->
val mark = playerMark[player]!![i]
Expand Down

0 comments on commit 8ae96cb

Please sign in to comment.