NextDevv's Docs Help

Pages

class Pages { val pages: MutableList<GuiPage> = mutableListOf() fun addPage(guiPage: GuiPage): Pages { pages.add(guiPage) return this } fun addPage(guiPage: GuiPage, index: Int): Pages { pages.add(index, guiPage) return this } fun removePage(index: Int): Pages { pages.removeAt(index) return this } fun removePage(guiPage: GuiPage): Pages { pages.remove(guiPage) return this } fun filterPages(predicate: (GuiPage) -> Boolean): Pages { pages.filter(predicate) return this } fun builder(): Builder { return Builder() } class Builder() { private val pages: MutableList<GuiPage> = mutableListOf() private var maxPerPages = 10 fun autoCreatePages(itemStacks: List<ItemStack>): Builder { var guiPage = GuiPage() for (itemStack in itemStacks) { if (guiPage.getContent().size >= maxPerPages) { pages.add(guiPage) guiPage = GuiPage() } guiPage.addItem(itemStack) } pages.add(guiPage) return this } fun setMaxPerPages(maxPerPages: Int): Builder { this.maxPerPages = maxPerPages return this } fun build(): Pages { val pages = Pages() pages.pages.addAll(this.pages) return pages } } }

Description & Properties

The Pages class is used to manage multiple GuiPage objects within a GUI. It has the following properties and methods:

  • pages: A list of GuiPage objects that represent the pages in the GUI.

  • addPage(guiPage: GuiPage): Pages: Adds a GuiPage to the list of pages.

  • addPage(guiPage: GuiPage, index: Int): Pages: Adds a GuiPage at the specified index in the list of pages.

  • removePage(index: Int): Pages: Removes the GuiPage at the specified index from the list of pages.

  • removePage(guiPage: GuiPage): Pages: Removes the specified GuiPage from the list of pages.

  • filterPages(predicate: (GuiPage) -> Boolean): Pages: Filters the list of pages based on the given predicate.

  • builder(): Builder: Returns a Builder object to create and configure a Pages object.

  • Builder: A nested class that provides methods to configure and build a Pages object.

    • pages: A list of GuiPage objects to be added to the Pages object.

    • maxPerPages: The maximum number of items per page.

    • autoCreatePages(itemStacks: List<ItemStack): Builder: Automatically creates pages based on a list of item stacks, splitting them into pages based on the maxPerPages value.

    • setMaxPerPages(maxPerPages: Int): Builder: Sets the maximum number of items per page.

    • build(): Pages: Builds and returns a Pages object with the configured settings.

Example

You can use the Pages class to manage multiple GuiPage objects within a GUI and automatically split a list of item stacks into pages. This allows you to create paginated GUIs with a fixed number of items per page.

Here is an example of how to use the Pages class in Kotlin:

// Create a Pages object var pages = Pages() // Create a list of item stacks val itemStacks = listOf( ItemStack(Material.APPLE), ItemStack(Material.BREAD), ItemStack(Material.CARROT), ItemStack(Material.DIAMOND) ) // Create a Pages builder val builder = pages.builder() // Configure the builder builder.setMaxPerPages(2) builder.autoCreatePages(itemStacks) // Build the Pages object pages = builder.build()

In this example, we create a Pages object and use a builder to configure it. We set the maximum number of items per page to 2 and automatically split a list of item stacks into pages. The resulting Pages object contains the paginated content based on the specified settings.

You can then use the Pages object to manage and display multiple pages of content within a GUI, allowing players to navigate through the pages to view different items or information.

Summary

The Pages class provides a convenient way to manage multiple GuiPage objects within a GUI and create paginated interfaces for displaying content. By organizing items into pages and allowing players to navigate between them, you can enhance the user experience and present information in a structured and accessible manner.

Last modified: 03 July 2024