一个用于使用 Minecraft 1.13 引入的命令 UI 的 Bukkit/Spigot API
所有你所需的信息都能在 GitHub 页面上找到
CommandAPI 是什么?
CommandAPI 全面支持在 Minecraft 1.13 更新中实现的新的命令 UI。
想保持最新?我们有一个 Discord 服务器!
功能简要概览
- 更好的命令 - 防止玩家运行无效命令,让开发者更轻松
- 更好的参数 - 自动参数解析与内置验证
- 支持代理命令发送者 - 使用
/execute as ... run 命令以其他实体的身份运行你的命令
- 支持 /execute 命令 - 让你的命令能够被内置的
/execute 命令执行
- 支持 Minecraft 的函数 - 允许你的命令从 Minecraft 的函数和标签中执行
- 无需 plugin.yml 注册 - 命令不再需要在
plugin.yml 文件中注册
- 无其他依赖 - 你不需要在项目中导入 Brigadier 即可使用 CommandAPI
- 无追踪 - CommandAPI 不收集关于其插件的任何统计信息;所见即所得!
参数类型转换
与其在玩家运行命令后检查参数是否为整数,像这样:
onCommand(CommandSender sender, Command command, String label, String[] args) {
try {
int i = Integer.parseInt(args[0]);
// 对这个数字做点什么
catch (NumberFormatException e) {
// 对这不是数字的事实做点什么...
}
}
你可以放心,CommandAPI 已经推断出你想要的任何类型,并可以直接跳转到这段代码:
new CommandAPICommand("mycommand")
.withArguments(new IntegerArgument("myint"))
.executes((sender, args) -> {
int i = (int) args.get("myint");
// 对这个数字做点什么
})
.register();
CommandAPI 提供超过 40 种不同的参数以满足你的需求!自动转换为附魔、实体类型、位置、物品堆、药水效果以及更多!
命令发送者类型检查
再也不用检查你的发送者是否是玩家了!CommandAPI 为各种命令发送者提供自动命令发送者检查:
new CommandAPICommand("mycommand")
.withArguments(arguments)
.executesPlayer((player, args) -> {
player.sendMessage("Hi " + player.getDisplayName());
})
.register();
文档
最新文档可以在 这里 找到。相信我,你以前从未见过这么好的文档。
内置插件转换器
对你的插件命令无法与 /execute 命令一起使用且不知道如何编写代码而感到沮丧吗?CommandAPI 可以帮你解决!通过其内置的插件命令转换系统,你可以使任何插件命令兼容 Minecraft 的 /execute 命令和数据包!
仍然不确定?
以下是它还能做的其他事情:
- 自动解析带范围的整数(强制你的命令只接受范围内的值)
- 处理整数和浮点数位置,以及使用
~ 符号的相对位置
- 解析原始 JSON 并直接转换为
BaseComponent[]
- 解析在线玩家,并根据谁在线提供建议
- 创建自定义参数,将字符串解析为自定义定义的对象
- 将权限应用于特定参数——你需要权限才能看到建议的参数以及运行它
- 使未使用 CommandAPI 编写的其他插件兼容
/execute 命令
- 处理命令的结果和成功情况,就像你可以使用命令方块一样
- 根据用户已经在命令提示符中输入的内容设置上下文感知的建议
还需要我说什么吗?
A Bukkit/Spigot API to use the command UI introduced in Minecraft 1.13
Everything you'll ever need can be found on the GitHub page
What is the CommandAPI?
The CommandAPI provides full support for the new command UI which was implemented in Minecraft's 1.13 update.
Wanna stay up to date? We've got a Discord server!
Brief overview of features
- Better commands - Prevent players from running invalid commands, making it easier for developers
- Better arguments - Automatic argument parsing with built-in validation
- Support for proxied command senders - Run your command as other entities using /execute as ... run command
- Support for the /execute command - Let your command to be executed by the built in /execute command
- Support for Minecraft's functions - Allow your command to be executed from Minecraft's functions and tags
- No plugin.yml registration - Commands don't need to be registered in the plugin.yml file anymore
- No other dependencies - You don't need to import Brigadier in your projects to use the CommandAPI
- No tracking - The CommandAPI doesn't collect any stats about its plugin; what you see is what you get!
Argument type casting
Instead of checking if an argument is an integer after they run the command like this:
onCommand(CommandSender sender, Command command, String label, String[] args) {
try {
int i = Integer.parseInt(args[0]);
// Do something with this number
catch (NumberFormatException e) {
// Do something with the fact this isn't a number...
}
}
You can rest assured that the CommandAPI has inferred whatever type you want and can jump straight to this:
new CommandAPICommand("mycommand")
.withArguments(new IntegerArgument("myint"))
.executes((sender, args) -> {
int i = (int) args.get("myint");
// Do something with this number
})
.register();
The CommandAPI offers over 40 different arguments to tailor to your needs! Automatic casting to Enchantments, EntityTypes, Locations, ItemStacks, PotionEffects and many more!
CommandSender type checks
Never again will you have to check if your sender is a player! The CommandAPI provides automatic command sender checks for all sorts of command senders:
new CommandAPICommand("mycommand")
.withArguments(arguments)
.executesPlayer((player, args) -> {
player.sendMessage("Hi " + player.getDisplayName());
})
.register();
Documentation
The latest documentation can be found here. Trust me, you've never, ever seen documentation this good before.
Built-in plugin converter
Bummed that your plugin's commands can't be used with the /execute command and don't know how to write code? The CommandAPI has you covered! With its built-in plugin command conversion system, you can make any plugin command compatible with Minecraft's /execute command and datapacks!
Still not convinced?
Here's what else it can do:
- Parse integers with ranges automatically (force your command to only accept values within a range)
- Handle integer and floating point locations, as well as relative locations using the ~ symbol
- Parse raw JSON and convert it straight into a BaseComponent[]
- Parse online players, with suggestions based on who's online
- Create custom arguments that parse Strings into custom defined objects
- Apply permissions to specific arguments - you need permissions to even see the suggested arguments as well as run it
- Make other plugins that weren't written with the CommandAPI compatible with the /execute command
- Handle results and successes of commands just like you can with command blocks
- Set context-aware suggestions based on what the user has already entered into their command prompt
Need I say more?
评论 0
登录后参与评分
还没有评论,来抢沙发吧