API

Commands and permissions

Commands with typed arguments, subcommands, aliases, suggestions and permissions. When someone uses one wrong, they see the correct usage without you having to write that message.

In CraftScript

One file per command, in commands/, with the same name as the command:

commands/pay.craftCraftScript
command pay(to: player, amount: int) requires "eco.pay" alias "send" describe "Send coins" {
    if player == null { return "Players only" }
    if amount <= 0 { return "&cThe amount must be positive" }
    return "Sent {amount} coins to {to.name}"
}
commands/announce.craftCraftScript
command announce(message: text) requires "eco.admin" describe "Announce to everyone" {
    broadcast("&6[Notice] {message}")
}

If an argument is missing or isn't the expected type, the player sees, for example, Missing <amount>. Usage: /pay <to> <amount> or 'abc' is not a whole number.

Type Accepts
player An online player, with suggestions
int, number Integer, number
bool true/false, yes/no, on/off
string One word, or several in quotes
text The rest of the line
id A game id (minecraft:stone)

Add ? to make an argument optional (target: player?).

In Kotlin

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

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

    fun register() {
        Crafting.commands.command("home") {
            description = "Teleport home"
            alias("h")
            executes { c -> c.player.teleport(homes[c.player.uuid] ?: c.fail("&cNo home set")) }
            sub("set") {
                executes { c -> homes[c.player.uuid] = c.player.location; c.reply("&aHome set") }
            }
            sub("of") {
                permission = "homes.others"
                player("target")
                executes { c -> c.player.teleport(homes[c.player("target").uuid] ?: c.fail("&cNo home")) }
            }
        }
    }
}

Arguments: string, greedy, int, double, bool, player, identifier, each with optional. Inside executes: c.player (who runs it), c.player("target"), c.int("n"), c.getOrNull<Int>("n"), c.reply(…) and c.fail(…), which stops with an error message.

Permissions

Crafting comes with group-based permissions, in config/crafting/permissions.json. Server operators have all of them.

config/crafting/permissions.jsonJSON
{
  "groups": {
    "default": ["homes.use", "eco.pay"],
    "mod": ["homes.*", "chatguard.*", "-homes.others"],
    "admin": ["*"]
  },
  "players": {
    "Steve": { "groups": ["mod"], "permissions": ["homes.others"] }
  }
}
  • * grants everything; homes.*, everything that starts with homes..
  • -permission denies it. The most specific rule wins; on a tie, the denial wins.
  • All players are in the default group.
  • Prefix your permissions with your mod's id (rubies.give) so they don't clash with other mods'.

Crafting commands

They work from the game and from the server console.

Command What it does
/crafting (or /cf) Version and help.
/crafting mods Loaded mods and their status.
/crafting reload <id> Reloads a script or a plugin. Requires crafting.admin.
/crafting profile The first time it starts measuring; the second time, it shows each mod's time.
/crafting info Startup time, listeners, tasks, memory and content.