diff --git a/kommand-lib b/kommand-lib index 9af2931..e0613cd 160000 --- a/kommand-lib +++ b/kommand-lib @@ -1 +1 @@ -Subproject commit 9af293122b860d8c65d68a2bdc02a9c2c5e206cc +Subproject commit e0613cd05278222b0a2ac1c79a2d4ef317c9cea1 diff --git a/src/main/kotlin/net/hareworks/ghostdisplays/GhostDisplaysPlugin.kt b/src/main/kotlin/net/hareworks/ghostdisplays/GhostDisplaysPlugin.kt index d5942b0..3a716cc 100644 --- a/src/main/kotlin/net/hareworks/ghostdisplays/GhostDisplaysPlugin.kt +++ b/src/main/kotlin/net/hareworks/ghostdisplays/GhostDisplaysPlugin.kt @@ -39,6 +39,10 @@ class GhostDisplaysPlugin : JavaPlugin() { instance = this logger.info("GhostDisplays ready: ${displayRegistry.controllerCount()} controllers active.") + + server.scheduler.runTaskTimer(this, Runnable { + displayRegistry.tick() + }, 10L, 10L) } override fun onDisable() { diff --git a/src/main/kotlin/net/hareworks/ghostdisplays/display/EditSessionManager.kt b/src/main/kotlin/net/hareworks/ghostdisplays/display/EditSessionManager.kt index 363b2bd..059689f 100644 --- a/src/main/kotlin/net/hareworks/ghostdisplays/display/EditSessionManager.kt +++ b/src/main/kotlin/net/hareworks/ghostdisplays/display/EditSessionManager.kt @@ -7,7 +7,6 @@ import org.bukkit.Bukkit import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.Listener -import org.bukkit.event.player.AsyncPlayerChatEvent import org.bukkit.event.player.PlayerQuitEvent import org.bukkit.plugin.java.JavaPlugin @@ -28,10 +27,12 @@ class EditSessionManager( } @EventHandler(ignoreCancelled = true) - fun onPlayerChat(event: AsyncPlayerChatEvent) { + fun onPlayerChat(event: io.papermc.paper.event.player.AsyncChatEvent) { val displayId = sessions[event.player.uniqueId] ?: return event.isCancelled = true - val message = event.message + val serializer = net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer.plainText() + val message = serializer.serialize(event.message()) + if (message.equals("cancel", ignoreCase = true)) { sessions.remove(event.player.uniqueId) event.player.sendMessage("GhostDisplays: editing for '$displayId' cancelled.") diff --git a/src/main/kotlin/net/hareworks/ghostdisplays/internal/controller/DisplayRegistry.kt b/src/main/kotlin/net/hareworks/ghostdisplays/internal/controller/DisplayRegistry.kt index 39f0c6d..b031b7c 100644 --- a/src/main/kotlin/net/hareworks/ghostdisplays/internal/controller/DisplayRegistry.kt +++ b/src/main/kotlin/net/hareworks/ghostdisplays/internal/controller/DisplayRegistry.kt @@ -81,4 +81,19 @@ internal class DisplayRegistry : Listener { if (controllers.isEmpty()) return controllers.forEach { it.refreshAudience(player) } } + + fun tick() { + val players = org.bukkit.Bukkit.getOnlinePlayers() + if (players.isEmpty()) return + val controllers = controllersSnapshot() + if (controllers.isEmpty()) return + + // 最適化: 動的な評価が必要なコントローラーだけ抽出できれば良いが、 + // 現状はシンプルに全走査する。 + players.forEach { player -> + controllers.forEach { controller -> + controller.refreshAudience(player) + } + } + } }