Skip to content

Adventure Components

Hamza Coşkun edited this page Mar 27, 2024 · 11 revisions

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.

TL;DR

To use components: new Icon(Material.STONE).toComp().setName(Component.text("name"))

To use strings: new Icon(Material.STONE).setName("name")

Converting Icon to ComponentIcon

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()

Converting ComponentIcon to Icon

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()

Difference between Icon & ComponentIcon

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.

Passing real component to Gui title

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);
}