feat: 为指令工具添加 sendHelp 方法

This commit is contained in:
2022-10-29 03:49:56 +08:00
parent d1ba4d4519
commit 14cfd8ffe6
3 changed files with 17 additions and 14 deletions

View File

@@ -57,8 +57,7 @@ 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.");
//noinspection SpellCheckingInspection ParentCoreCommand.INSTANCE.hook(getCommand("HamsterCore"));
ParentCoreCommand.INSTANCE.hook(getCommand("hamstercore"));
ParentLoreCommand.INSTANCE.hook(getCommand("lore")); ParentLoreCommand.INSTANCE.hook(getCommand("lore"));
long time = System.currentTimeMillis() - start; long time = System.currentTimeMillis() - start;
logger.info("仓鼠核心启动完成,总计耗时 " + time + " ms."); logger.info("仓鼠核心启动完成,总计耗时 " + time + " ms.");

View File

@@ -99,6 +99,20 @@ public class ParentCommand extends ChildCommand {
return map; return map;
} }
public void sendHelp(@NotNull CommandSender sender) {
sender.sendMessage("§e==================== [" + name + "使用帮助] ====================");
Map<String, String> helpMap = getCommandHelp(sender);
int maxLength = helpMap.keySet().stream()
.map(String::length)
.max(Integer::compareTo)
.orElse(-1);
ArrayList<Map.Entry<String, String>> list = new ArrayList<>(helpMap.entrySet());
list.sort(Map.Entry.comparingByKey());
for (Map.Entry<String, String> entry : list) {
sender.sendMessage(String.format("§a%-" + maxLength + "s - %s", entry.getKey(), entry.getValue()));
}
}
public void hook(PluginCommand command) { public void hook(PluginCommand command) {
if (command == null) { if (command == null) {
return; return;
@@ -115,17 +129,7 @@ public class ParentCommand extends ChildCommand {
return true; return true;
} }
if (args.length == 0) { if (args.length == 0) {
sender.sendMessage("§e==================== [" + name + "使用帮助] ===================="); sendHelp(sender);
Map<String, String> helpMap = getCommandHelp(sender);
int maxLength = helpMap.keySet().stream()
.map(String::length)
.max(Integer::compareTo)
.orElse(-1);
ArrayList<Map.Entry<String, String>> list = new ArrayList<>(helpMap.entrySet());
list.sort(Map.Entry.comparingByKey());
for (Map.Entry<String, String> entry : list) {
sender.sendMessage(String.format("§a%-" + maxLength + "s - %s", entry.getKey(), entry.getValue()));
}
return true; return true;
} }
for (ChildCommand childCommand : childCommands) { for (ChildCommand childCommand : childCommands) {

View File

@@ -11,7 +11,7 @@ softdepend:
- PlayerPoints - PlayerPoints
commands: commands:
hamstercore: HamsterCore:
aliases: [ hcore, core ] aliases: [ hcore, core ]
description: 仓鼠核心调试指令 description: 仓鼠核心调试指令
permission: hamster.core.admin permission: hamster.core.admin