Repository navigation
Item
The Item class represents a custom item in the Origin plugin. It allows you to define behavior for when the item is used by a player. The class provides flexibility by allowing you to associate additional data with the item, which can be accessed during item use events.
- Register event listeners automatically upon initialization.
- Set consumer functions to handle item use events.
- Support for associating additional data with items.
- Conversion of ItemStack to Item for convenience.
To use the Item class, follow these steps:
- Create an instance of Item by providing the item stack and optional data:
Item<ExampleShopItem> item = new Item<>(itemStack, data);SimpleItem item = new Item(itemStack);itemStack: The item stack representing the custom item. data: Additional data associated with the item (optional). 2. Register consumer functions to handle item use events using the onUse method:
item.onUse(itemConsumer -> {
Bukkit.broadcast(Component.text("The item type is: " + itemStack.getType()));
});
item.onUse((item, itemData) -> {
// Handle item use with additional data
Bukkit.broadcast(Component.text("The price of " + itemStack.getType() + " is: " + itemData.data));
});itemConsumer: A consumer function that accepts the item stack as a parameter. (item, itemData): A bi-consumer function that accepts the item stack and associated data as parameters. 3. Handle the item use events in the consumer functions:
Consumer<ItemStack> itemConsumer = itemStack -> {
Bukkit.broadcast(Component.text("The item type is: " + itemStack.getType()));
};
BiConsumer<ItemStack, ExampleShopItem> itemDataConsumer = (itemStack, itemData) -> {
// Handle item use with additional data
Bukkit.broadcast(Component.text("The price of " + itemStack.getType() + " is: " + itemData.price));
};- Listen for the item use events by registering the Item as a listener:
Origin.registerListener(item);- Optionally, convert an existing ItemStack to an Item using the extension function toOriginItem:
ItemStack itemStack = new ItemStack(Material.DIAMOND);
OriginItem<ExampleShopItem> item = itemStack.toOriginItem();ItemStack itemStack = new ItemStack(Material.DIAMOND);
SimpleItem item = itemStack.toOriginItem();By following these steps, you can create and customize Item instances to add custom behavior to your items in the Origin plugin.