From c70991f4ae23b1e0b9603ec45f380cdfe4406a00 Mon Sep 17 00:00:00 2001 From: TheBjoRedCraft Date: Tue, 3 Mar 2026 15:42:12 +0100 Subject: [PATCH 1/3] feat: implement synchronization for event server display name --- .../kotlin/dev/slne/surf/lobby/PaperMain.kt | 5 +++ .../slne/surf/lobby/hook/npc/SurfNpcHook.kt | 33 +++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/dev/slne/surf/lobby/PaperMain.kt b/src/main/kotlin/dev/slne/surf/lobby/PaperMain.kt index 6e7b60a..85a7279 100644 --- a/src/main/kotlin/dev/slne/surf/lobby/PaperMain.kt +++ b/src/main/kotlin/dev/slne/surf/lobby/PaperMain.kt @@ -22,6 +22,7 @@ class PaperMain : SuspendingJavaPlugin() { lateinit var redisApi: RedisApi override fun onEnable() { if (surfNpcHook) { + SurfNpcHook.startSyncTask() SurfNpcHook.initialize() } @@ -50,6 +51,10 @@ class PaperMain : SuspendingJavaPlugin() { } override fun onDisable() { + if (surfNpcHook) { + SurfNpcHook.stopSyncTask() + } + redisApi.disconnect() } diff --git a/src/main/kotlin/dev/slne/surf/lobby/hook/npc/SurfNpcHook.kt b/src/main/kotlin/dev/slne/surf/lobby/hook/npc/SurfNpcHook.kt index 212e4bc..2069705 100644 --- a/src/main/kotlin/dev/slne/surf/lobby/hook/npc/SurfNpcHook.kt +++ b/src/main/kotlin/dev/slne/surf/lobby/hook/npc/SurfNpcHook.kt @@ -22,10 +22,13 @@ import dev.slne.surf.surfapi.core.api.font.toSmallCaps import dev.slne.surf.surfapi.core.api.messages.adventure.clickOpensUrl import dev.slne.surf.surfapi.core.api.messages.adventure.playSound import dev.slne.surf.surfapi.core.api.messages.adventure.sendText +import io.papermc.paper.threadedregions.scheduler.ScheduledTask import net.kyori.adventure.text.format.TextDecoration +import org.bukkit.Bukkit import org.bukkit.Sound import org.bukkit.entity.EntityType import org.bukkit.entity.Player +import java.util.concurrent.TimeUnit object SurfNpcHook { lateinit var survivalNpc: Npc @@ -36,6 +39,8 @@ object SurfNpcHook { lateinit var spawnEventNpc: Npc lateinit var shopNpc: Npc + var eventServerDisplayName: String = "Event" + fun initialize() { createSurvivalNpc() createEventNpc() @@ -90,13 +95,6 @@ object SurfNpcHook { } } - private val eventServerDisplayName by lazy { - val server = surfCoreApi.getServerByName(lobbyConfig.eventServerName) - ?: error("Event server with name ${lobbyConfig.eventServerName} not found") - - server.displayName - } - private fun createEventNpc() { eventNpc = npc { displayName = { @@ -284,4 +282,25 @@ object SurfNpcHook { } } ?: error("Event server with name ${lobbyConfig.eventServerName} not found") } + + private lateinit var syncTask: ScheduledTask + + fun startSyncTask() { + syncTask = Bukkit.getAsyncScheduler().runAtFixedRate(plugin, { + val server = + surfCoreApi.getServerByName(lobbyConfig.eventServerName) ?: return@runAtFixedRate + + if (eventServerDisplayName != server.displayName) { + eventServerDisplayName = server.displayName + + eventNpc.refresh() + } + }, 0L, 30L, TimeUnit.SECONDS) + } + + fun stopSyncTask() { + if (::syncTask.isInitialized) { + syncTask.cancel() + } + } } \ No newline at end of file From 50a864830f7682c142075c0f0564acfa1022ef2b Mon Sep 17 00:00:00 2001 From: TheBjoRedCraft Date: Tue, 3 Mar 2026 15:42:21 +0100 Subject: [PATCH 2/3] chore: update version to 1.21.11-3.0.8-SNAPSHOT --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ee09553..97e7b74 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ kotlin.code.style=official kotlin.stdlib.default.dependency=false org.gradle.parallel=true -version=1.21.11-3.0.7-SNAPSHOT \ No newline at end of file +version=1.21.11-3.0.8-SNAPSHOT \ No newline at end of file From 4f4c256a6f7b890e5355891bbc85a4439696f4c1 Mon Sep 17 00:00:00 2001 From: TheBjoRedCraft Date: Tue, 3 Mar 2026 15:44:27 +0100 Subject: [PATCH 3/3] fix: ensure SurfNpcHook synchronization task starts after initialization --- src/main/kotlin/dev/slne/surf/lobby/PaperMain.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/dev/slne/surf/lobby/PaperMain.kt b/src/main/kotlin/dev/slne/surf/lobby/PaperMain.kt index 85a7279..8a82e36 100644 --- a/src/main/kotlin/dev/slne/surf/lobby/PaperMain.kt +++ b/src/main/kotlin/dev/slne/surf/lobby/PaperMain.kt @@ -22,8 +22,8 @@ class PaperMain : SuspendingJavaPlugin() { lateinit var redisApi: RedisApi override fun onEnable() { if (surfNpcHook) { - SurfNpcHook.startSyncTask() SurfNpcHook.initialize() + SurfNpcHook.startSyncTask() } if (surfHologramHook) {