Skip to content

Commit

Permalink
feat: show debugtext in spectator mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jun 7, 2024
1 parent f09e2c1 commit 9e8c94d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
gearyPaper = "0.30.1"
blocky = "0.9.13-dev.13"
blocky = "0.9.13-dev.22"

[libraries]
geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "gearyPaper" }
Expand Down
24 changes: 22 additions & 2 deletions src/main/kotlin/com/mineinabyss/bonfire/listeners/DebugListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.EntityType
import net.minecraft.world.phys.Vec3
import org.bukkit.Color
import org.bukkit.GameMode
import org.bukkit.craftbukkit.entity.CraftPlayer
import org.bukkit.entity.ItemDisplay
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerGameModeChangeEvent
import org.bukkit.event.player.PlayerMoveEvent
import org.bukkit.event.player.PlayerToggleSneakEvent
import java.util.*
import kotlin.time.Duration.Companion.seconds
Expand All @@ -42,13 +45,30 @@ class DebugListener : Listener {

@EventHandler
fun PlayerToggleSneakEvent.onDebugToggle() {
player.toGeary().has<BonfireDebug>() || return
player.getNearbyEntities(10.0,10.0,10.0).filterIsInstance<ItemDisplay>().filter { it.isBonfire }.forEach {
if (!player.toGeary().has<BonfireDebug>()) return
player.getNearbyEntities(16.0, 16.0, 16.0).filterIsInstance<ItemDisplay>().filter { it.isBonfire }.forEach {
if (isSneaking) player.sendDebugTextDisplay(it)
else removeDebugTextDisplay(player)
}
}

@EventHandler
fun PlayerGameModeChangeEvent.onDebugToggle() {
if (!player.toGeary().has<BonfireDebug>()) return
player.getNearbyEntities(16.0, 16.0, 16.0).filterIsInstance<ItemDisplay>().filter { it.isBonfire }.forEach {
if (newGameMode == GameMode.SPECTATOR) player.sendDebugTextDisplay(it)
else removeDebugTextDisplay(player)
}
}

@EventHandler
fun PlayerMoveEvent.onDebugToggle() {
if (player.gameMode != GameMode.SPECTATOR || !player.toGeary().has<BonfireDebug>()) return
player.getNearbyEntities(16.0, 16.0, 16.0).filterIsInstance<ItemDisplay>().filter { it.isBonfire }.forEach {
player.sendDebugTextDisplay(it)
}
}

private val debugIdMap = mutableMapOf<UUID, MutableMap<FurnitureUUID, Int>>()
private fun Player.sendDebugTextDisplay(baseEntity: ItemDisplay) {
val entityIds = debugIdMap.computeIfAbsent(uniqueId) { mutableMapOf(baseEntity.uniqueId to Entity.nextEntityId()) }
Expand Down

0 comments on commit 9e8c94d

Please sign in to comment.