Skip to content
stefvanschie edited this page Aug 15, 2023 · 10 revisions

Languages: Dutch (Nederlands)

Navigator

Example code for a navigator gui. This gui can for example be used to let the player travel to different places.

The navigator GUI as produced by the above code snippet

Code

ChestGui gui = new ChestGui(3, "Navigator");

gui.setOnGlobalClick(event -> event.setCancelled(true));

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

gui.addPane(background);

OutlinePane navigationPane = new OutlinePane(3, 1, 3, 1);

ItemStack shop = new ItemStack(Material.CHEST);
ItemMeta shopMeta = shop.getItemMeta();
shopMeta.setDisplayName("Shop");
shop.setItemMeta(shopMeta);

navigationPane.addItem(new GuiItem(shop, event -> {
    //navigate to the shop
}));

ItemStack beacon = new ItemStack(Material.BEACON);
ItemMeta beaconMeta = beacon.getItemMeta();
beaconMeta.setDisplayName("Spawn");
beacon.setItemMeta(beaconMeta);

navigationPane.addItem(new GuiItem(beacon, event -> {
    //navigate to spawn
}));

ItemStack bed = new ItemStack(Material.RED_BED);
ItemMeta bedMeta = bed.getItemMeta();
bedMeta.setDisplayName("Home");
bed.setItemMeta(bedMeta);

navigationPane.addItem(new GuiItem(bed, event -> {
    //navigate to home
}));

gui.addPane(navigationPane);

XML

<chestgui title="Navigator" rows="3">
  <outlinepane x="0" y="0" length="9" height="3" priority="lowest" repeat="true">
    <item id="black_stained_glass_pane" />
  </outlinepane>
  <outlinepane x="3" y="1" length="3" height="1">
    <item id="chest">
      <displayname>Shop</displayname>
    </item>
    <item id="beacon">
      <displayname>Spawn</displayname>
    </item>
    <item id="red_bed">
      <displayname>Home</displayname>
    </item>
  </outlinepane>
</chestgui>
Clone this wiki locally