summaryrefslogtreecommitdiff
path: root/platform-paper/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'platform-paper/src/main')
-rw-r--r--platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManager.kt40
-rw-r--r--platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/listener/PlayerPresenceListener.kt40
-rw-r--r--platform-paper/src/main/resources/languages/en.yml2
-rw-r--r--platform-paper/src/main/resources/languages/ja.yml2
4 files changed, 68 insertions, 16 deletions
diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManager.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManager.kt
index ffc6e26..7305266 100644
--- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManager.kt
+++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManager.kt
@@ -436,9 +436,49 @@ class ChannelManager(
*/
fun getPlayerChannelContext(playerId: UUID): ChannelContext? {
val channelId = activeChannels[playerId] ?: return null
+ val channel = channelsCache[channelId]
+ val members = membersCache[channelId]?.toList()
+
+ if (channel == null || members == null) {
+ activeChannels.remove(playerId)
+ saveToStorage()
+ return null
+ }
+
+ return ChannelContext(
+ channelId = channelId,
+ channel = channel,
+ members = members,
+ )
+ }
+
+ /**
+ * Restores the active channel of a player based on their channel membership.
+ * If the player is a member of multiple channels, the most recently joined one is selected.
+ *
+ * @param playerId The UUID of the player.
+ * @return The restored ChannelContext, or null if the player is not a member of any channel.
+ */
+ fun restorePlayerChannel(playerId: UUID): ChannelContext? {
+ // Already has an active channel
+ getPlayerChannelContext(playerId)?.let { return it }
+
+ // Find the most recently joined channel for this player
+ val channelId =
+ membersCache.entries
+ .mapNotNull { (channelId, members) ->
+ members.find { it.playerId == playerId }?.let { member ->
+ channelId to member.joinedAt
+ }
+ }.maxByOrNull { it.second }
+ ?.first ?: return null
+
val channel = channelsCache[channelId] ?: return null
val members = membersCache[channelId]?.toList() ?: return null
+ activeChannels[playerId] = channelId
+ saveToStorage()
+
return ChannelContext(
channelId = channelId,
channel = channel,
diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/listener/PlayerPresenceListener.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/listener/PlayerPresenceListener.kt
index 3979246..56cbe59 100644
--- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/listener/PlayerPresenceListener.kt
+++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/listener/PlayerPresenceListener.kt
@@ -12,6 +12,7 @@ import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.event.player.PlayerQuitEvent
+import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
class PlayerPresenceListener(
@@ -27,25 +28,36 @@ class PlayerPresenceListener(
// Send update notification if available
if (updateCheckerFlag.get() && player.hasAnyPermission { +LunaticChatPermissionNode.NoticeUpdate }) {
- player.sendMessage(
- MessageFormatter
- .format(languageManager.getMessage("general.newUpdateAvailable"))
- .clickEvent(ClickEvent.openUrl("https://github.com/m1sk9/LunaticChat/releases/latest")),
- )
+ lunaticChat.server.asyncScheduler.runDelayed(lunaticChat, { _ ->
+ if (player.isOnline) {
+ player.sendMessage(
+ MessageFormatter
+ .format(languageManager.getMessage("general.newUpdateAvailable"))
+ .clickEvent(ClickEvent.openUrl("https://github.com/m1sk9/LunaticChat/releases/latest")),
+ )
+ }
+ }, 3, TimeUnit.SECONDS)
}
- // Send channel notification if in a channel
+ // Restore active channel from membership and notify (delayed to avoid being buried by other plugins' join messages)
channelManager?.let { manager ->
- val context = manager.getPlayerChannelContext(player.uniqueId)
+ val context = manager.restorePlayerChannel(player.uniqueId)
context?.let {
val notification =
- MessageFormatter.format(
- languageManager.getMessage(
- "channel.notification.login",
- mapOf("channelName" to it.channel.name),
- ),
- )
- player.sendMessage(notification)
+ MessageFormatter
+ .format(
+ languageManager.getMessage(
+ "channel.notification.login",
+ mapOf("channelName" to it.channel.name),
+ ),
+ ).clickEvent(
+ ClickEvent.runCommand("/lc channel status"),
+ )
+ lunaticChat.server.asyncScheduler.runDelayed(lunaticChat, { _ ->
+ if (player.isOnline) {
+ player.sendMessage(notification)
+ }
+ }, 3, TimeUnit.SECONDS)
}
}
}
diff --git a/platform-paper/src/main/resources/languages/en.yml b/platform-paper/src/main/resources/languages/en.yml
index d932105..04ca56a 100644
--- a/platform-paper/src/main/resources/languages/en.yml
+++ b/platform-paper/src/main/resources/languages/en.yml
@@ -132,7 +132,7 @@ channel:
noActiveChannel: "You don't have an active channel. Please specify a channel ID"
error: "Failed to retrieve channel information"
notification:
- login: "You are in channel '{channelName}'"
+ login: "You are currently in the channel '{channelName}'. You can check the channel's status by typing /lc channel status."
playerJoined: "{player} joined {channel}"
playerLeft: "{player} left {channel}"
playerKicked: "{player} was kicked from {channel} by {kicker}"
diff --git a/platform-paper/src/main/resources/languages/ja.yml b/platform-paper/src/main/resources/languages/ja.yml
index fbf09f9..74f2dfb 100644
--- a/platform-paper/src/main/resources/languages/ja.yml
+++ b/platform-paper/src/main/resources/languages/ja.yml
@@ -132,7 +132,7 @@ channel:
noActiveChannel: "アクティブなチャンネルがありません。チャンネルIDを指定してください"
error: "チャンネル情報の取得に失敗しました"
notification:
- login: "チャンネル '{channelName}' に入室中です"
+ login: "現在、チャンネル '{channelName}' に入室中です。チャンネルの状態は /lc channel status で確認できます"
playerJoined: "{player}がチャンネル {channel} に参加しました"
playerLeft: "{player}がチャンネル {channel} から退出しました"
playerKicked: "{player}は{kicker}によってチャンネル {channel} から追放されました"