refactor(bukkit): 重构部分代码
This commit is contained in:
@@ -68,8 +68,8 @@ public class HamsterCorePlugin extends JavaPlugin {
|
|||||||
logger.info("已注册 CallbackListener.");
|
logger.info("已注册 CallbackListener.");
|
||||||
Bukkit.getPluginManager().registerEvents(DebugListener.INSTANCE, this);
|
Bukkit.getPluginManager().registerEvents(DebugListener.INSTANCE, this);
|
||||||
logger.info("已注册 DebugListener.");
|
logger.info("已注册 DebugListener.");
|
||||||
ParentCoreCommand.INSTANCE.hook(getCommand("HamsterCore"));
|
ParentCoreCommand.INSTANCE.hook();
|
||||||
ParentLoreCommand.INSTANCE.hook(getCommand("lore"));
|
ParentLoreCommand.INSTANCE.hook();
|
||||||
long time = System.currentTimeMillis() - start;
|
long time = System.currentTimeMillis() - start;
|
||||||
logger.info("仓鼠核心启动完成,总计耗时 " + time + " ms.");
|
logger.info("仓鼠核心启动完成,总计耗时 " + time + " ms.");
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@ import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.PluginCommand;
|
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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -12,27 +12,14 @@ import java.util.*;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class ParentCommand extends ChildCommand {
|
public abstract class ParentCommand extends ChildCommand {
|
||||||
@NotNull
|
|
||||||
private final Plugin plugin;
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String name;
|
private final String name;
|
||||||
@Nullable
|
|
||||||
private final ParentCommand parent;
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final List<ChildCommand> childCommands;
|
private final List<ChildCommand> childCommands;
|
||||||
|
|
||||||
public ParentCommand(@NotNull Plugin plugin, @NotNull String name) {
|
public ParentCommand(@NotNull String name) {
|
||||||
this.plugin = plugin;
|
|
||||||
this.name = 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<>();
|
childCommands = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,12 +28,25 @@ public class ParentCommand extends ChildCommand {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public ParentCommand getParent() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public abstract JavaPlugin getPlugin();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public List<ChildCommand> getChildCommands() {
|
||||||
|
return childCommands;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getUsage() {
|
public String getUsage() {
|
||||||
if (parent == null) {
|
if (getParent() == null) {
|
||||||
return "/" + name;
|
return "/" + name;
|
||||||
}
|
}
|
||||||
return parent.getUsage() + " " + name;
|
return getParent().getUsage() + " " + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -59,11 +59,6 @@ public class ParentCommand extends ChildCommand {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public List<ChildCommand> getChildCommands() {
|
|
||||||
return childCommands;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<ChildCommand> getEndChildCommands() {
|
public List<ChildCommand> getEndChildCommands() {
|
||||||
ArrayList<ChildCommand> list = new ArrayList<>();
|
ArrayList<ChildCommand> list = new ArrayList<>();
|
||||||
@@ -79,7 +74,7 @@ public class ParentCommand extends ChildCommand {
|
|||||||
|
|
||||||
public void addChildCommand(@NotNull ChildCommand command) {
|
public void addChildCommand(@NotNull ChildCommand command) {
|
||||||
childCommands.add(command);
|
childCommands.add(command);
|
||||||
plugin.getLogger().info("已为 " + getUsage() + " 添加子命令: " + command.getName() + " .");
|
getPlugin().getLogger().info("已为 " + getUsage() + " 添加子命令: " + command.getName() + " .");
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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) {
|
if (command == null) {
|
||||||
return;
|
throw new IllegalArgumentException("在插件 " + plugin.getName() + " 中未找到指令 " + getName() + ".");
|
||||||
}
|
}
|
||||||
command.setExecutor(this);
|
command.setExecutor(this);
|
||||||
command.setTabCompleter(this);
|
command.setTabCompleter(this);
|
||||||
|
@@ -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.HamsterCorePlugin;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.command.ParentCommand;
|
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 class ParentCoreCommand extends ParentCommand {
|
||||||
public static final ParentCoreCommand INSTANCE = new ParentCoreCommand();
|
public static final ParentCoreCommand INSTANCE = new ParentCoreCommand();
|
||||||
|
|
||||||
private ParentCoreCommand() {
|
private ParentCoreCommand() {
|
||||||
super(HamsterCorePlugin.getInstance(), "core");
|
super("hamster-core");
|
||||||
addChildCommand(EnvCommand.INSTANCE);
|
addChildCommand(EnvCommand.INSTANCE);
|
||||||
addChildCommand(GCCommand.INSTANCE);
|
addChildCommand(GCCommand.INSTANCE);
|
||||||
addChildCommand(YamlCommand.INSTANCE);
|
addChildCommand(YamlCommand.INSTANCE);
|
||||||
addChildCommand(InfoModeCommand.INSTANCE);
|
addChildCommand(InfoModeCommand.INSTANCE);
|
||||||
addChildCommand(ReloadCommand.INSTANCE);
|
addChildCommand(ReloadCommand.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull JavaPlugin getPlugin() {
|
||||||
|
return HamsterCorePlugin.getInstance();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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.command.ChildCommand;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
@@ -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.command.ChildCommand;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
@@ -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.command.ChildCommand;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
@@ -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.command.ChildCommand;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.page.PageManager;
|
import cn.hamster3.mc.plugin.core.bukkit.page.PageManager;
|
@@ -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.HamsterCorePlugin;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
|
import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
|
@@ -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.HamsterCorePlugin;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.command.ParentCommand;
|
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 cn.hamster3.mc.plugin.core.common.util.CommonUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public final class ParentLoreCommand extends ParentCommand {
|
public final class ParentLoreCommand extends ParentCommand {
|
||||||
public static final ParentLoreCommand INSTANCE = new ParentLoreCommand();
|
public static final ParentLoreCommand INSTANCE = new ParentLoreCommand();
|
||||||
|
|
||||||
public ParentLoreCommand() {
|
public ParentLoreCommand() {
|
||||||
super(HamsterCorePlugin.getInstance(), "lore");
|
super("lore");
|
||||||
addChildCommand(LoreAddCommand.INSTANCE);
|
addChildCommand(LoreAddCommand.INSTANCE);
|
||||||
addChildCommand(LoreRemoveCommand.INSTANCE);
|
addChildCommand(LoreRemoveCommand.INSTANCE);
|
||||||
addChildCommand(LoreSetCommand.INSTANCE);
|
addChildCommand(LoreSetCommand.INSTANCE);
|
||||||
@@ -21,6 +23,11 @@ public final class ParentLoreCommand extends ParentCommand {
|
|||||||
addChildCommand(LoreFlagCommand.INSTANCE);
|
addChildCommand(LoreFlagCommand.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull JavaPlugin getPlugin() {
|
||||||
|
return HamsterCorePlugin.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||||
CommonUtils.replaceColorCode(args);
|
CommonUtils.replaceColorCode(args);
|
||||||
|
@@ -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.command.ChildCommand;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
@@ -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.command.ChildCommand;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
@@ -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.command.ChildCommand;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
@@ -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.command.ChildCommand;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
@@ -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.command.ChildCommand;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
@@ -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.command.ChildCommand;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
@@ -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.command.ChildCommand;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
@@ -23,8 +23,8 @@ libraries:
|
|||||||
- 'com.zaxxer:HikariCP:5.0.1'
|
- 'com.zaxxer:HikariCP:5.0.1'
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
HamsterCore:
|
hamster-core:
|
||||||
aliases: [ hcore, hc ]
|
aliases: [ hcore, hc, core ]
|
||||||
description: 仓鼠核心调试指令
|
description: 仓鼠核心调试指令
|
||||||
permission: hamster.core.admin
|
permission: hamster.core.admin
|
||||||
permission-message: §c你没有这个权限!
|
permission-message: §c你没有这个权限!
|
||||||
|
Reference in New Issue
Block a user