doc: 例示している実装の誤りを修正

This commit is contained in:
Keisuke Hirata 2025-12-04 08:44:20 +09:00
parent 3df862a0c2
commit db6362444c

View File

@ -34,7 +34,7 @@ dependencies {
1. プラグインの `onEnable` などで `kommand(plugin) { ... }` DSL を呼び出します。 1. プラグインの `onEnable` などで `kommand(plugin) { ... }` DSL を呼び出します。
2. `command("root", "alias") { ... }` でコマンドを宣言し、`literal` や `string`/`integer` 引数を追加します。 2. `command("root", "alias") { ... }` でコマンドを宣言し、`literal` や `string`/`integer` 引数を追加します。
3. `executes { ... }` 内で `string("player")``int("amount")` を使ってパース済みの値を取得します。 3. `executes { ... }` は必ず対象のノード (`literal`, `player`, `integer` など) の中にネストします。これにより、そのノードまでに宣言した引数を `string("player")``int("amount")` のように取得できます。
### サンプル: 経済コマンド ### サンプル: 経済コマンド
@ -49,20 +49,20 @@ class EconomyPlugin : JavaPlugin() {
permission = "example.eco" permission = "example.eco"
literal("give") { literal("give") {
player("target") // プレイヤー名 or セレクター (@p 等) player("target") { // プレイヤー名 or セレクター (@p 等)
integer("amount", min = 1) integer("amount", min = 1) {
executes { executes {
val target = player("target") val target = player("target")
val amount = int("amount") val amount = int("amount")
sender.sendMessage("Giving $amount to ${target.name}") sender.sendMessage("Giving $amount to ${target.name}")
} }
} }
}
}
literal("speed") { literal("speed") {
players("targets") // @a, プレイヤー名, などをまとめて取得 players("targets") { // @a, プレイヤー名, などをまとめて取得
float("value", min = 0.1, max = 5.0) float("value", min = 0.1, max = 5.0) {
executes { executes {
val targets = players("targets") val targets = players("targets")
val speed = float("value") val speed = float("value")
@ -70,10 +70,11 @@ class EconomyPlugin : JavaPlugin() {
sender.sendMessage("Updated ${targets.size} players") sender.sendMessage("Updated ${targets.size} players")
} }
} }
}
}
literal("setspawn") { literal("setspawn") {
coordinates("point") // "~ ~1 ~-2" のような入力を受け付ける coordinates("point") { // "~ ~1 ~-2" のような入力を受け付ける
executes { executes {
val base = (sender as? Player)?.location ?: return@executes val base = (sender as? Player)?.location ?: return@executes
val target = location("point", base) val target = location("point", base)
@ -81,10 +82,10 @@ class EconomyPlugin : JavaPlugin() {
sender.sendMessage("Spawn set to ${target.x}, ${target.y}, ${target.z}") sender.sendMessage("Spawn set to ${target.x}, ${target.y}, ${target.z}")
} }
} }
}
literal("inspect") { literal("inspect") {
selector("entities") selector("entities") {
executes { executes {
val entities = selector("entities") val entities = selector("entities")
sender.sendMessage("Selector resolved ${entities.size} entities") sender.sendMessage("Selector resolved ${entities.size} entities")
@ -93,6 +94,7 @@ class EconomyPlugin : JavaPlugin() {
} }
} }
} }
}
override fun onDisable() { override fun onDisable() {
commands.unregister() commands.unregister()