-
-
Notifications
You must be signed in to change notification settings - Fork 6
Creating a Command
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
orxyz.theprogramsrc.supercoreapi.bungee.commands.CommandResult
depending if you're using a SpigotCommand or BungeeCommand respectively.
Example of SpigotCommand:
package xyz.theprogramsrc.myplugin.commands.MyCommand;
import org.bukkit.entity.Player;
import xyz.theprogramsrc.supercoreapi.spigot.commands.CommandResult;
import xyz.theprogramsrc.supercoreapi.spigot.commands.SpigotCommand;
import xyz.theprogramsrc.supercoreapi.spigot.utils.SpigotConsole;
public class MyCommand extends SpigotCommand {
@Override
public String getCommand(){
return "my-command";
}
@Override
public CommandResult onPlayerExecute(Player player, String[] args){
// Add some stuff
if(!player.isOp()) return CommandResult.NO_PERMISSION; // No permission pmessage
if(args.length == 0) return CommandResult.INVALID_ARGS; // Invalid Arguments Message
if(args[0].equalsIgnoreCase("no-access")) return CommandResult.NO_ACCESS; // No access message
if(args[0].equalsIgnoreCase("not-supported")) return CommandResult.NOT_SUPPORTED; // Command only for console message
return CommandResult.COMPLETED; // Nothing to say
}
@Override
public CommandResult onConsoleExecute(SpigotConsole console, String[] args){
// Add some stuff
if(args.length == 0) return CommandResult.INVALID_ARGS; // Invalid Arguments Message
if(args[0].equalsIgnoreCase("not-supported")) return CommandResult.NOT_SUPPORTED; // Command only for players message
return CommandResult.COMPLETED; // Nothing to say
}
}
-
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.