Skip to content

Utilities

James Collins edited this page Jan 5, 2025 · 9 revisions

STEMCraft contains utility classes to aid in the development of plugins:


SCChatMenu

Provides a simple class to generate menu lists in the players chat.

getPageFromArgs

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);

render

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 method SCChatMenu.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"
);    

Clone this wiki locally