-
Notifications
You must be signed in to change notification settings - Fork 0
Using the CommandAPI
CommandAPI is an API for processing user commands in Minecraft.
Advantages over the Bukkit Framework API
- Full asynchrony (when using the API implementation in the form of AncapPlugin)
- More complete implementation of features from Minecraft Command API (for example, features such as chat previews and color hints)
- Rich toolkit for creating highly loaded command handlers
- Ability to process commands in a declarative style
How the processing of commands with Bukkit looks like...
@Override
public boolean onCommand(CommandSender sender, Command command, String alias, String[] arguments) {
if (arguments.length == 0) {
sender.sendMessage(LAPI.localized(AncapPlugin.MESSAGE_DOMAIN+"enter-language", sender.getName()));
return true;
}
if (arguments[0].equals("set")) {
if (arguments.length < 2) {
Event event = new NotEnoughArgsEvent(sender, 1);
Bukkit.getPluginManager().callEvent(event);
}
Event event = new LanguageChangeEvent(sender, arguments[1]);
Bukkit.getPluginManager().callEvent(event);
}
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] arguments) {
if (arguments.length == 0) {
return List.of("set");
}
if (arguments[0].equals("set")) {
return List.of(
"ru",
"en",
"uk"
);
}
return Collections.emptyList();
}And how would it be written with CommandAPI from AncapFramework...
public LanguageChangeInput() {
super(new Delegate(
new Raw(new Advice(new LAPIMessage(Artifex.class, "command.language.enter-language"))),
new SubCommand(
new StringDelegatePattern("set"),
new Arguments(
new Accept(new Argument("language", new Self())),
dispatch -> {
LAPI.setupLanguage(dispatch.source().sender().getName(), Language.of(dispatch.arguments().get("language", String.class)));
new Communicator(dispatch.source().sender()).send(new LAPIMessage(Artifex.class, "command.language.setup"));
}
)
)
));
}Commands are registered via AncapPluginAPI via the this.registerExecutor(String CommandName, CommandOperator operator) method the AncapPlugin heir.
All commands must be written in ancapplugin.yml:
commands:
list:
- language
aliases:
language:
- lang(aliases do not have to be prescribed)
AncapPlugin creates a new thread to process each new command.
You can easily create long-term queries to a remote database and are not afraid that everything will hang. This is implemented by processing player packets, packets are also processed asynchronously.
Also, all objects passed by the implementation can be safely moved between threads. They are all thread-safe.
Due to the features of Bukkit, in addition to ancapplugin.yml, commands must also be registered in plugin.yml, otherwise it will be impossible to complete the command.
-
Создание плагина
- Создание main-класса
- Настройка ancapplugin.yml
- Использование AncapPluginAPI
- Использование LanguageAPI
- Использование CommunicatorAPI
- Использование ConfigurationAPI
- Использование CommandAPI
- Использование DatabaseAPI
- Использование EventAPI
- Использование MaterialAPI
- Использование WorldIteratorAPI
- Использование BukkitUtil
- Использование ResourceAPI
-
- Creating main class
- Setting up the ancapplugin.yml
- Using the AncapPluginAPI
- Using the LanguageAPI
- Using the CommunicatorAPI
- Using the ConfigurationAPI
- Using the CommandAPI
- Using the DatabaseAPI
- Using the EventAPI
- Using the MaterialAPI
- Using the WorldIteratorAPI
- Using the BukkitUtil
- Using the ResouceAPI