API

コマンドと権限

型付きの引数、サブコマンド、エイリアス、候補表示、権限を持つコマンド。誰かが使い方を間違えると、そのメッセージを書かなくても正しい使い方が表示されます。

CraftScript では

commands/ に、1 つのコマンドにつき 1 ファイル、コマンドと同じ名前で置きます。

commands/pay.craftCraftScript
command pay(to: player, amount: int) requires "eco.pay" alias "send" describe "コインを送る" {
    if player == null { return "プレイヤー専用です" }
    if amount <= 0 { return "&c金額は正の数にしてください" }
    return "{to.name} に {amount} コインを送りました"
}
commands/announce.craftCraftScript
command announce(message: text) requires "eco.admin" describe "全員に告知する" {
    broadcast("&6[お知らせ] {message}")
}

引数が足りない、または期待する型でない場合、プレイヤーにはたとえば Missing <amount>. Usage: /pay <to> <amount> や 'abc' is not a whole number と表示されます。

型 受け付けるもの
player オンラインのプレイヤー。候補が表示されます
int、number 整数、数値
bool true/false、yes/no、on/off
string 1 語、または引用符で囲んだ複数語
text 行の残り全部
id ゲームの id(minecraft:stone)

? を付けると引数が省略可能になります(target: player?)。

Kotlin では

commands/HomeCommand.ktKotlin
package com.example.homes.commands

object HomeCommand {
    private val homes = mutableMapOf<UUID, Location>()

    fun register() {
        Crafting.commands.command("home") {
            description = "ホームにテレポートする"
            alias("h")
            executes { c -> c.player.teleport(homes[c.player.uuid] ?: c.fail("&cホームが設定されていません")) }
            sub("set") {
                executes { c -> homes[c.player.uuid] = c.player.location; c.reply("&aホームを設定しました") }
            }
            sub("of") {
                permission = "homes.others"
                player("target")
                executes { c -> c.player.teleport(homes[c.player("target").uuid] ?: c.fail("&cホームがありません")) }
            }
        }
    }
}

引数:string、greedy、int、double、bool、player、identifier。それぞれ optional にできます。executes の中では、c.player(実行した人)、c.player("target")、c.int("n")、c.getOrNull<Int>("n")、c.reply(…)、そしてエラーメッセージを出して中断する c.fail(…) が使えます。

権限

Crafting にはグループベースの権限が付属しており、config/crafting/permissions.json にあります。サーバーのオペレーターはすべての権限を持ちます。

config/crafting/permissions.jsonJSON
{
  "groups": {
    "default": ["homes.use", "eco.pay"],
    "mod": ["homes.*", "chatguard.*", "-homes.others"],
    "admin": ["*"]
  },
  "players": {
    "Steve": { "groups": ["mod"], "permissions": ["homes.others"] }
  }
}
  • * はすべてを許可し、homes.* は homes. で始まるすべてを許可します。
  • -permission は拒否します。最も具体的なルールが優先され、同じ場合は拒否が優先されます。
  • すべてのプレイヤーは default グループに属します。
  • 他の Mod と衝突しないよう、権限には Mod の id を前に付けましょう(rubies.give)。

Crafting のコマンド

ゲーム内からもサーバーのコンソールからも使えます。

コマンド 内容
/crafting(または /cf) バージョンとヘルプ。
/crafting mods 読み込まれた Mod とその状態。
/crafting reload <id> スクリプトかプラグインを再読み込みします。crafting.admin が必要です。
/crafting profile 1 回目で計測を開始し、2 回目で各 Mod の時間を表示します。
/crafting info 起動時間、リスナー、タスク、メモリ、コンテンツ。