-
-
Notifications
You must be signed in to change notification settings - Fork 340
Closed
Description
It would be nice to have a simple abstract implementation of CommandCallable (like SimpleDispatcher implementation for Dispatcher).
The abstract class provides the basic functionality that is sufficient in many cases. The only method it should not implement is the call method. A command class extending the abstract class would look like this:
public class SendCommand extends AbstractCommand {
public SendCommand() {
super(
"simplemail.write", // permission
"Send a mail", // description
Texts.of("Send a server mail to a player."), // help
"<player> <msg>"); // usage
}
@Override
public boolean call(CommandSource source, String arguments, List<String> parents) throws CommandException {
// Command stuff...
return true;
}
}This is the proposed abstract command class:
public abstract class AbstractCommand implements CommandCallable {
private final String permission;
private final String shortDescription;
private final Text help;
private final String usage;
public AbstractCommand(String permission, String shortDescription, Text help, String usage) {
this.permission = permission;
this.shortDescription = shortDescription;
this.help = help;
this.usage = usage;
}
@Override
public boolean testPermission(CommandSource source) {
return source.hasPermission(this.permission);
}
@Override
public String getShortDescription(CommandSource source) {
return this.shortDescription;
}
@Override
public Text getHelp(CommandSource source) {
return this.help;
}
@Override
public String getUsage(CommandSource source) {
return this.usage;
}
@Override
public List<String> getSuggestions(CommandSource source, String arguments) throws CommandException {
return Collections.emptyList();
}
}Reactions are currently unavailable