-
Notifications
You must be signed in to change notification settings - Fork 0
Plugin Commands
mak001 edited this page Oct 12, 2015
·
4 revisions
Commands are useful for responding to specific things users want to look up, or use. Commands an be created in several ways. Every way to create a command requires the parent plugin, a command String (or String array), and a CommandAction.
//The simplest way to create a command with only one trigger
Command(Plugin plugin, String command, CommandAction commandAction);
//the simplest way to create a command with multiple triggers
Command(Plugin plugin, String[] command, CommandAction commandAction);
Using a permission String can limit which users can use a specific command.
//creates a plugin with a permission users have to pass before it will trigger
Command(Plugin plugin, String command, String permission, CommandAction commandAction);
//creates a plugin with multiple triggers and a permission users have to pass before it will trigger
Command(Plugin plugin, String[] command, String permission, CommandAction commandAction);
###CommandAction
The CommandAction is an interface with two methods. They are onCommand()
and onHelp()
.
####onCommand()
onCommand()
activates when a command is sent that matches one of the Command's trigger Strings.
####onHelp()
onHelp()
activates when a user sends the help command to view the help of the command.
###Example An example command.
//The simplest way to create a command with only one trigger
Command example = new Command(this, "example", new CommandAction() {
@Override
public void onCommand(Server server, String channel, String sender, String login, String hostname, String additional) {
log("Command was issued.");
}
@Override
public void onHelp(Server server, String channel, String sender, String login, String hostname, String additional) {
log("Command help was issued.");
}
});