2020-07-13 21:27:59 +02:00
|
|
|
package me.clip.placeholderapi.commands;
|
|
|
|
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public abstract class Command {
|
2020-07-16 09:32:22 -07:00
|
|
|
private static final Options EMPTY_OPTIONS = new Options(null, 0);
|
2020-07-13 21:27:59 +02:00
|
|
|
|
|
|
|
private final String match;
|
|
|
|
private final String usage;
|
|
|
|
private final int minimumArguments;
|
2020-07-16 09:32:22 -07:00
|
|
|
/**
|
|
|
|
* Commands should not have multiple permissions. This can lead to a lot of confusions.
|
|
|
|
* This is also a lot more appropriate for maintainability, I saw a lot of commands regitered with wrong permissions.
|
|
|
|
* We will use the main command name to parse our permission.
|
|
|
|
*/
|
|
|
|
private final String permission;
|
|
|
|
|
|
|
|
protected Command(String match) {
|
2020-07-13 21:27:59 +02:00
|
|
|
this(match, EMPTY_OPTIONS);
|
|
|
|
}
|
|
|
|
|
2020-07-16 09:32:22 -07:00
|
|
|
protected Command(String match, Options options) {
|
2020-07-13 21:27:59 +02:00
|
|
|
this.match = match;
|
|
|
|
this.usage = options.usage == null ? "/papi " + match + " <required args> [optional args]" : options.usage;
|
2020-07-16 09:32:22 -07:00
|
|
|
this.permission = "placeholderapi." + match.replace(' ', '.');
|
2020-07-13 21:27:59 +02:00
|
|
|
this.minimumArguments = options.minimumArguments;
|
|
|
|
}
|
|
|
|
|
2020-07-16 09:32:22 -07:00
|
|
|
protected static Options options(String usage, int minimumArguments) {
|
|
|
|
return new Options(usage, minimumArguments);
|
2020-07-13 21:27:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getMatch() {
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUsage() {
|
|
|
|
return usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getMinimumArguments() {
|
|
|
|
return minimumArguments;
|
|
|
|
}
|
|
|
|
|
2020-07-16 09:32:22 -07:00
|
|
|
public String getPermission() {
|
|
|
|
return permission;
|
2020-07-13 21:27:59 +02:00
|
|
|
}
|
|
|
|
|
2020-07-16 09:32:22 -07:00
|
|
|
public abstract void execute(CommandSender sender, String[] args);
|
2020-07-13 21:27:59 +02:00
|
|
|
|
2020-07-16 09:32:22 -07:00
|
|
|
public List<String> handleCompletion(CommandSender sender, String[] args) {
|
2020-07-13 21:27:59 +02:00
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class Options {
|
|
|
|
private final String usage;
|
|
|
|
private final int minimumArguments;
|
|
|
|
|
2020-07-16 09:32:22 -07:00
|
|
|
private Options(String usage, int minimumArguments) {
|
2020-07-13 21:27:59 +02:00
|
|
|
this.usage = usage;
|
|
|
|
this.minimumArguments = minimumArguments;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|