-
Notifications
You must be signed in to change notification settings - Fork 0
Utilities
James Collins edited this page Jan 5, 2025
·
9 revisions
STEMCraft contains utility classes to aid in the development of plugins:
Provides a simple class to generate menu lists in the players chat.
This static method requires a List\<String\> parameter containing the command arguments provided by the player. It will then return the page requested by the player, or page 1, as an integer.
-
List\<String\> argList: The command argument list.
int page = SCChatMenu.getPageFromArgs(args);This static method generates the chat menu for the player based on the provided arguments:
-
CommandSender sender: The command sender to respond with the chat menu. The chat menu does not work from the console. -
String title: The title of the chat menu. -
String command: The command to use to show the chat menu itself. This command is used as a prefix when moving between pages. -
int page: The page to display in the menu. This can be obtained from the last command argument (if provided by the player) or the helper methodSCChatMenu.getPageFromArgs. -
int size: The amount of items in the entire list (not just the current page). -
BiFunction<Integer start, Integer count, List<Component>> func: The callback function used to format each list item. Provides the list index starting point (start) and the amount of items to display (count). -
String noneText: The string to display when the list is empty.
String title = "Generators";
String command = "world listgenerators";
int page = SCChatMenu.getPageFromArgs(args);
SCChatMenu.render(
sender,
title,
command,
page,
generators.size(),
(Integer start, Integer count) -> {
List<Component> list = new ArrayList<>();
int end = Math.min(start + count, generators.size()); // Ensure bounds
for (int i = start; i < end; i++) {
Component component = Component.text((i + 1) + ". ", NamedTextColor.LIGHT_PURPLE)
.append(Component.text(generators.get(i) + " ", NamedTextColor.GOLD));
list.add(component);
}
return list;
},
"No generators where found"
);