通过 JSONAPI-Commands,你可以轻松注册 真正的 游戏内命令,例如 /spawn 或 /tp silvinci Notch。
就是这样。没有缺点,也没有奇怪的 hack。它就能正常工作。你甚至不会收到那些烦人的 Unknown command 消息。
安装方法
下载 最新版本 的 JSONAPI-Commands,并将其放入服务器的 plugins 目录中。如果你还没有安装,请获取 最新版本 的 JSONAPI,并放在同一个目录中。
工作原理
JSONAPI-Commands 监听 PlayerCommandPreprocessEvent,每当玩家(必须是玩家,控制台不算)输入命令时就会触发该事件。顾名思义,它在任何其他插件或 Bukkit 本身能够介入之前被调用。通过这种方式,我们可以取消整个命令,而不会有人察觉到,实际上发出的命令从未被正式注册。
配置
JSONAPI-Commands 会在 JSONAPI 文件夹中生成一个 commands.yml 文件。该文件的用途一目了然,其中包含了所有已注册的命令,并且可以手动编辑。此文件在服务器重载和重启后仍然保留。这样,你的程序就不需要反复重新注册命令(请参阅“方法”部分)。
尽管如此,我仍建议您在自己的软件中实现相关检查。你永远不知道可能会发生什么。
使用方法
JSONAPI-Commands 为 @alecgorge 的 优秀 JSONAPI 引入了新的方法和一个流式接口。
方法
addListener(String command) 注册给定的命令
addListeners(String[] command) 注册给定的多个命令
removeListener(String command) 移除给定的命令
removeListeners(String[] command) 移除给定的多个命令
removeAllListeners() 移除所有监听器 (请谨慎使用!)
allListeners() 返回所有已注册命令的数组
Stream(流)
新的数据流名为 commands。这意味着你可以通过以下 URL 订阅它:
/api/2/subscribe?json={"name":"commands","username":"yourName","key":sha256("yourName"+"commands"+"yourPassword"+"yourSalt")}
由玩家 alecgorge 执行 /tp silvinci Notch 的一个示例(美化后)响应可能如下所示:
{
"result": "success",
"source": "commands",
"success": {
"time": 1353715957,
"command": "tp",
"args": ["silvinci", "Notch"],
"player": "alecgorge"
}
}
time 是发出命令的确切时间戳
command 是发出的命令
args 是与命令拼接的参数数组 (无参数 = 空数组)
player 是发出命令的玩家 (非受影响的玩家)
示例
……稍后将补充。
帮助
- 如果遇到 bug 或有功能建议,请随时 提交 issue。
- 如果无法顺利运行并需要帮助,您可以在 论坛帖子 中发帖询问。
With JSONAPI-Commands you can easily register real ingame commands like /spawn or /tp silvinci Notch.
This is it. No downsides. No quirky hacks. It just works. You don't even get these pesky Unknown command messages.
Installation
Download the latest version of JSONAPI-Commands and put it in your server's plugins directory. If you haven't already grab the latest version of JSONAPI and put in the very same directory.
How it works
JSONAPI-Commands listens on the PlayerCommandPreprocessEvent, that is fired whenever a player (it has to be a player, console doesn't count) enters a command. As the name suggests it is called before any other plugin or Bukkit itself can interfere. This way we can cancel the whole command and noone will ever notice, that in reality the issued command never was officially registered.
Configuration
JSONAPI-Commands creates a commands.yml in the JSONAPI folder. This file is pretty self-explanatory.
It contains all registered commands and may be edited by hand. This file survives server reloads and restarts.
This way you're programs don't have to re-register (refer to 'Methods') their commands all the time,
nevertheless I do encourage you to implement checks into your software. You'll never now what can possibly happen.
How to use it
JSONAPI-Commands introduces new methods and a stream to @alecgorge's great JSONAPI.
Methods
addListener(String command) registers the given command
addListeners(String[] command) registers the given commands
removeListener(String command) removes the given command
removeListeners(String[] command) removes the given commands
removeAllListeners() removes all listeners (use with caution!)
allListeners() returns an array of all registered commands
Stream
The new stream is named commands. This means you can subscribe to it with this URL:
/api/2/subscribe?json={"name":"commands","username":"yourName","key":sha256("yourName"+"commands"+"yourPassword"+"yourSalt")}
A sample (prettifyed) response for /tp silvinci Notch run by the player alecgorge may look like this:
{
"result": "success",
"source": "commands",
"success": {
"time": 1353715957,
"command": "tp",
"args": ["silvinci", "Notch"],
"player": "alecgorge"
}
}
time is the exact timestamp when the command was issued
command is the command issued
args is an array of the arguments concatenated to the command (no args = empty array)
player is the player who issued the command (not the affected player)
Examples
... will follow shortly.
Help
评论 0
登录后参与评分
还没有评论,来抢沙发吧