From c5e355b851ad4d71d32d3c10f89aa4ed1f6dc41c Mon Sep 17 00:00:00 2001 From: Sho Sakuma Date: Mon, 26 Jan 2026 00:59:43 +0900 Subject: feat: Add chatmode data --- .../lunaticChat/engine/channel/modal/Channel.kt | 40 -------------------- .../engine/channel/modal/ChannelData.kt | 11 ------ .../engine/channel/modal/ChannelMember.kt | 22 ----------- .../engine/channel/modal/ChannelRole.kt | 17 --------- .../dev/m1sk9/lunaticChat/engine/chat/ChatMode.kt | 43 ++++++++++++++++++++++ .../m1sk9/lunaticChat/engine/chat/ChatModeData.kt | 14 +++++++ .../lunaticChat/engine/chat/channel/Channel.kt | 40 ++++++++++++++++++++ .../lunaticChat/engine/chat/channel/ChannelData.kt | 11 ++++++ .../engine/chat/channel/ChannelMember.kt | 22 +++++++++++ .../lunaticChat/engine/chat/channel/ChannelRole.kt | 17 +++++++++ .../engine/exception/ChatModeStorageException.kt | 6 +++ .../engine/permission/LunaticChatPermissionNode.kt | 4 ++ 12 files changed, 157 insertions(+), 90 deletions(-) delete mode 100644 engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/Channel.kt delete mode 100644 engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelData.kt delete mode 100644 engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelMember.kt delete mode 100644 engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelRole.kt create mode 100644 engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/ChatMode.kt create mode 100644 engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/ChatModeData.kt create mode 100644 engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/Channel.kt create mode 100644 engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelData.kt create mode 100644 engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelMember.kt create mode 100644 engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelRole.kt create mode 100644 engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/exception/ChatModeStorageException.kt (limited to 'engine') diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/Channel.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/Channel.kt deleted file mode 100644 index 427e526..0000000 --- a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/Channel.kt +++ /dev/null @@ -1,40 +0,0 @@ -package dev.m1sk9.lunaticChat.engine.channel.modal - -import dev.m1sk9.lunaticChat.engine.settings.UUIDSerializer -import kotlinx.serialization.Serializable -import java.util.UUID - -/** - * Represents a communication channel within the LunaticChat application. - * - * @property id Unique identifier for the channel. - * @property name Name of the channel. - * @property description Optional description of the channel. - * @property isPrivate Indicates whether the channel is private or public. - * @property ownerId UUID of the user who owns the channel. - * @property createdAt Timestamp of when the channel was created. - */ -@Serializable -data class Channel( - val id: String, - val name: String, - val description: String? = null, - val isPrivate: Boolean = false, - @Serializable(with = UUIDSerializer::class) - val ownerId: UUID, - val createdAt: Long = System.currentTimeMillis(), -) { - init { - require(id.matches(CHANNEL_ID_PATTERN)) { - "Channel ID must be 3-30 characters long and can only contain letters, numbers, underscores, and hyphens." - } - - require(name.isNotBlank()) { - "Channel name cannot be blank." - } - } - - companion object { - val CHANNEL_ID_PATTERN = Regex("^[a-zA-Z0-9_-]{3,30}$") - } -} diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelData.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelData.kt deleted file mode 100644 index 67e86ec..0000000 --- a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelData.kt +++ /dev/null @@ -1,11 +0,0 @@ -package dev.m1sk9.lunaticChat.engine.channel.modal - -import kotlinx.serialization.Serializable - -@Serializable -data class ChannelData( - val version: Int = 1, - val channels: Map = emptyMap(), - val members: Map> = emptyMap(), - val activeChannels: Map = emptyMap(), -) diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelMember.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelMember.kt deleted file mode 100644 index 3bc2b67..0000000 --- a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelMember.kt +++ /dev/null @@ -1,22 +0,0 @@ -package dev.m1sk9.lunaticChat.engine.channel.modal - -import dev.m1sk9.lunaticChat.engine.settings.UUIDSerializer -import kotlinx.serialization.Serializable -import java.util.UUID - -/** - * Represents a member of a channel with their role and join timestamp. - * - * @property channelId The ID of the channel. - * @property playerId The UUID of the player. - * @property role The role of the member in the channel. - * @property joinedAt The timestamp when the member joined the channel. - */ -@Serializable -data class ChannelMember( - val channelId: String, - @Serializable(with = UUIDSerializer::class) - val playerId: UUID, - val role: ChannelRole, - val joinedAt: Long = System.currentTimeMillis(), -) diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelRole.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelRole.kt deleted file mode 100644 index 6a3309a..0000000 --- a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelRole.kt +++ /dev/null @@ -1,17 +0,0 @@ -package dev.m1sk9.lunaticChat.engine.channel.modal - -import kotlinx.serialization.Serializable - -/** - * Represents the role of a user within a channel. - * - * - OWNER: The creator and primary administrator of the channel. - * - MODERATOR: A user with elevated permissions to manage channel content and users. - * - MEMBER: A regular user with standard access to the channel. - */ -@Serializable -enum class ChannelRole { - OWNER, - MODERATOR, - MEMBER, -} diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/ChatMode.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/ChatMode.kt new file mode 100644 index 0000000..98bb79d --- /dev/null +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/ChatMode.kt @@ -0,0 +1,43 @@ +package dev.m1sk9.lunaticChat.engine.chat + +/** + * Represents the chat mode for a player. + * + * Chat mode determines where messages are sent by default: + * - GLOBAL: All messages go to global chat (visible to everyone) + * - CHANNEL: All messages go to the active channel (visible to channel members only) + * + * Players can temporarily override their mode by prefixing messages with '!'. + * Chat mode is persisted and maintains its state across server restarts. + * Default mode is GLOBAL. + */ +enum class ChatMode { + /** + * Global chat mode - messages visible to all players. + */ + GLOBAL, + + /** + * Channel chat mode - messages visible only to channel members. + * Requires player to be in an active channel. + */ + CHANNEL, + ; + + /** + * Returns the opposite chat mode. + * Used when player prefixes message with '!'. + */ + fun toggle(): ChatMode = + when (this) { + GLOBAL -> CHANNEL + CHANNEL -> GLOBAL + } + + companion object { + /** + * Default chat mode for all players. + */ + val DEFAULT = GLOBAL + } +} diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/ChatModeData.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/ChatModeData.kt new file mode 100644 index 0000000..b462ede --- /dev/null +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/ChatModeData.kt @@ -0,0 +1,14 @@ +package dev.m1sk9.lunaticChat.engine.chat + +import dev.m1sk9.lunaticChat.engine.settings.UUIDSerializer +import kotlinx.serialization.Serializable +import java.util.UUID + +@Serializable +data class ChatModeData( + val modes: Map< + @Serializable(with = UUIDSerializer::class) + UUID, + ChatMode, + > = emptyMap(), +) diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/Channel.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/Channel.kt new file mode 100644 index 0000000..cc1f743 --- /dev/null +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/Channel.kt @@ -0,0 +1,40 @@ +package dev.m1sk9.lunaticChat.engine.chat.channel + +import dev.m1sk9.lunaticChat.engine.settings.UUIDSerializer +import kotlinx.serialization.Serializable +import java.util.UUID + +/** + * Represents a communication channel within the LunaticChat application. + * + * @property id Unique identifier for the channel. + * @property name Name of the channel. + * @property description Optional description of the channel. + * @property isPrivate Indicates whether the channel is private or public. + * @property ownerId UUID of the user who owns the channel. + * @property createdAt Timestamp of when the channel was created. + */ +@Serializable +data class Channel( + val id: String, + val name: String, + val description: String? = null, + val isPrivate: Boolean = false, + @Serializable(with = UUIDSerializer::class) + val ownerId: UUID, + val createdAt: Long = System.currentTimeMillis(), +) { + init { + require(id.matches(CHANNEL_ID_PATTERN)) { + "Channel ID must be 3-30 characters long and can only contain letters, numbers, underscores, and hyphens." + } + + require(name.isNotBlank()) { + "Channel name cannot be blank." + } + } + + companion object { + val CHANNEL_ID_PATTERN = Regex("^[a-zA-Z0-9_-]{3,30}$") + } +} diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelData.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelData.kt new file mode 100644 index 0000000..de942f7 --- /dev/null +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelData.kt @@ -0,0 +1,11 @@ +package dev.m1sk9.lunaticChat.engine.chat.channel + +import kotlinx.serialization.Serializable + +@Serializable +data class ChannelData( + val version: Int = 1, + val channels: Map = emptyMap(), + val members: Map> = emptyMap(), + val activeChannels: Map = emptyMap(), +) diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelMember.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelMember.kt new file mode 100644 index 0000000..1eb49f4 --- /dev/null +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelMember.kt @@ -0,0 +1,22 @@ +package dev.m1sk9.lunaticChat.engine.chat.channel + +import dev.m1sk9.lunaticChat.engine.settings.UUIDSerializer +import kotlinx.serialization.Serializable +import java.util.UUID + +/** + * Represents a member of a channel with their role and join timestamp. + * + * @property channelId The ID of the channel. + * @property playerId The UUID of the player. + * @property role The role of the member in the channel. + * @property joinedAt The timestamp when the member joined the channel. + */ +@Serializable +data class ChannelMember( + val channelId: String, + @Serializable(with = UUIDSerializer::class) + val playerId: UUID, + val role: ChannelRole, + val joinedAt: Long = System.currentTimeMillis(), +) diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelRole.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelRole.kt new file mode 100644 index 0000000..be7bf58 --- /dev/null +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelRole.kt @@ -0,0 +1,17 @@ +package dev.m1sk9.lunaticChat.engine.chat.channel + +import kotlinx.serialization.Serializable + +/** + * Represents the role of a user within a channel. + * + * - OWNER: The creator and primary administrator of the channel. + * - MODERATOR: A user with elevated permissions to manage channel content and users. + * - MEMBER: A regular user with standard access to the channel. + */ +@Serializable +enum class ChannelRole { + OWNER, + MODERATOR, + MEMBER, +} diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/exception/ChatModeStorageException.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/exception/ChatModeStorageException.kt new file mode 100644 index 0000000..85c1e69 --- /dev/null +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/exception/ChatModeStorageException.kt @@ -0,0 +1,6 @@ +package dev.m1sk9.lunaticChat.engine.exception + +class ChatModeStorageException( + message: String, + cause: Throwable? = null, +) : Exception(message, cause) diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/permission/LunaticChatPermissionNode.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/permission/LunaticChatPermissionNode.kt index b615fb7..838a48b 100644 --- a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/permission/LunaticChatPermissionNode.kt +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/permission/LunaticChatPermissionNode.kt @@ -29,6 +29,10 @@ sealed class LunaticChatPermissionNode( object ChannelDelete : LunaticChatPermissionNode("lunaticchat.command.lc.channel.delete") + object ChatMode : LunaticChatPermissionNode("lunaticchat.command.lc.chatmode") + + object ChatModeToggle : LunaticChatPermissionNode("lunaticchat.command.lc.chatmode.toggle") + object Spy : LunaticChatPermissionNode("lunaticchat.spy") object NoticeUpdate : LunaticChatPermissionNode("lunaticchat.noticeUpdate") -- cgit v1.2.1