Example
The following is an example of a ShortCommand:
package com.shortcircuit.test; import org.bukkit.ChatColor; import com.shortcircuit.shortcommands.ShortCommands; import com.shortcircuit.shortcommands.command.CommandType; import com.shortcircuit.shortcommands.command.CommandWrapper; import com.shortcircuit.shortcommands.command.ShortCommand; import com.shortcircuit.shortcommands.command.ShortCommandHandler; import com.shortcircuit.shortcommands.exceptions.BlockOnlyException; import com.shortcircuit.shortcommands.exceptions.ConsoleOnlyException; import com.shortcircuit.shortcommands.exceptions.InvalidArgumentException; import com.shortcircuit.shortcommands.exceptions.NoPermissionException; import com.shortcircuit.shortcommands.exceptions.PersistentCommandException; import com.shortcircuit.shortcommands.exceptions.PlayerOnlyException; import com.shortcircuit.shortcommands.exceptions.TooFewArgumentsException; import com.shortcircuit.shortcommands.exceptions.TooManyArgumentsException; /** * @author ShortCircuit908 * */ public class TestCommand extends ShortCommand{ public TestCommand(Plugin owning_plugin) { super(owning_plugin); } @Override public CommandType getCommandType() { return CommandType.CONSOLE; } @Override public String[] getCommandNames() { return new String[] {"test", "test-alias"}; } @Override public String getPermissions() { return "test.*"; } @Override public String[] getHelp() { return new String[] { ChatColor.GOLD + "This is the first line of help", ChatColor.GOLD + "This is the second line of help", ChatColor.GOLD + "Usage: /${command}"}; } @Override public boolean canBeDisabled() { return true; } @Override public String[] exec(CommandWrapper command) throws TooFewArgumentsException, TooManyArgumentsException, InvalidArgumentException, NoPermissionException, PlayerOnlyException, ConsoleOnlyException, BlockOnlyException { return new String[]{ ChatColor.AQUA + "I think this plugin is pretty neat.", ChatColor.AQUA + "Don't you?"} } }
To register this command, simply add this in your plugin's onEnable() method:
ShortCommands short_commands = ShortCommands.getInstance(); try{ short_commands.getCommandHandler().registerCommand(new TestCommand(this)); } catch(CommandExistsException e){ getLogger().warn("This command conflicts with another ShortCommand"); }
Comments