doc: 例示している実装の誤りを修正
This commit is contained in:
parent
3df862a0c2
commit
db6362444c
58
README.md
58
README.md
|
|
@ -34,7 +34,7 @@ dependencies {
|
|||
|
||||
1. プラグインの `onEnable` などで `kommand(plugin) { ... }` DSL を呼び出します。
|
||||
2. `command("root", "alias") { ... }` でコマンドを宣言し、`literal` や `string`/`integer` 引数を追加します。
|
||||
3. `executes { ... }` 内で `string("player")` や `int("amount")` を使ってパース済みの値を取得します。
|
||||
3. `executes { ... }` は必ず対象のノード (`literal`, `player`, `integer` など) の中にネストします。これにより、そのノードまでに宣言した引数を `string("player")` や `int("amount")` のように取得できます。
|
||||
|
||||
### サンプル: 経済コマンド
|
||||
|
||||
|
|
@ -49,45 +49,47 @@ class EconomyPlugin : JavaPlugin() {
|
|||
permission = "example.eco"
|
||||
|
||||
literal("give") {
|
||||
player("target") // プレイヤー名 or セレクター (@p 等)
|
||||
integer("amount", min = 1)
|
||||
|
||||
executes {
|
||||
val target = player("target")
|
||||
val amount = int("amount")
|
||||
sender.sendMessage("Giving $amount to ${target.name}")
|
||||
player("target") { // プレイヤー名 or セレクター (@p 等)
|
||||
integer("amount", min = 1) {
|
||||
executes {
|
||||
val target = player("target")
|
||||
val amount = int("amount")
|
||||
sender.sendMessage("Giving $amount to ${target.name}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
literal("speed") {
|
||||
players("targets") // @a, プレイヤー名, などをまとめて取得
|
||||
float("value", min = 0.1, max = 5.0)
|
||||
|
||||
executes {
|
||||
val targets = players("targets")
|
||||
val speed = float("value")
|
||||
targets.forEach { it.walkSpeed = speed.toFloat() / 5.0f }
|
||||
sender.sendMessage("Updated ${targets.size} players")
|
||||
players("targets") { // @a, プレイヤー名, などをまとめて取得
|
||||
float("value", min = 0.1, max = 5.0) {
|
||||
executes {
|
||||
val targets = players("targets")
|
||||
val speed = float("value")
|
||||
targets.forEach { it.walkSpeed = speed.toFloat() / 5.0f }
|
||||
sender.sendMessage("Updated ${targets.size} players")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
literal("setspawn") {
|
||||
coordinates("point") // "~ ~1 ~-2" のような入力を受け付ける
|
||||
|
||||
executes {
|
||||
val base = (sender as? Player)?.location ?: return@executes
|
||||
val target = location("point", base)
|
||||
plugin.server.worlds.first().setSpawnLocation(target)
|
||||
sender.sendMessage("Spawn set to ${target.x}, ${target.y}, ${target.z}")
|
||||
coordinates("point") { // "~ ~1 ~-2" のような入力を受け付ける
|
||||
executes {
|
||||
val base = (sender as? Player)?.location ?: return@executes
|
||||
val target = location("point", base)
|
||||
plugin.server.worlds.first().setSpawnLocation(target)
|
||||
sender.sendMessage("Spawn set to ${target.x}, ${target.y}, ${target.z}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
literal("inspect") {
|
||||
selector("entities")
|
||||
|
||||
executes {
|
||||
val entities = selector("entities")
|
||||
sender.sendMessage("Selector resolved ${entities.size} entities")
|
||||
selector("entities") {
|
||||
executes {
|
||||
val entities = selector("entities")
|
||||
sender.sendMessage("Selector resolved ${entities.size} entities")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user