Yay code duplication for this PR, next PR implements cloud smh

This commit is contained in:
Frank van der Heijden 2021-07-21 03:11:14 +02:00
parent f10407b5ea
commit 02bee8c839
No known key found for this signature in database
GPG key ID: B808721C2DD5B5B8
2 changed files with 32 additions and 18 deletions

View file

@ -3,6 +3,8 @@ package net.frankheijden.serverutils.bungee.commands;
import static net.frankheijden.serverutils.common.config.Messenger.sendMessage; import static net.frankheijden.serverutils.common.config.Messenger.sendMessage;
import co.aikar.commands.BaseCommand; import co.aikar.commands.BaseCommand;
import co.aikar.commands.RegisteredCommand;
import co.aikar.commands.RootCommand;
import co.aikar.commands.annotation.CommandAlias; import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion; import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission; import co.aikar.commands.annotation.CommandPermission;
@ -61,16 +63,21 @@ public class CommandServerUtils extends BaseCommand {
FormatBuilder builder = FormatBuilder.create(Messenger.getMessage("serverutils.help.format")) FormatBuilder builder = FormatBuilder.create(Messenger.getMessage("serverutils.help.format"))
.orderedKeys("%command%", "%subcommand%", "%help%"); .orderedKeys("%command%", "%subcommand%", "%help%");
plugin.getCommandManager().getRegisteredRootCommands().stream()
.filter(c -> !ALIASES.contains(c.getCommandName().toLowerCase()))
.forEach(rootCommand -> {
builder.add(rootCommand.getCommandName(), "", rootCommand.getDescription());
rootCommand.getSubCommands().forEach((str, cmd) -> { Set<String> rootCommands = new HashSet<>();
if (cmd.getPrefSubCommand().isEmpty()) return; for (RootCommand root : plugin.getCommandManager().getRegisteredRootCommands()) {
builder.add(rootCommand.getCommandName(), " " + cmd.getPrefSubCommand(), cmd.getHelpText()); String rootName = root.getDefCommand().getName();
}); if (!rootCommands.add(rootName)) continue;
}); builder.add(rootName, "", root.getDescription());
Set<String> subCommands = new HashSet<>();
for (RegisteredCommand<?> sub : root.getSubCommands().values()) {
String name = sub.getPrefSubCommand().toLowerCase();
if (name.isEmpty()) continue;
if (!subCommands.add(name)) continue;
builder.add(rootName, " " + name, sub.getHelpText());
}
}
builder.sendTo(sender); builder.sendTo(sender);
Messenger.sendMessage(sender, "serverutils.help.footer"); Messenger.sendMessage(sender, "serverutils.help.footer");
} }

View file

@ -1,6 +1,8 @@
package net.frankheijden.serverutils.velocity.commands; package net.frankheijden.serverutils.velocity.commands;
import co.aikar.commands.BaseCommand; import co.aikar.commands.BaseCommand;
import co.aikar.commands.RegisteredCommand;
import co.aikar.commands.RootCommand;
import co.aikar.commands.annotation.CommandAlias; import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion; import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission; import co.aikar.commands.annotation.CommandPermission;
@ -64,16 +66,21 @@ public class CommandServerUtils extends BaseCommand {
FormatBuilder builder = FormatBuilder.create(Messenger.getMessage("serverutils.help.format")) FormatBuilder builder = FormatBuilder.create(Messenger.getMessage("serverutils.help.format"))
.orderedKeys("%command%", "%subcommand%", "%help%"); .orderedKeys("%command%", "%subcommand%", "%help%");
plugin.getCommandManager().getRegisteredRootCommands().stream()
.filter(c -> !ALIASES.contains(c.getCommandName().toLowerCase()))
.forEach(rootCommand -> {
builder.add(rootCommand.getCommandName(), "", rootCommand.getDescription());
rootCommand.getSubCommands().forEach((str, cmd) -> { Set<String> rootCommands = new HashSet<>();
if (cmd.getPrefSubCommand().isEmpty()) return; for (RootCommand root : plugin.getCommandManager().getRegisteredRootCommands()) {
builder.add(rootCommand.getCommandName(), " " + cmd.getPrefSubCommand(), cmd.getHelpText()); String rootName = root.getDefCommand().getName();
}); if (!rootCommands.add(rootName)) continue;
}); builder.add(rootName, "", root.getDescription());
Set<String> subCommands = new HashSet<>();
for (RegisteredCommand<?> sub : root.getSubCommands().values()) {
String name = sub.getPrefSubCommand().toLowerCase();
if (name.isEmpty()) continue;
if (!subCommands.add(name)) continue;
builder.add(rootName, " " + name, sub.getHelpText());
}
}
builder.sendTo(sender); builder.sendTo(sender);
Messenger.sendMessage(sender, "serverutils.help.footer"); Messenger.sendMessage(sender, "serverutils.help.footer");
} }