Page - landonjw/GooeyLibs GitHub Wiki

Page

A page defines a user interface that can be sent to a player, and may have behavior when it is opened or closed. Each page must have a specified Template, and can optionally have an InventoryTemplate. The base implementation of a Page supplied by GooeyLibs is GooeyPage.

You can implement your own pages to add more fine-tuning by implementing the Page interface. For an example of this see Asteroids in the cookbook.

Creating a Page

An example of creating a GooeyPage is:

        GooeyButton button = GooeyButton.builder()
                .display(new ItemStack(Items.DIAMOND))
                .build();

        ChestTemplate template = ChestTemplate.builder(6)
                .fill(button)
                .build();

        GooeyPage page = GooeyPage.builder()
                .template(template)
                .build();

Sending a Page

In order to send a page to a user, you should use the UIManager. This class has two methods for opening a page:

  • UIManager#openPageForcefully: This will immediately open the page for the player. If they have a container already open, it is closed.

  • UIManager#openPagePassively: This will wait for any open container to be closed before opening the page.

Following the previous example and assuming we have an EntityPlayerMP named player, an example of opening a page for a player is:

UIManager.openPageForcefully(player, page);

Updating a Page

You can invoke update on a PageBase in order to have it update any changes to all players viewing the page. In default implementations, invoking the setTitle or setTemplate methods will also automatically update the page for all viewers.

Page Synchronization

Sharing a single page instance between several players will cause the page to be synchronized for both players. Sharing templates will additionally synchronize.

Pagination

Pagination is primarily done through the PaginationHelper class. You define an area you want to paginate with PlaceholderButtons on a Template, and supply a list of buttons to PaginationHelper#createPagesFromPlaceholders, and it will automatically generate and link together a series of LinkedPage, returning the first page created. These LinkedPages essentially act as a doubley-linked list of Pages, allowing you to traverse with getNext and getPrevious.

You can optionally add a LinkedPage.Builder to define the page properties of the LinkedPages.

An example of pagination would be:

        List<Button> buttons = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            Button button = GooeyButton.builder()
                    .display(new ItemStack(Item.getItemById(100 + i)))
                    .build();
            buttons.add(button);
        }

        GooeyButton filler = GooeyButton.builder()
                .display(new ItemStack(Blocks.STAINED_GLASS_PANE, 1, EnumDyeColor.BLUE.getMetadata()))
                .build();

        LinkedPageButton previous = LinkedPageButton.builder()
                .title("Previous")
                .display(new ItemStack(Items.DIAMOND))
                .linkType(LinkType.Previous)
                .build();

        LinkedPageButton next = LinkedPageButton.builder()
                .title("Next")
                .display(new ItemStack(Items.DIAMOND))
                .linkType(LinkType.Next)
                .build();

        PlaceholderButton placeholder = new PlaceholderButton();

        ChestTemplate template = ChestTemplate.builder(6)
                .rectangle(1, 1, 4, 7, placeholder)
                .fill(filler)
                .set(5, 3, previous)
                .set(5, 5, next)
                .build();

        LinkedPage firstPage = PaginationHelper.createPagesFromPlaceholders(template, buttons, null);
⚠️ **GitHub.com Fallback** ⚠️