-
Notifications
You must be signed in to change notification settings - Fork 88
Amount selector
stefvanschie edited this page Oct 22, 2021
·
3 revisions
Languages: Dutch (Nederlands)
Example code for creating an amount selector. This can, for example, be used to let players decide how much of an item they want to buy or sell in a shop.
ChestGui gui = new ChestGui(3, "Select amount");
ItemStack item = new ItemStack(Material.DIAMOND);
OutlinePane itemPane = new OutlinePane(4, 1, 1, 1);
itemPane.addItem(new GuiItem(item));
Label decrement = new Label(2, 1, 1, 1, Font.OAK_PLANKS);
decrement.setText("-");
decrement.setVisible(false);
Label increment = new Label(6, 1, 1, 1, Font.OAK_PLANKS);
increment.setText("+");
if (item.getMaxStackSize() == 1) {
increment.setVisible(false);
}
decrement.setOnClick(event -> {
item.setAmount(item.getAmount() - 1);
if (item.getAmount() == 1) {
decrement.setVisible(false);
}
increment.setVisible(true);
gui.update();
});
increment.setOnClick(event -> {
item.setAmount(item.getAmount() + 1);
decrement.setVisible(true);
if (item.getAmount() == item.getMaxStackSize()) {
increment.setVisible(false);
}
gui.update();
});
gui.addPane(itemPane);
gui.addPane(decrement);
gui.addPane(increment);
<chestgui title="Select amount" rows="3">
<outlinepane x="4" y="1" length="1" height="1">
<item id="diamond" />
</outlinepane>
<label x="2" y="1" length="1" height="1" font="oak_planks" text="-" visible="false" />
<label x="6" y="1" length="1" height="1" font="oak_planks" text="+" />
</chestgui>