mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2026-06-05 00:58:17 +08:00
feat(command): 为SubCommand支持Alias构造函数
This commit is contained in:
@@ -16,6 +16,7 @@ public abstract class CommandHandler implements TabExecutor, NamedExecutor {
|
||||
|
||||
protected final @NotNull JavaPlugin plugin;
|
||||
protected final @NotNull String cmd;
|
||||
protected final @NotNull List<String> aliases;
|
||||
|
||||
protected final @NotNull Map<String, SubCommand> registeredCommands = new HashMap<>();
|
||||
protected final @NotNull Map<String, CommandHandler> registeredHandlers = new HashMap<>();
|
||||
@@ -27,8 +28,13 @@ public abstract class CommandHandler implements TabExecutor, NamedExecutor {
|
||||
}
|
||||
|
||||
public CommandHandler(@NotNull JavaPlugin plugin, @NotNull String cmd) {
|
||||
this(plugin, cmd, new String[0]);
|
||||
}
|
||||
|
||||
public CommandHandler(@NotNull JavaPlugin plugin, @NotNull String cmd, @NotNull String... aliases) {
|
||||
this.plugin = plugin;
|
||||
this.cmd = cmd;
|
||||
this.aliases = Arrays.asList(aliases);
|
||||
}
|
||||
|
||||
public abstract void noArgs(CommandSender sender);
|
||||
@@ -37,6 +43,11 @@ public abstract class CommandHandler implements TabExecutor, NamedExecutor {
|
||||
|
||||
public abstract void noPermission(CommandSender sender);
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.cmd;
|
||||
|
||||
@@ -2,16 +2,13 @@ package cc.carm.lib.easyplugin.command;
|
||||
|
||||
import org.bukkit.permissions.Permissible;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public interface NamedExecutor {
|
||||
|
||||
String getName();
|
||||
|
||||
default List<String> getAliases() {
|
||||
return Collections.singletonList(getName());
|
||||
}
|
||||
List<String> getAliases();
|
||||
|
||||
default boolean hasPermission(Permissible permissible) {
|
||||
return true;
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
public abstract class SubCommand implements NamedExecutor {
|
||||
|
||||
private final String name;
|
||||
private final String[] aliases;
|
||||
private final List<String> aliases;
|
||||
|
||||
public SubCommand(String name) {
|
||||
this(name, new String[0]);
|
||||
@@ -19,7 +19,7 @@ public abstract class SubCommand implements NamedExecutor {
|
||||
|
||||
public SubCommand(String name, String... aliases) {
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
this.aliases = Arrays.asList(aliases);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public abstract class SubCommand implements NamedExecutor {
|
||||
|
||||
@Override
|
||||
public List<String> getAliases() {
|
||||
return Arrays.asList(this.aliases);
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
public abstract Void execute(JavaPlugin plugin, CommandSender sender, String[] args);
|
||||
|
||||
Reference in New Issue
Block a user