From 4343d01d119a05dca2a0227b9e92a737f9d9fe1d Mon Sep 17 00:00:00 2001 From: Hare Date: Sun, 7 Dec 2025 04:26:22 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=AF=E8=A6=96=E5=88=87=E3=82=8A?= =?UTF-8?q?=E6=9B=BF=E3=81=88=E3=81=AEtick?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kommand-lib | 2 +- .../ghostdisplays/GhostDisplaysPlugin.kt | 4 ++++ .../ghostdisplays/display/EditSessionManager.kt | 7 ++++--- .../internal/controller/DisplayRegistry.kt | 15 +++++++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) 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) + } + } + } }