Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 80903ac

Browse files
committed
fix help pagination (again)
1 parent 2c31827 commit 80903ac

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

‎src/main/java/de/oliver/fancynpcs/commands/npc/HelpCMD.java‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.bukkit.command.CommandSender;
77
import org.incendo.cloud.annotations.Argument;
88
import org.incendo.cloud.annotations.Command;
9+
import org.incendo.cloud.annotations.Default;
910
import org.incendo.cloud.annotations.Permission;
1011
import org.incendo.cloud.annotations.suggestion.Suggestions;
1112
import org.incendo.cloud.context.CommandContext;
@@ -15,7 +16,6 @@
1516
import java.util.List;
1617

1718
import org.jetbrains.annotations.NotNull;
18-
import org.jetbrains.annotations.Nullable;
1919

2020
public enum HelpCMD {
2121
INSTANCE; // SINGLETON
@@ -26,28 +26,24 @@ public enum HelpCMD {
2626
@Permission("fancynpcs.command.npc")
2727
public void onHelp(
2828
final @NotNull CommandSender sender,
29-
final @Nullable @Argument(suggestions = "HelpCMD/page") Integer page
29+
final @Argument(suggestions = "HelpCMD/page") @Default("1") int page
3030
) {
3131
// Getting the (full) help contents.
3232
final MultiMessage contents = (MultiMessage) translator.translate("npc_help_contents");
3333
// Calculating max page number.
34-
final int maxPage = (int) Math.ceil(Math.max(1, contents.getRawMessages().size() - 1) / 6F);
34+
final int maxPage = (int) Math.ceil(contents.getRawMessages().size() / 6F);
3535
// Getting the requested page. Defaults to 1 for invalid input and is capped by number of the last page.
36-
final int finalPage = Math.min(page != null ? page : 1, maxPage);
37-
// Getting help contents for requested page, or defaulting to 1.
38-
final MultiMessage requestedContents = contents.page(finalPage, 6);
39-
// Sending help header to the sender.
36+
final int finalPage = Math.clamp(page, 1, maxPage);
37+
// Sending help contents to the sender.
4038
translator.translate("npc_help_page_header").replace("page", String.valueOf(finalPage)).replace("max_page", String.valueOf(maxPage)).send(sender);
41-
// Sending (requested) help contents to the sender.
42-
requestedContents.send(sender);
43-
// Sending help footer to the sender.
39+
contents.page(finalPage, 6).send(sender);
4440
translator.translate("npc_help_page_footer").replace("page", String.valueOf(finalPage)).replace("max_page", String.valueOf(maxPage)).send(sender);
4541
}
4642

4743
/* PARSERS AND SUGGESTIONS */
4844

4945
@Suggestions("HelpCMD/page")
50-
public List<String> suggestions(final CommandContext<CommandSender> context, final CommandInput input) {
46+
public List<String> suggestPage(final CommandContext<CommandSender> context, final CommandInput input) {
5147
// Getting the (full) help contents.
5248
final MultiMessage contents = (MultiMessage) translator.translate("npc_help_contents");
5349
// Calculating max page number.

0 commit comments

Comments
 (0)