This repository was archived by the owner on Dec 11, 2024. It is now read-only.
Repository navigation
GUI
Syrent edited this page Jun 21, 2023
·
2 revisions
The GUI class represents a graphical user interface for inventory-based interactions in the Origin plugin. It provides methods for managing inventory items, handling events, and customizing GUI behavior.
- Easy creation and management of inventory-based GUIs.
- Event handling for GUI interactions such as item clicks, GUI open/close events, and more.
- Customizable behavior through consumer functions and overrideable methods.
The ExampleShopItem class represents an item in a shop GUI. It has an associated price represented by an integer.
public class ExampleShopItem {
private final int price;
public ExampleShopItem(int price) {
this.price = price;
}
public int getPrice() {
return price;
}
}GUIWrappedGenericGUIExampleShopItem> gui = new WrappedGenericGUI<>("My GUI", InventoryType.CHEST, 27)
.onOpen((player, inventory) -> {
// Custom behavior when GUI is opened
})
.onClick((player, item) -> {
// Custom behavior when an item is clicked
int price = item.getData().getPrice();
System.out.println("Item price: " + price);
})
.onClose((player, inventory) -> {
// Custom behavior when GUI is closed
})
.disableClick()
.setItem(new Item<>(0, new ItemStack(Material.DIAMOND, 1), new ExampleShopItem(10)))
.fill(new ItemStack(Material.GLASS, 1), 9, 17);WrappedSimpleGUI gui = new WrappedSimpleGUI("My GUI", InventoryType.CHEST, 27)
.onOpen((player, inventory) -> {
// Custom behavior when GUI is opened
})
.onClick((player, item) -> {
// Custom behavior when an item is clicked
System.out.println("Item type is: " + item.getType());
})
.onClose((player, inventory) -> {
// Custom behavior when GUI is closed
})
.disableClick()
.setItem(new Item<>(0, new ItemStack(Material.DIAMOND, 1), new ExampleShopItem(10)))
.fill(new ItemStack(Material.GLASS, 1), 9, 17);public class MyCustomGUI extends GUI<ExampleShopItem> {
public MyCustomGUI() {
super("Custom GUI", InventoryType.CHEST, 54);
}
@Override
public void onOpen(Player player, Inventory inventory) {
// Custom behavior when GUI is opened
}
@Override
public boolean onClick(Player player, InventoryItem<ExampleShopItem> item, ClickType clickType) {
// Custom behavior when an item is clicked
int price = item.getData().getPrice();
System.out.println("Item price: " + price);
return super.onClick(player, item, clickType);
}
@Override
public void onClose(Player player, Inventory inventory) {
// Custom behavior when GUI is closed
}
}public class MyCustomGUI extends SimpleGUI {
public MyCustomGUI() {
super("Custom GUI", InventoryType.CHEST, 54);
}
@Override
public void onOpen(Player player, Inventory inventory) {
// Custom behavior when GUI is opened
}
@Override
public boolean onClick(Player player, InventoryItem<ItemStack> item, ClickType clickType) {
// Custom behavior when an item is clicked
System.out.println("Item type: " + item.getType());
return super.onClick(player, item, clickType);
}
@Override
public void onClose(Player player, Inventory inventory) {
// Custom behavior when GUI is closed
}
}