feat: 兼容1.0.0

This commit is contained in:
2023-10-25 21:08:12 +08:00
parent 13b0e32d5a
commit 6079f4d930
4 changed files with 35 additions and 15 deletions

View File

@@ -59,8 +59,8 @@ public class HamsterCorePlugin extends JavaPlugin {
logger.info("已注册 CallbackListener.");
Bukkit.getPluginManager().registerEvents(DebugListener.INSTANCE, this);
logger.info("已注册 DebugListener.");
ParentCoreCommand.INSTANCE.hook();
ParentLoreCommand.INSTANCE.hook();
ParentCoreCommand.INSTANCE.register();
ParentLoreCommand.INSTANCE.register();
long time = System.currentTimeMillis() - start;
Bukkit.getScheduler().runTaskLater(this, () -> {
PointAPI.reloadPlayerPointAPIHook();

View File

@@ -11,9 +11,8 @@ public abstract class ChildCommand implements TabExecutor {
@NotNull
public abstract String getUsage();
public abstract boolean hasPermission(@NotNull CommandSender sender);
@NotNull
public abstract String getDescription();
public abstract boolean hasPermission(@NotNull CommandSender sender);
}

View File

@@ -53,6 +53,25 @@ public abstract class ParentCommand extends ChildCommand {
return "";
}
public void register() {
JavaPlugin plugin = getPlugin();
PluginCommand command = plugin.getCommand(getName());
if (command == null) {
throw new IllegalArgumentException("在插件 " + plugin.getName() + " 中未找到指令 " + getName() + ".");
}
command.setExecutor(this);
command.setTabCompleter(this);
plugin.getLogger().info("已注册指令 " + getUsage() + ".");
}
/**
* 建议使用 {@link #register()}
*/
@Deprecated
public void hook() {
register();
}
/**
* 获取所有子命令
* <p>
@@ -108,17 +127,6 @@ public abstract class ParentCommand extends ChildCommand {
}
}
public void hook() {
JavaPlugin plugin = getPlugin();
PluginCommand command = plugin.getCommand(getName());
if (command == null) {
throw new IllegalArgumentException("在插件 " + plugin.getName() + " 中未找到指令 " + getName() + ".");
}
command.setExecutor(this);
command.setTabCompleter(this);
plugin.getLogger().info("已注册指令 " + getUsage() + ".");
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (!hasPermission(sender)) {