Class VersionedComponentUtil
java.lang.Object
com.kamikazejam.kamicommon.nms.util.VersionedComponentUtil
Utility for interacting with
VersionedComponent and various server apis.
This provider selects the appropriate VersionedComponent implementation
based on the current Minecraft version, handling the evolution of
the adventure api and its integration natively into paper.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull ItemMetaaddLoreLine(@NotNull ItemMeta meta, @NotNull VersionedComponent component) Add a single line to the lore of an item stack using aVersionedComponent.
If the item has no existing lore, creates a new lore list with this component.static @Nullable VersionedComponentgetDisplayName(@NotNull ItemMeta meta) Get the display name of an item stack as aVersionedComponent.
Returns null if the item has no custom display name.static @Nullable List<VersionedComponent> Get the lore of an item stack as a list ofVersionedComponents.
Returns null if the item has no lore.static @NotNull VersionedComponentSerializerMirror method tofor convenience.invalid reference
NmsAPI#getVersionedComponentSerializer()static @NotNull ItemMetasetDisplayName(@NotNull ItemMeta meta, @Nullable VersionedComponent component) Set the display name of an item stack using aVersionedComponent.
On older versions the component is serialized to legacy codes, while on newer versions it uses the native adventure api.static @NotNull ItemMetasetLore(@NotNull ItemMeta meta, @Nullable List<VersionedComponent> lore) Set the lore of an item stack using a list ofVersionedComponents.
On older versions the components are serialized to legacy codes, while on newer versions it uses the native adventure api.
-
Constructor Details
-
VersionedComponentUtil
public VersionedComponentUtil()
-
-
Method Details
-
serializer
Mirror method tofor convenience.invalid reference
NmsAPI#getVersionedComponentSerializer() -
setDisplayName
@NotNull public static @NotNull ItemMeta setDisplayName(@NotNull @NotNull ItemMeta meta, @Nullable @Nullable VersionedComponent component) Set the display name of an item stack using aVersionedComponent.
On older versions the component is serialized to legacy codes, while on newer versions it uses the native adventure api.- Returns:
- the same
ItemMetainstance (for chaining).
-
setLore
@NotNull public static @NotNull ItemMeta setLore(@NotNull @NotNull ItemMeta meta, @Nullable @Nullable List<VersionedComponent> lore) Set the lore of an item stack using a list ofVersionedComponents.
On older versions the components are serialized to legacy codes, while on newer versions it uses the native adventure api.- Parameters:
meta- the item meta to modifylore- the lore lines as versioned components, or null to remove lore- Returns:
- the same
ItemMetainstance (for chaining).
-
getLore
Get the lore of an item stack as a list ofVersionedComponents.
Returns null if the item has no lore.- Parameters:
meta- the item meta to read from- Returns:
- the lore lines as versioned components, or null if no lore
-
getDisplayName
@Nullable public static @Nullable VersionedComponent getDisplayName(@NotNull @NotNull ItemMeta meta) Get the display name of an item stack as aVersionedComponent.
Returns null if the item has no custom display name.- Parameters:
meta- the item meta to read from- Returns:
- the display name as a versioned component, or null if no custom name
-
addLoreLine
@NotNull public static @NotNull ItemMeta addLoreLine(@NotNull @NotNull ItemMeta meta, @NotNull @NotNull VersionedComponent component) Add a single line to the lore of an item stack using aVersionedComponent.
If the item has no existing lore, creates a new lore list with this component.- Parameters:
meta- the item meta to modifycomponent- the lore line to add- Returns:
- the same
ItemMetainstance (for chaining).
-