-
Notifications
You must be signed in to change notification settings - Fork 18
Adventure Components
The obliviate-invs library supports components since version 4.1.12. However, it is not designed for components directly. To utilize components, you should use a proxy class. The class you need to use is called ComponentIcon, which can be found in the core module.
To use components: new Icon(Material.STONE).toComp().setName(Component.text("name"))
To use strings: new Icon(Material.STONE).setName("name")
To convert an icon into a component icon, you can use the static method provided by ComponentIcon:
ComponentIcon.fromIcon(new Icon(Material.STONE))
Alternatively, the Icon class also has an easy-to-use method for this conversion:
ComponentIcon compIcon = new Icon(Material.STONE).toComp()
If you are familiar with the proxy pattern, you know that each ComponentIcon actually contains an Icon object internally. Therefore, you can easily access it using the following method:
compIcon.toIcon()
Both ComponentIcon and Icon have the same set of methods, such as setAmount, setDurability, hideFlags, etc.
However, there are some differences in the available methods for setting lore, appending lore, inserting lore, and setting the name:
- ComponentIcon does not have methods like setLore, appendLore, insertLore, or setName that require a string parameter. Instead, ComponentIcon exclusively uses components.
- On the other hand, Icon does not have methods like setLore, appendLore, insertLore, or setName that require a component parameter. It only uses strings.
We used the 'real' term because obliviate-invs serialize and deserialize components. However, you can pass pure components for Gui titles. It allows you to modify the created Bukkit inventory object. Just override createInventory()
method.
@Override
protected Inventory createInventory(InventoryHolder owner, int size, String title) {
return Bukkit.createInventory(null, size, YOUR_COMPONENT);
}