Creating a basic command and registering it
-
Creating a basic command:
Create a class with some name and extend it with ACFCommand
Code (Java):public class HelloCommand extends ACFCommand {
Code (Java):
Code (Text):public HelloCommand(YourMain main) {
super(main, "hello");
setDescription("A hello command!");
setUsage("hello");
setAliases(Arrays.asList("hi", "hilol"));
}
Code (Java):
Code (Java):public class HelloCommand extends ACFCommand {
public HelloCommand(YourMain main) {
super(main, "hello");
setDescription("A hello command!");
setUsage("hello");
setAliases(Arrays.asList("hi", "hilol"));
}
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
sender.sendMessage("Hello, world!");
return true;
}
}
There are various of methods, non-deprecated register methods require the plugin to be hooked (if your plugin is not hooked see this page on how to hook it).
Here's how to:
1st you should get the ACFCommandHandler class by doing this line into your code where you register commands:
Code (Java):ACFCommandHandler handler = IvanACF.getRegisterHandler();
Code (Java):handler.registerCommand(new HelloCommand());
If you have various of commands and you want cleaner register, you could do this:
Code (Java):ACFCommandHandler handler = IvanACF.getRegisterHandler();
ArrayList<ACFCommand> commands = new ArrayList<>();
commands.add(new HelloCommand());
commands.add(new InfoCommand());
handler.registerCommands(commands);
Be aware that handler.registerCommands require the plugin to be hooked.
And that's it. You can use your commands the same way as you registered them into your plugin.yml. Be aware that if you want "yourpluginname:yourcommand" to work you plugin should be hooked.
Here's a pic on 1.13:
- Loading...
- Loading...
XenCarta PRO
© Jason Axelrod from 8WAYRUN.COM