Add /huskhomes help (Command list)

This commit is contained in:
William committed 2022-08-24 15:10:32 +01:00
1 parent 58b8c25a29
commit 80865aa060
5 files changed
+60 -4

No files matched your search

@@ -4,6 +4,7 @@ import io.papermc.lib.PaperLib;
import net.william278.annotaml.Annotaml;
import net.william278.huskhomes.command.BukkitCommand;
import net.william278.huskhomes.command.BukkitCommandType;
import net.william278.huskhomes.command.CommandBase;
import net.william278.huskhomes.command.DisabledCommand;
import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.config.Settings;
@@ -64,6 +65,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
private RtpEngine rtpEngine;
private Spawn serverSpawn;
private Set<PluginHook> pluginHooks;
private List<CommandBase> registeredCommands;
@Nullable
private NetworkMessenger networkMessenger;
@@ -175,6 +177,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
})));
// Register commands
this.registeredCommands = new ArrayList<>();
Arrays.stream(BukkitCommandType.values()).forEach(commandType -> {
final PluginCommand pluginCommand = getCommand(commandType.commandBase.command);
if (pluginCommand == null) {
@@ -193,7 +196,9 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
}
// Otherwise, register the command
new BukkitCommand(commandType.commandBase, this).register(pluginCommand);
final CommandBase commandBase = commandType.commandBase;
this.registeredCommands.add(commandBase);
new BukkitCommand(commandBase, this).register(pluginCommand);
});
getLoggingAdapter().log(Level.INFO, "Successfully registered permissions & commands.");
@@ -351,6 +356,11 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
return Version.fromString(getDescription().getVersion());
}
@Override
public @NotNull List<CommandBase> getCommands() {
return registeredCommands;
}
/**
* Returns the {@link Server} the plugin is on
*
@@ -1,6 +1,7 @@
package net.william278.huskhomes;
import de.themoep.minedown.MineDown;
import net.william278.huskhomes.command.CommandBase;
import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.database.Database;
import net.william278.huskhomes.player.OnlineUser;
@@ -105,6 +106,7 @@ public class Cache {
}
}
@NotNull
private ListOptions.Builder getBaseList(@NotNull Locales locales, int itemsPerPage) {
return new ListOptions.Builder().setFooterFormat(locales.getRawLocale("list_footer",
"%previous_page_button%", "%current_page%",
@@ -126,6 +128,7 @@ public class Cache {
.setEscapeItemsMineDown(false);
}
@NotNull
public MineDown getHomeList(@NotNull OnlineUser onlineUser, @NotNull User listOwner, @NotNull Locales locales,
@NotNull List<Home> homes, final int itemsPerPage, final int page) {
final PaginatedList homeList = PaginatedList.of(homes.stream().map(home ->
@@ -142,6 +145,23 @@ public class Cache {
return homeList.getNearestValidPage(page);
}
@NotNull
public MineDown getCommandList(@NotNull Locales locales, @NotNull List<CommandBase> commands,
final int itemsPerPage, final int page) {
return PaginatedList.of(commands.stream().map(command -> locales.getRawLocale("command_list_item",
Locales.escapeMineDown(command.command),
Locales.escapeMineDown(command.getDescription().length() > 50
? command.getDescription().substring(0, 49).trim() + "…"
: command.getDescription()),
Locales.escapeMineDown(locales.formatDescription(command.getDescription())))
.orElse(command.command))
.collect(Collectors.toList()),
getBaseList(locales, itemsPerPage)
.setHeaderFormat(locales.getRawLocale("command_list_title").orElse(""))
.setItemSeparator("\n").setCommand("/huskhomes:huskhomes help").build())
.getNearestValidPage(page);
}
@NotNull
public MineDown getPublicHomeList(@NotNull OnlineUser onlineUser, @NotNull Locales locales,
@NotNull List<Home> publicHomes, final int itemsPerPage, final int page) {
@@ -1,5 +1,6 @@
package net.william278.huskhomes;
import net.william278.huskhomes.command.CommandBase;
import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.config.Settings;
import net.william278.huskhomes.config.Spawn;
@@ -228,10 +229,19 @@ public interface HuskHomes {
@NotNull
Version getPluginVersion();
/**
* Returns a list of enabled commands
*
* @return A list of registered and enabled {@link CommandBase}s
*/
@NotNull
List<CommandBase> getCommands();
/**
* Reloads the {@link Settings} and {@link Locales} from their respective config files
*
* @return a {@link CompletableFuture} that will be completed when the plugin reload is complete and if it was successful
*/
CompletableFuture<Boolean> reload();
}
@@ -20,7 +20,7 @@ public class HuskHomesCommand extends CommandBase implements ConsoleExecutable,
protected HuskHomesCommand(@NotNull HuskHomes implementor) {
super("huskhomes", Permission.COMMAND_HUSKHOMES, implementor);
aboutMenu = AboutMenu.create("HuskHomes")
this.aboutMenu = AboutMenu.create("HuskHomes")
.withDescription("A powerful, intuitive and flexible teleportation suite")
.withVersion(implementor.getPluginVersion())
.addAttribution("Author",
@@ -48,10 +48,26 @@ public class HuskHomesCommand extends CommandBase implements ConsoleExecutable,
sendAboutMenu(onlineUser);
return;
}
if (args.length > 2) {
plugin.getLocales().getLocale("error_invalid_syntax", "/huskhomes [about|help|reload|update]")
.ifPresent(onlineUser::sendMessage);
return;
}
switch (args[0].toLowerCase()) {
case "about" -> sendAboutMenu(onlineUser);
case "help" -> {
// todo sendHelpMenu(onlineUser);
int page = 1;
if (args.length == 2) {
try {
page = Integer.parseInt(args[1]);
} catch (NumberFormatException ignored) {
plugin.getLocales().getLocale("error_invalid_syntax", "/huskhomes help <page>")
.ifPresent(onlineUser::sendMessage);
return;
}
}
onlineUser.sendMessage(plugin.getCache().getCommandList(plugin.getLocales(), plugin.getCommands(),
plugin.getSettings().listItemsPerPage, page));
}
case "reload" -> {
+1 -1
View File
@@ -55,7 +55,7 @@ command_list_title: '[HuskHomes](#00fb9a bold) [| Command List](#00fb9a)'
home_list_item: '[[%1%]](show_text=&#00fb9a&%1%\n&7ℹ %3% run_command=/huskhomes:edithome %2%)'
public_home_list_item: '[[%1%]](show_text=&#00fb9a&%1%\n&7☻ %3%\n&7ℹ %4% run_command=/huskhomes:publichome %2%)'
warp_list_item: '[[%1%]](show_text=&#00fb9a&%1%\n&7ℹ %2% run_command=/huskhomes:warp %1%)'
command_list_item: '[/%1%](#00fb9a show_text=&#00fb9a&%2% suggest_command=/%1%) [•](white) [%3%](gray)'
command_list_item: '[/%1%](#00fb9a show_text=&7Click to suggest command suggest_command=/%1%) [%2%](gray show_text=&#00fb9a&/%1%\n&7%3%)'
list_item_divider: ' [•](gray) '
list_footer: '%1%[Page](#00fb9a) [%2%](#00fb9a)/[%3%](#00fb9a)%4% %5%'