mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
Add /huskhomes help (Command list)
This commit is contained in:
1 parent
58b8c25a29
commit
80865aa060
5 files changed
+60
-4
No files matched your search
@@ -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" -> {
|
||||
|
||||
|
||||
Reference in new issue
Block a user