diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/HamsterCorePlugin.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/HamsterCorePlugin.java index a5c4ff9..2220bc1 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/HamsterCorePlugin.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/HamsterCorePlugin.java @@ -68,8 +68,8 @@ public class HamsterCorePlugin extends JavaPlugin { logger.info("已注册 CallbackListener."); Bukkit.getPluginManager().registerEvents(DebugListener.INSTANCE, this); logger.info("已注册 DebugListener."); - ParentCoreCommand.INSTANCE.hook(getCommand("HamsterCore")); - ParentLoreCommand.INSTANCE.hook(getCommand("lore")); + ParentCoreCommand.INSTANCE.hook(); + ParentLoreCommand.INSTANCE.hook(); long time = System.currentTimeMillis() - start; logger.info("仓鼠核心启动完成,总计耗时 " + time + " ms."); } diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/ParentCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/ParentCommand.java index 7b207b8..8d6ad02 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/ParentCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/ParentCommand.java @@ -4,7 +4,7 @@ import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.PluginCommand; -import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,27 +12,14 @@ import java.util.*; import java.util.stream.Collectors; @SuppressWarnings("unused") -public class ParentCommand extends ChildCommand { - @NotNull - private final Plugin plugin; +public abstract class ParentCommand extends ChildCommand { @NotNull private final String name; - @Nullable - private final ParentCommand parent; @NotNull private final List childCommands; - public ParentCommand(@NotNull Plugin plugin, @NotNull String name) { - this.plugin = plugin; + public ParentCommand(@NotNull String name) { this.name = name; - parent = null; - childCommands = new ArrayList<>(); - } - - public ParentCommand(@NotNull Plugin plugin, @NotNull String name, @Nullable ParentCommand parent) { - this.plugin = plugin; - this.name = name; - this.parent = parent; childCommands = new ArrayList<>(); } @@ -41,12 +28,25 @@ public class ParentCommand extends ChildCommand { return name; } + @Nullable + public ParentCommand getParent() { + return null; + } + + @NotNull + public abstract JavaPlugin getPlugin(); + + @NotNull + public List getChildCommands() { + return childCommands; + } + @NotNull public String getUsage() { - if (parent == null) { + if (getParent() == null) { return "/" + name; } - return parent.getUsage() + " " + name; + return getParent().getUsage() + " " + name; } @Override @@ -59,11 +59,6 @@ public class ParentCommand extends ChildCommand { return ""; } - @NotNull - public List getChildCommands() { - return childCommands; - } - @NotNull public List getEndChildCommands() { ArrayList list = new ArrayList<>(); @@ -79,7 +74,7 @@ public class ParentCommand extends ChildCommand { public void addChildCommand(@NotNull ChildCommand command) { childCommands.add(command); - plugin.getLogger().info("已为 " + getUsage() + " 添加子命令: " + command.getName() + " ."); + getPlugin().getLogger().info("已为 " + getUsage() + " 添加子命令: " + command.getName() + " ."); } @NotNull @@ -113,9 +108,11 @@ public class ParentCommand extends ChildCommand { } } - public void hook(PluginCommand command) { + public void hook() { + JavaPlugin plugin = getPlugin(); + PluginCommand command = plugin.getCommand(getName()); if (command == null) { - return; + throw new IllegalArgumentException("在插件 " + plugin.getName() + " 中未找到指令 " + getName() + "."); } command.setExecutor(this); command.setTabCompleter(this); diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/ParentCoreCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/ParentCoreCommand.java index dc87e2f..d62e03c 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/ParentCoreCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/ParentCoreCommand.java @@ -2,16 +2,24 @@ package cn.hamster3.mc.plugin.core.bukkit.command.core; import cn.hamster3.mc.plugin.core.bukkit.HamsterCorePlugin; import cn.hamster3.mc.plugin.core.bukkit.command.ParentCommand; +import cn.hamster3.mc.plugin.core.bukkit.command.core.sub.*; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; public class ParentCoreCommand extends ParentCommand { public static final ParentCoreCommand INSTANCE = new ParentCoreCommand(); private ParentCoreCommand() { - super(HamsterCorePlugin.getInstance(), "core"); + super("hamster-core"); addChildCommand(EnvCommand.INSTANCE); addChildCommand(GCCommand.INSTANCE); addChildCommand(YamlCommand.INSTANCE); addChildCommand(InfoModeCommand.INSTANCE); addChildCommand(ReloadCommand.INSTANCE); } + + @Override + public @NotNull JavaPlugin getPlugin() { + return HamsterCorePlugin.getInstance(); + } } diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/EnvCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/EnvCommand.java similarity index 95% rename from hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/EnvCommand.java rename to hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/EnvCommand.java index e163e44..2c1e5aa 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/EnvCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/EnvCommand.java @@ -1,4 +1,4 @@ -package cn.hamster3.mc.plugin.core.bukkit.command.core; +package cn.hamster3.mc.plugin.core.bukkit.command.core.sub; import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand; import org.bukkit.command.Command; diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/GCCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/GCCommand.java similarity index 95% rename from hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/GCCommand.java rename to hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/GCCommand.java index 0122ec1..a6d2835 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/GCCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/GCCommand.java @@ -1,4 +1,4 @@ -package cn.hamster3.mc.plugin.core.bukkit.command.core; +package cn.hamster3.mc.plugin.core.bukkit.command.core.sub; import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand; import org.bukkit.command.Command; diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/InfoModeCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/InfoModeCommand.java similarity index 97% rename from hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/InfoModeCommand.java rename to hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/InfoModeCommand.java index a08eda4..9a07cd4 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/InfoModeCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/InfoModeCommand.java @@ -1,4 +1,4 @@ -package cn.hamster3.mc.plugin.core.bukkit.command.core; +package cn.hamster3.mc.plugin.core.bukkit.command.core.sub; import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/ReloadCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/ReloadCommand.java similarity index 95% rename from hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/ReloadCommand.java rename to hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/ReloadCommand.java index 9d1a602..23b5e1f 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/ReloadCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/ReloadCommand.java @@ -1,4 +1,4 @@ -package cn.hamster3.mc.plugin.core.bukkit.command.core; +package cn.hamster3.mc.plugin.core.bukkit.command.core.sub; import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand; import cn.hamster3.mc.plugin.core.bukkit.page.PageManager; diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/YamlCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/YamlCommand.java similarity index 98% rename from hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/YamlCommand.java rename to hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/YamlCommand.java index eb49091..f61c835 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/YamlCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/core/sub/YamlCommand.java @@ -1,4 +1,4 @@ -package cn.hamster3.mc.plugin.core.bukkit.command.core; +package cn.hamster3.mc.plugin.core.bukkit.command.core.sub; import cn.hamster3.mc.plugin.core.bukkit.HamsterCorePlugin; import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand; diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/ParentLoreCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/ParentLoreCommand.java index 1f36e48..730d4d9 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/ParentLoreCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/ParentLoreCommand.java @@ -2,16 +2,18 @@ package cn.hamster3.mc.plugin.core.bukkit.command.lore; import cn.hamster3.mc.plugin.core.bukkit.HamsterCorePlugin; import cn.hamster3.mc.plugin.core.bukkit.command.ParentCommand; +import cn.hamster3.mc.plugin.core.bukkit.command.lore.sub.*; import cn.hamster3.mc.plugin.core.common.util.CommonUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; public final class ParentLoreCommand extends ParentCommand { public static final ParentLoreCommand INSTANCE = new ParentLoreCommand(); public ParentLoreCommand() { - super(HamsterCorePlugin.getInstance(), "lore"); + super("lore"); addChildCommand(LoreAddCommand.INSTANCE); addChildCommand(LoreRemoveCommand.INSTANCE); addChildCommand(LoreSetCommand.INSTANCE); @@ -21,6 +23,11 @@ public final class ParentLoreCommand extends ParentCommand { addChildCommand(LoreFlagCommand.INSTANCE); } + @Override + public @NotNull JavaPlugin getPlugin() { + return HamsterCorePlugin.getInstance(); + } + @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { CommonUtils.replaceColorCode(args); diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreAddCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreAddCommand.java similarity index 97% rename from hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreAddCommand.java rename to hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreAddCommand.java index 5923d09..437650d 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreAddCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreAddCommand.java @@ -1,4 +1,4 @@ -package cn.hamster3.mc.plugin.core.bukkit.command.lore; +package cn.hamster3.mc.plugin.core.bukkit.command.lore.sub; import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreClearCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreClearCommand.java similarity index 97% rename from hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreClearCommand.java rename to hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreClearCommand.java index cebde01..a7db632 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreClearCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreClearCommand.java @@ -1,4 +1,4 @@ -package cn.hamster3.mc.plugin.core.bukkit.command.lore; +package cn.hamster3.mc.plugin.core.bukkit.command.lore.sub; import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreCustomModelDataCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreCustomModelDataCommand.java similarity index 97% rename from hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreCustomModelDataCommand.java rename to hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreCustomModelDataCommand.java index f5dafc7..6a73898 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreCustomModelDataCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreCustomModelDataCommand.java @@ -1,4 +1,4 @@ -package cn.hamster3.mc.plugin.core.bukkit.command.lore; +package cn.hamster3.mc.plugin.core.bukkit.command.lore.sub; import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreFlagCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreFlagCommand.java similarity index 97% rename from hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreFlagCommand.java rename to hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreFlagCommand.java index 73b195b..c8858e9 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreFlagCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreFlagCommand.java @@ -1,4 +1,4 @@ -package cn.hamster3.mc.plugin.core.bukkit.command.lore; +package cn.hamster3.mc.plugin.core.bukkit.command.lore.sub; import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreNameCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreNameCommand.java similarity index 97% rename from hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreNameCommand.java rename to hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreNameCommand.java index 1fdc216..51079ef 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreNameCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreNameCommand.java @@ -1,4 +1,4 @@ -package cn.hamster3.mc.plugin.core.bukkit.command.lore; +package cn.hamster3.mc.plugin.core.bukkit.command.lore.sub; import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreRemoveCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreRemoveCommand.java similarity index 97% rename from hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreRemoveCommand.java rename to hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreRemoveCommand.java index f7327c0..651f7d2 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreRemoveCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreRemoveCommand.java @@ -1,4 +1,4 @@ -package cn.hamster3.mc.plugin.core.bukkit.command.lore; +package cn.hamster3.mc.plugin.core.bukkit.command.lore.sub; import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreSetCommand.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreSetCommand.java similarity index 97% rename from hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreSetCommand.java rename to hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreSetCommand.java index 17fd03f..8b6ae14 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/LoreSetCommand.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/command/lore/sub/LoreSetCommand.java @@ -1,4 +1,4 @@ -package cn.hamster3.mc.plugin.core.bukkit.command.lore; +package cn.hamster3.mc.plugin.core.bukkit.command.lore.sub; import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; diff --git a/hamster-core-bukkit/src/main/resources/plugin.yml b/hamster-core-bukkit/src/main/resources/plugin.yml index 1b44cf0..7e45e9e 100644 --- a/hamster-core-bukkit/src/main/resources/plugin.yml +++ b/hamster-core-bukkit/src/main/resources/plugin.yml @@ -23,8 +23,8 @@ libraries: - 'com.zaxxer:HikariCP:5.0.1' commands: - HamsterCore: - aliases: [ hcore, hc ] + hamster-core: + aliases: [ hcore, hc, core ] description: 仓鼠核心调试指令 permission: hamster.core.admin permission-message: §c你没有这个权限!