Skip to content

Creating a Command

Francisco Solis edited this page Jul 20, 2021 · 1 revision

Commands? Lots of them!

Almost all plugins has commands, maybe we should add them 😆. To Create a command just extend a class to xyz.theprogramsrc.supercoreapi.spigot.commands.SpigotCommand or xyz.theprogramsrc.supercoreapi.bungee.commands.BungeeCommand, then override the methods getCommand, onPlayerExecute(Player|ProxiedPlayer, String[]) and onConsoleExecute(SpigotConsole|BungeeConsole, String[]). The method getCommand is the one that contains the command, you may also override getAliases to add aliases.

The onPlayerExecute and onConsoleExecute method needs to return xyz.theprogramsrc.supercoreapi.spigot.commands.CommandResult or xyz.theprogramsrc.supercoreapi.bungee.commands.CommandResult depending if you're using a SpigotCommand or BungeeCommand respectively.

Example of SpigotCommand:

packagexyz.theprogramsrc.myplugin.commands.MyCommand;
importorg.bukkit.entity.Player;
importxyz.theprogramsrc.supercoreapi.spigot.commands.CommandResult;
importxyz.theprogramsrc.supercoreapi.spigot.commands.SpigotCommand;
importxyz.theprogramsrc.supercoreapi.spigot.utils.SpigotConsole;
publicclassMyCommandextendsSpigotCommand {
@OverridepublicStringgetCommand(){
return"my-command";
}
@OverridepublicCommandResultonPlayerExecute(Playerplayer, String[] args){
// Add some stuffif(!player.isOp()) returnCommandResult.NO_PERMISSION; // No permission pmessageif(args.length == 0) returnCommandResult.INVALID_ARGS; // Invalid Arguments Messageif(args[0].equalsIgnoreCase("no-access")) returnCommandResult.NO_ACCESS; // No access messageif(args[0].equalsIgnoreCase("not-supported")) returnCommandResult.NOT_SUPPORTED; // Command only for console messagereturnCommandResult.COMPLETED; // Nothing to say 
}
@OverridepublicCommandResultonConsoleExecute(SpigotConsoleconsole, String[] args){
// Add some stuffif(args.length == 0) returnCommandResult.INVALID_ARGS; // Invalid Arguments Messageif(args[0].equalsIgnoreCase("not-supported")) returnCommandResult.NOT_SUPPORTED; // Command only for players messagereturnCommandResult.COMPLETED; // Nothing to say 
}
}

Command Results

  • COMPLETED: No message, just a normal response.
  • NOT_SUPPORTED: Output a message that the command is only for players or console if is being executed by a console or player respectively.
  • NO_PERMISSION: Output a message that the command sender doesn't have permissions.
  • NO_ACCESS: Output a message that the sender has no access.
  • INVALID_ARGS: Output a message that the arguments are invalid.

> Current Version

> Donate
PayPal
Patreon

Clone this wiki locally