mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 22:16:34 +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
@@ -4,6 +4,7 @@ import io.papermc.lib.PaperLib;
|
|||||||
import net.william278.annotaml.Annotaml;
|
import net.william278.annotaml.Annotaml;
|
||||||
import net.william278.huskhomes.command.BukkitCommand;
|
import net.william278.huskhomes.command.BukkitCommand;
|
||||||
import net.william278.huskhomes.command.BukkitCommandType;
|
import net.william278.huskhomes.command.BukkitCommandType;
|
||||||
|
import net.william278.huskhomes.command.CommandBase;
|
||||||
import net.william278.huskhomes.command.DisabledCommand;
|
import net.william278.huskhomes.command.DisabledCommand;
|
||||||
import net.william278.huskhomes.config.Locales;
|
import net.william278.huskhomes.config.Locales;
|
||||||
import net.william278.huskhomes.config.Settings;
|
import net.william278.huskhomes.config.Settings;
|
||||||
@@ -64,6 +65,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
|
|||||||
private RtpEngine rtpEngine;
|
private RtpEngine rtpEngine;
|
||||||
private Spawn serverSpawn;
|
private Spawn serverSpawn;
|
||||||
private Set<PluginHook> pluginHooks;
|
private Set<PluginHook> pluginHooks;
|
||||||
|
private List<CommandBase> registeredCommands;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private NetworkMessenger networkMessenger;
|
private NetworkMessenger networkMessenger;
|
||||||
@@ -175,6 +177,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
|
|||||||
})));
|
})));
|
||||||
|
|
||||||
// Register commands
|
// Register commands
|
||||||
|
this.registeredCommands = new ArrayList<>();
|
||||||
Arrays.stream(BukkitCommandType.values()).forEach(commandType -> {
|
Arrays.stream(BukkitCommandType.values()).forEach(commandType -> {
|
||||||
final PluginCommand pluginCommand = getCommand(commandType.commandBase.command);
|
final PluginCommand pluginCommand = getCommand(commandType.commandBase.command);
|
||||||
if (pluginCommand == null) {
|
if (pluginCommand == null) {
|
||||||
@@ -193,7 +196,9 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, register the command
|
// 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.");
|
getLoggingAdapter().log(Level.INFO, "Successfully registered permissions & commands.");
|
||||||
|
|
||||||
@@ -351,6 +356,11 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
|
|||||||
return Version.fromString(getDescription().getVersion());
|
return Version.fromString(getDescription().getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<CommandBase> getCommands() {
|
||||||
|
return registeredCommands;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link Server} the plugin is on
|
* Returns the {@link Server} the plugin is on
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.william278.huskhomes;
|
package net.william278.huskhomes;
|
||||||
|
|
||||||
import de.themoep.minedown.MineDown;
|
import de.themoep.minedown.MineDown;
|
||||||
|
import net.william278.huskhomes.command.CommandBase;
|
||||||
import net.william278.huskhomes.config.Locales;
|
import net.william278.huskhomes.config.Locales;
|
||||||
import net.william278.huskhomes.database.Database;
|
import net.william278.huskhomes.database.Database;
|
||||||
import net.william278.huskhomes.player.OnlineUser;
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
@@ -105,6 +106,7 @@ public class Cache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private ListOptions.Builder getBaseList(@NotNull Locales locales, int itemsPerPage) {
|
private ListOptions.Builder getBaseList(@NotNull Locales locales, int itemsPerPage) {
|
||||||
return new ListOptions.Builder().setFooterFormat(locales.getRawLocale("list_footer",
|
return new ListOptions.Builder().setFooterFormat(locales.getRawLocale("list_footer",
|
||||||
"%previous_page_button%", "%current_page%",
|
"%previous_page_button%", "%current_page%",
|
||||||
@@ -126,6 +128,7 @@ public class Cache {
|
|||||||
.setEscapeItemsMineDown(false);
|
.setEscapeItemsMineDown(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public MineDown getHomeList(@NotNull OnlineUser onlineUser, @NotNull User listOwner, @NotNull Locales locales,
|
public MineDown getHomeList(@NotNull OnlineUser onlineUser, @NotNull User listOwner, @NotNull Locales locales,
|
||||||
@NotNull List<Home> homes, final int itemsPerPage, final int page) {
|
@NotNull List<Home> homes, final int itemsPerPage, final int page) {
|
||||||
final PaginatedList homeList = PaginatedList.of(homes.stream().map(home ->
|
final PaginatedList homeList = PaginatedList.of(homes.stream().map(home ->
|
||||||
@@ -142,6 +145,23 @@ public class Cache {
|
|||||||
return homeList.getNearestValidPage(page);
|
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
|
@NotNull
|
||||||
public MineDown getPublicHomeList(@NotNull OnlineUser onlineUser, @NotNull Locales locales,
|
public MineDown getPublicHomeList(@NotNull OnlineUser onlineUser, @NotNull Locales locales,
|
||||||
@NotNull List<Home> publicHomes, final int itemsPerPage, final int page) {
|
@NotNull List<Home> publicHomes, final int itemsPerPage, final int page) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.william278.huskhomes;
|
package net.william278.huskhomes;
|
||||||
|
|
||||||
|
import net.william278.huskhomes.command.CommandBase;
|
||||||
import net.william278.huskhomes.config.Locales;
|
import net.william278.huskhomes.config.Locales;
|
||||||
import net.william278.huskhomes.config.Settings;
|
import net.william278.huskhomes.config.Settings;
|
||||||
import net.william278.huskhomes.config.Spawn;
|
import net.william278.huskhomes.config.Spawn;
|
||||||
@@ -228,10 +229,19 @@ public interface HuskHomes {
|
|||||||
@NotNull
|
@NotNull
|
||||||
Version getPluginVersion();
|
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
|
* 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
|
* @return a {@link CompletableFuture} that will be completed when the plugin reload is complete and if it was successful
|
||||||
*/
|
*/
|
||||||
CompletableFuture<Boolean> reload();
|
CompletableFuture<Boolean> reload();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ public class HuskHomesCommand extends CommandBase implements ConsoleExecutable,
|
|||||||
|
|
||||||
protected HuskHomesCommand(@NotNull HuskHomes implementor) {
|
protected HuskHomesCommand(@NotNull HuskHomes implementor) {
|
||||||
super("huskhomes", Permission.COMMAND_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")
|
.withDescription("A powerful, intuitive and flexible teleportation suite")
|
||||||
.withVersion(implementor.getPluginVersion())
|
.withVersion(implementor.getPluginVersion())
|
||||||
.addAttribution("Author",
|
.addAttribution("Author",
|
||||||
@@ -48,10 +48,26 @@ public class HuskHomesCommand extends CommandBase implements ConsoleExecutable,
|
|||||||
sendAboutMenu(onlineUser);
|
sendAboutMenu(onlineUser);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (args.length > 2) {
|
||||||
|
plugin.getLocales().getLocale("error_invalid_syntax", "/huskhomes [about|help|reload|update]")
|
||||||
|
.ifPresent(onlineUser::sendMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "about" -> sendAboutMenu(onlineUser);
|
case "about" -> sendAboutMenu(onlineUser);
|
||||||
case "help" -> {
|
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" -> {
|
case "reload" -> {
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ command_list_title: '[HuskHomes](#00fb9a bold) [| Command List](#00fb9a)'
|
|||||||
home_list_item: '[[%1%]](show_text=�fb9a&%1%\n&7ℹ %3% run_command=/huskhomes:edithome %2%)'
|
home_list_item: '[[%1%]](show_text=�fb9a&%1%\n&7ℹ %3% run_command=/huskhomes:edithome %2%)'
|
||||||
public_home_list_item: '[[%1%]](show_text=�fb9a&%1%\n&7☻ %3%\n&7ℹ %4% run_command=/huskhomes:publichome %2%)'
|
public_home_list_item: '[[%1%]](show_text=�fb9a&%1%\n&7☻ %3%\n&7ℹ %4% run_command=/huskhomes:publichome %2%)'
|
||||||
warp_list_item: '[[%1%]](show_text=�fb9a&%1%\n&7ℹ %2% run_command=/huskhomes:warp %1%)'
|
warp_list_item: '[[%1%]](show_text=�fb9a&%1%\n&7ℹ %2% run_command=/huskhomes:warp %1%)'
|
||||||
command_list_item: '[/%1%](#00fb9a show_text=�fb9a&%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=�fb9a&/%1%\n&7%3%)'
|
||||||
|
|
||||||
list_item_divider: ' [•](gray) '
|
list_item_divider: ' [•](gray) '
|
||||||
list_footer: '%1%[Page](#00fb9a) [%2%](#00fb9a)/[%3%](#00fb9a)%4% %5%'
|
list_footer: '%1%[Page](#00fb9a) [%2%](#00fb9a)/[%3%](#00fb9a)%4% %5%'
|
||||||
|
|||||||
Reference in new issue
Block a user