summaryrefslogtreecommitdiff
path: root/platform-paper
diff options
context:
space:
mode:
authorSho Sakuma <me@m1sk9.dev>2026-01-24 01:07:42 +0900
committerSho Sakuma <me@m1sk9.dev>2026-01-24 01:17:19 +0900
commit774bab351b7023e2b06f0d7495c334836eb383d5 (patch)
tree08370a59875f7fc267422e7de10e4101ffe5a01e /platform-paper
parentfc5caa61437e49f275f8d3075bbb460430f4f19b (diff)
downloadLunaticChat-774bab351b7023e2b06f0d7495c334836eb383d5.tar.gz
LunaticChat-774bab351b7023e2b06f0d7495c334836eb383d5.tar.bz2
LunaticChat-774bab351b7023e2b06f0d7495c334836eb383d5.zip
feat: Add new permission
Diffstat (limited to 'platform-paper')
-rw-r--r--platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt2
-rw-r--r--platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/annotation/Permission.kt6
-rw-r--r--platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/core/LunaticCommand.kt23
-rw-r--r--platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/LunaticChatCommand.kt7
-rw-r--r--platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/SettingsCommand.kt16
-rw-r--r--platform-paper/src/main/resources/languages/en.yml1
-rw-r--r--platform-paper/src/main/resources/languages/ja.yml1
-rw-r--r--platform-paper/src/main/resources/paper-plugin.yml6
8 files changed, 55 insertions, 7 deletions
diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt
index c4cf9ec..78232c2 100644
--- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt
+++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt
@@ -3,9 +3,9 @@ package dev.m1sk9.lunaticChat.paper
import dev.m1sk9.lunaticChat.engine.converter.GoogleIMEClient
import dev.m1sk9.lunaticChat.paper.command.core.CommandRegistry
import dev.m1sk9.lunaticChat.paper.command.handler.DirectMessageHandler
-import dev.m1sk9.lunaticChat.paper.command.impl.lc.LunaticChatCommand
import dev.m1sk9.lunaticChat.paper.command.impl.ReplyCommand
import dev.m1sk9.lunaticChat.paper.command.impl.TellCommand
+import dev.m1sk9.lunaticChat.paper.command.impl.lc.LunaticChatCommand
import dev.m1sk9.lunaticChat.paper.command.setting.SettingHandlerRegistry
import dev.m1sk9.lunaticChat.paper.command.setting.handler.DirectMessageNoticeSettingHandler
import dev.m1sk9.lunaticChat.paper.command.setting.handler.JapaneseConversionSettingHandler
diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/annotation/Permission.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/annotation/Permission.kt
index d96e1b5..15f7535 100644
--- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/annotation/Permission.kt
+++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/annotation/Permission.kt
@@ -6,9 +6,13 @@ import kotlin.reflect.KClass
/**
* Restricts command execution to senders with the specified permission.
*
+ * Can be applied to:
+ * - Classes: Restricts the entire command
+ * - Functions: Restricts a specific subcommand (when applied to build() methods)
+ *
* @param value The permission node required to execute this command
*/
-@Target(AnnotationTarget.CLASS)
+@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class Permission(
val value: KClass<out LunaticChatPermissionNode>,
diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/core/LunaticCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/core/LunaticCommand.kt
index b11fd1a..817c002 100644
--- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/core/LunaticCommand.kt
+++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/core/LunaticCommand.kt
@@ -11,6 +11,8 @@ import io.papermc.paper.command.brigadier.CommandSourceStack
import io.papermc.paper.command.brigadier.Commands
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor
+import kotlin.reflect.full.findAnnotation
+import kotlin.reflect.full.memberFunctions
/**
* Abstract base class for all LunaticChat commands.
@@ -130,4 +132,25 @@ abstract class LunaticCommand(
}
return result.toBrigadierResult()
}
+
+ /**
+ * Applies permission checks to a subcommand builder based on method-level @Permission annotation.
+ * Used for subcommands that use build() instead of buildCommand().
+ *
+ * @param methodName The name of the method to check for @Permission annotation
+ * @param builder The subcommand builder to wrap
+ * @return The builder with permission checks applied if annotation is present
+ */
+ protected fun applyMethodPermission(
+ methodName: String,
+ builder: LiteralArgumentBuilder<CommandSourceStack>,
+ ): LiteralArgumentBuilder<CommandSourceStack> {
+ val method = this::class.memberFunctions.find { it.name == methodName } ?: return builder
+ val permissionAnnotation = method.findAnnotation<Permission>() ?: return builder
+ val permissionNode = permissionAnnotation.value.objectInstance?.permissionNode ?: return builder
+
+ return builder.requires { source ->
+ source.sender.hasPermission(permissionNode)
+ }
+ }
}
diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/LunaticChatCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/LunaticChatCommand.kt
index ba3adf4..1ced328 100644
--- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/LunaticChatCommand.kt
+++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/LunaticChatCommand.kt
@@ -1,8 +1,11 @@
package dev.m1sk9.lunaticChat.paper.command.impl.lc
import com.mojang.brigadier.builder.LiteralArgumentBuilder
+import dev.m1sk9.lunaticChat.engine.permission.LunaticChatPermissionNode
import dev.m1sk9.lunaticChat.paper.LunaticChat
import dev.m1sk9.lunaticChat.paper.command.annotation.Command
+import dev.m1sk9.lunaticChat.paper.command.annotation.Permission
+import dev.m1sk9.lunaticChat.paper.command.annotation.PlayerOnly
import dev.m1sk9.lunaticChat.paper.command.core.LunaticCommand
import dev.m1sk9.lunaticChat.paper.command.setting.SettingHandlerRegistry
import dev.m1sk9.lunaticChat.paper.i18n.LanguageManager
@@ -18,6 +21,8 @@ import io.papermc.paper.command.brigadier.Commands
aliases = ["lunaticchat"],
description = "",
)
+@Permission(LunaticChatPermissionNode.Lc::class)
+@PlayerOnly
class LunaticChatCommand(
plugin: LunaticChat,
private val settingHandlerRegistry: SettingHandlerRegistry,
@@ -34,6 +39,6 @@ class LunaticChatCommand(
plugin,
settingHandlerRegistry,
languageManager,
- ).build(),
+ ).buildWithPermissionCheck(),
)
}
diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/SettingsCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/SettingsCommand.kt
index b6a79b3..7e6b658 100644
--- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/SettingsCommand.kt
+++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/SettingsCommand.kt
@@ -2,7 +2,9 @@ package dev.m1sk9.lunaticChat.paper.command.impl.lc
import com.mojang.brigadier.builder.LiteralArgumentBuilder
import dev.m1sk9.lunaticChat.engine.command.CommandResult
+import dev.m1sk9.lunaticChat.engine.permission.LunaticChatPermissionNode
import dev.m1sk9.lunaticChat.paper.LunaticChat
+import dev.m1sk9.lunaticChat.paper.command.annotation.Permission
import dev.m1sk9.lunaticChat.paper.command.annotation.PlayerOnly
import dev.m1sk9.lunaticChat.paper.command.core.CommandContext
import dev.m1sk9.lunaticChat.paper.command.core.LunaticCommand
@@ -29,12 +31,22 @@ class SettingsCommand(
private val languageManager: LanguageManager,
) : LunaticCommand(plugin) {
/**
+ * Builds the setting subcommand structure with permission checks.
+ * This method should be called from parent commands.
+ */
+ fun buildWithPermissionCheck(): LiteralArgumentBuilder<CommandSourceStack> {
+ val builder = build()
+ return applyMethodPermission("build", builder)
+ }
+
+ /**
* Builds the setting subcommand structure.
* For each registered setting key, creates:
* - /lc setting <key> on
* - /lc setting <key> off
* - /lc setting <key> (shows status)
*/
+ @Permission(LunaticChatPermissionNode.Settings::class)
fun build(): LiteralArgumentBuilder<CommandSourceStack> {
val settingCommand = Commands.literal("settings")
@@ -92,7 +104,9 @@ class SettingsCommand(
private fun showHelp(ctx: CommandContext): CommandResult {
val availableKeys = settingHandlerRegistry.getAvailableKeys()
val helpMessage =
- MessageFormatter.format(languageManager.getMessage("settingsAvailableValues", mapOf("values" to availableKeys.joinToString(", "))))
+ MessageFormatter.format(
+ languageManager.getMessage("settingsAvailableValues", mapOf("values" to availableKeys.joinToString(", "))),
+ )
ctx.reply(helpMessage)
return CommandResult.Success
diff --git a/platform-paper/src/main/resources/languages/en.yml b/platform-paper/src/main/resources/languages/en.yml
index 7e312c8..c26ace2 100644
--- a/platform-paper/src/main/resources/languages/en.yml
+++ b/platform-paper/src/main/resources/languages/en.yml
@@ -27,6 +27,7 @@ romajiConversionToggle: "Romaji-to-kana conversion has been set to {toggle}"
settingsAvailableValues: "Available settings value: {values}"
tellTargetOffline: "Player '{target}' is currently offline."
tellYourself: "You cannot send a message to yourself."
+noPermission: "You do not have permission to execute this command."
toggle:
off: "Disabled"
diff --git a/platform-paper/src/main/resources/languages/ja.yml b/platform-paper/src/main/resources/languages/ja.yml
index cd93098..70f0cc1 100644
--- a/platform-paper/src/main/resources/languages/ja.yml
+++ b/platform-paper/src/main/resources/languages/ja.yml
@@ -27,6 +27,7 @@ romajiConversionStatus: "現在かな・ローマ字変換機能は{toggle}で
settingsAvailableValues: "使用可能な設定値: {values}"
tellTargetOffline: "プレイヤー '{target}' は現在オフラインです"
tellYourself: "自分自身にメッセージを送信することはできません"
+noPermission: "このコマンドを実行する権限がありません"
toggle:
on: "有効"
diff --git a/platform-paper/src/main/resources/paper-plugin.yml b/platform-paper/src/main/resources/paper-plugin.yml
index af90681..40c3fc3 100644
--- a/platform-paper/src/main/resources/paper-plugin.yml
+++ b/platform-paper/src/main/resources/paper-plugin.yml
@@ -9,13 +9,13 @@ description: Next-generation channel chat plugin for Paper/Velocity
website: lc.m1sk9.dev
permissions:
+ lunaticchat.command.lc:
+ default: true
lunaticchat.command.tell:
default: true
lunaticchat.command.reply:
default: true
- lunaticchat.command.jp:
- default: true
- lunaticchat.command.notice:
+ lunaticchat.command.lc.settings:
default: true
lunaticchat.spy: