翻译草稿

· · 个人记录

The command file is a custom format parsed by CommandParser. The idea behind this is that much of what you end up writing code for to make your commands work is extremely repetitive and serves little purpose. So instead of having you write code to specify the behavior of the command, almost all of this is removed from your code and put into the command file as metadata.

命令文件的格式很简单:它看起来像一个代码块,但是其内容是元数据,而不是代码。

commandname {
    //这里填写命令信息
}

这是它的基本结构。如果你想创建子命令,你可以这样做:

basecommand {
    //这里填写主命令信息
    childcommand {
        //这里填写子命令信息
    }
}

The resulting commands created from this structure would be /basecommand and /basecommand childcommand.

If you have a command which has many children and you don't want them all to be shown in the help menu, you can add the hidesub tag to a parent command.

你也可以通过使用逗号隔开的方式来添加命令的别名,就像这样:

name1,name2 {
    //This command can be run with either /name1 or /name2
}

Inside the command body, you put command tags. Tags specify information about the command, and it's the stuff you'd expect: Help messages, permissions, and who can use it (console/player).

commandname {
    permission command.permission.name
    help This is a help message
    user player
}

This command will now only be runnable by players who have the permission command.permission.name. Its help message is This is a help message, and it can only be used by players.

But this command doesn't actually do anything yet. Command Manager works by hooking into annotated methods in your code. You'll read more about that in the wiki page for Command Hooks, but for now, just know that in order for your command to execute any code, it needs the hook tag to be specified.

commandname {
    permission command.permission.name
    help This is a help message
    user player
    hook hookname
}

Now this command will hook into an annotated method with the hook hookname.

Every command created in the command file automatically has an implicit subcommand called help, for showing the help message of its parent. To disable this, you can use the nohelp flag, which may be helpful for commands which send messages:

reply string...:message {
    nohelp
    hook reply
    user player
}

That's all for the extremely basic functionality of command manager. Continue reading about Command Hooks from here.