From 07b18d16f79913404e037ad98aa9c0914fc4ff3f Mon Sep 17 00:00:00 2001 From: Hare Date: Thu, 4 Dec 2025 08:54:56 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=96=E9=83=A8=E3=81=8B=E3=82=89?= =?UTF-8?q?=E4=BD=BF=E3=81=86=E3=81=A8=E3=82=A8=E3=83=A9=E3=83=BC=E3=81=AE?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=E3=81=AB=E3=81=AA=E3=82=8B=E9=96=A2=E6=95=B0?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 23 ++++++++++--------- .../kommand-lib/context/KommandContext.kt | 22 ------------------ 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index f18d8ae..4c0518f 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ dependencies { 1. プラグインの `onEnable` などで `kommand(plugin) { ... }` DSL を呼び出します。 2. `command("root", "alias") { ... }` でコマンドを宣言し、`literal` や `string`/`integer` 引数を追加します。 -3. `executes { ... }` は必ず対象のノード (`literal`, `player`, `integer` など) の中にネストします。これにより、そのノードまでに宣言した引数を `string("player")` や `int("amount")` のように取得できます。 +3. `executes { ... }` は必ず対象のノード (`literal`, `player`, `integer` など) の中にネストします。これにより、そのノードまでに宣言した引数を `argument("player")` や `argument("amount")` のように取得できます。 ### サンプル: 経済コマンド @@ -52,8 +52,8 @@ class EconomyPlugin : JavaPlugin() { player("target") { // プレイヤー名 or セレクター (@p 等) integer("amount", min = 1) { executes { - val target = player("target") - val amount = int("amount") + val target: Player = argument("target") + val amount = argument("amount") sender.sendMessage("Giving $amount to ${target.name}") } } @@ -64,8 +64,8 @@ class EconomyPlugin : JavaPlugin() { players("targets") { // @a, プレイヤー名, などをまとめて取得 float("value", min = 0.1, max = 5.0) { executes { - val targets = players("targets") - val speed = float("value") + val targets: List = argument("targets") + val speed = argument("value") targets.forEach { it.walkSpeed = speed.toFloat() / 5.0f } sender.sendMessage("Updated ${targets.size} players") } @@ -77,7 +77,8 @@ class EconomyPlugin : JavaPlugin() { coordinates("point") { // "~ ~1 ~-2" のような入力を受け付ける executes { val base = (sender as? Player)?.location ?: return@executes - val target = location("point", base) + val coords = argument("point") + val target = coords.resolve(base) plugin.server.worlds.first().setSpawnLocation(target) sender.sendMessage("Spawn set to ${target.x}, ${target.y}, ${target.z}") } @@ -87,7 +88,7 @@ class EconomyPlugin : JavaPlugin() { literal("inspect") { selector("entities") { executes { - val entities = selector("entities") + val entities: List = argument("entities") sender.sendMessage("Selector resolved ${entities.size} entities") } } @@ -105,10 +106,10 @@ class EconomyPlugin : JavaPlugin() { ### DSL 構文のポイント - `literal("sub") { ... }` は固定語句を表すノードです。`requires("permission.node")` でその枝のみにパーミッションを設定できます。 -- `string("name")` や `integer("value", min = 0)` は値をパースし、成功すると `KommandContext` に記憶されます。 -- `float("speed")` は倍精度を、`player("target")`/`players("targets")`/`selector("entities")` は Minecraft の標準セレクター (`@p`, `@a`, `@s` など) やプレイヤー名を型付きで扱えます。 +- `string("name")` や `integer("value", min = 0)` は値をパースし、成功すると `KommandContext` に記憶されます。取得時は `argument("name")` や `argument("value")` を呼び出してください。 +- `float("speed")` や `player("target")`/`players("targets")`/`selector("entities")` は Minecraft の標準セレクター (`@p`, `@a`, `@s` など) やプレイヤー名を型付きで扱えます。実行時は `argument("speed")`、`argument("target")`、`argument>("targets")` のように取得できます。 - `suggests { prefix -> ... }` を指定すると、タブ補完時に任意の候補リストを返せます。 -- `coordinates("pos")` は `x y z` をまとめて 1 つの引数として受け取り、`location("pos", player.location)` で現在位置を基準に解決できます (`~` を使用した相対座標に対応)。 +- `coordinates("pos")` は `x y z` をまとめて 1 つの引数として受け取り、`argument("pos").resolve(player.location)` で現在位置を基準に解決できます (`~` を使用した相対座標に対応)。 - `command` や各ノードの `condition { sender -> ... }` で実行条件 (例: コンソール禁止) を追加できます。 - ルートレベルで `executes { ... }` を指定すると、引数なしで `/eco` を実行した場合に呼び出されます。 @@ -159,7 +160,7 @@ commands = kommand(this) { | `selector("entities")` | `List` | Bukkit の `Bukkit.selectEntities` をそのまま利用 | | `coordinates("pos")` | `Coordinates3` | `~` 相対座標を含む 3 軸をまとめて扱う | -`Coordinates3` は `coordinates("pos") { ... }` 直後のコンテキストで `coordinates("pos")` もしくは `location("pos", baseLocation)` として取得できます。 +`Coordinates3` は `coordinates("pos") { ... }` 直後のコンテキストで `argument("pos")` として取得でき、`resolve(baseLocation)` で基準座標に対して実座標を求められます。 ## ビルドとテスト diff --git a/src/main/kotlin/net/hareworks/kommand-lib/context/KommandContext.kt b/src/main/kotlin/net/hareworks/kommand-lib/context/KommandContext.kt index 6fd7798..3bf4f93 100644 --- a/src/main/kotlin/net/hareworks/kommand-lib/context/KommandContext.kt +++ b/src/main/kotlin/net/hareworks/kommand-lib/context/KommandContext.kt @@ -1,10 +1,6 @@ package net.hareworks.kommand_lib.context -import net.hareworks.kommand_lib.arguments.Coordinates3 -import org.bukkit.Location import org.bukkit.command.CommandSender -import org.bukkit.entity.Entity -import org.bukkit.entity.Player import org.bukkit.plugin.java.JavaPlugin import net.hareworks.kommand_lib.execution.ParseMode @@ -35,21 +31,3 @@ open class KommandContext internal constructor( fun arguments(): Map = parsedArguments.toMap() } - -fun KommandContext.string(name: String): String = argument(name) - -fun KommandContext.int(name: String): Int = argument(name) - -fun KommandContext.double(name: String): Double = argument(name) - -fun KommandContext.float(name: String): Double = argument(name) - -fun KommandContext.player(name: String): Player = argument(name) - -fun KommandContext.players(name: String): List = argument(name) - -fun KommandContext.selector(name: String): List = argument(name) - -fun KommandContext.coordinates(name: String): Coordinates3 = argument(name) - -fun KommandContext.location(name: String, origin: Location): Location = coordinates(name).resolve(origin)