Skip to content
stefvanschie edited this page Nov 30, 2021 · 4 revisions

Languages: Dutch (Nederlands)

Shop

Example code for a shop gui. This gui can be used to let players buy items.

The shop gui as produced by the code snippet below

Code

ChestGui gui = new ChestGui(6, "Shop");

PaginatedPane pages = new PaginatedPane(0, 0, 9, 5);
pages.populateWithItemStacks(Arrays.asList(
    new ItemStack(Material.GOLDEN_SWORD),
    new ItemStack(Material.LIGHT_GRAY_GLAZED_TERRACOTTA, 16),
    new ItemStack(Material.COOKED_COD, 64)
));
pages.setOnClick(event -> {
    //buy item
});

gui.addPane(pages);

OutlinePane background = new OutlinePane(0, 5, 9, 1);
background.addItem(new GuiItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE)));
background.setRepeat(true);
background.setPriority(Pane.Priority.LOWEST);

gui.addPane(background);

StaticPane navigation = new StaticPane(0, 5, 9, 1);
navigation.addItem(new GuiItem(new ItemStack(Material.RED_WOOL), event -> {
    if (pages.getPage() > 0) {
        pages.setPage(pages.getPage() - 1);

        gui.update();
    }
 }), 0, 0);

navigation.addItem(new GuiItem(new ItemStack(Material.GREEN_WOOL), event -> {
    if (pages.getPage() < pages.getPages() - 1) {
        pages.setPage(pages.getPage() + 1);

        gui.update();
    }
}), 8, 0);

navigation.addItem(new GuiItem(new ItemStack(Material.BARRIER), event ->
    event.getWhoClicked().closeInventory()), 4, 0);

gui.addPane(navigation);

XML

<chestgui title="Shop" rows="6">
  <paginatedpane x="0" y="0" length="9" height="5">
    <page>
      <outlinepane x="0" y="0" length="9" height="5">
        <item id="golden_sword" />
        <item id="light_gray_glazed_terracotta" amount="16" />
        <item id="cooked_cod" amount="64" />
      </outlinepane>
    </page>
  </paginatedpane>
  <outlinepane x="0" y="5" length="9" height="1" priority="lowest" repeat="true">
    <item id="black_stained_glass_pane" />
  </outlinepane>
  <staticpane x="0" y="5" length="9" height="1">
    <item id="red_wool" x="0" y="0" />
    <item id="barrier" x="4" y="0" />
    <item id="green_wool" x="8" y="0" />
  </staticpane>
</chestgui>
Clone this wiki locally