Class ComponentWrapper<T,B extends io.papermc.paper.datacomponent.DataComponentBuilder<T>>

java.lang.Object
org.skriptlang.skript.bukkit.itemcomponents.ComponentWrapper<T,B>
Type Parameters:
T - The type of component
B - The builder type of ComponentWrapper
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
EquippableWrapper

public abstract class ComponentWrapper<T,B extends io.papermc.paper.datacomponent.DataComponentBuilder<T>> extends Object implements Cloneable
A wrapper that allows access and modification of a specific component from an ItemStack or a stand-alone component.
  • Constructor Details

    • ComponentWrapper

      public ComponentWrapper(org.bukkit.inventory.ItemStack itemStack)
      Constructs a ComponentWrapper that wraps the given ItemStack in an ItemSource.
      Parameters:
      itemStack - The original ItemStack.
      See Also:
    • ComponentWrapper

      public ComponentWrapper(ItemSource<?> itemSource)
      Constructs a ComponentWrapper with the given ItemSource. Ensures up-to-date component data retrieval and modification on the ItemStack of the ItemSource .
      Parameters:
      itemSource - The ItemSource representing the original source of the ItemStack.
    • ComponentWrapper

      public ComponentWrapper(T component)
      Constructs a ComponentWrapper that only references to a component.
    • ComponentWrapper

      public ComponentWrapper(B builder)
      Constructs a ComponentWrapper that only references to a built component.
  • Method Details

    • getComponent

      public T getComponent()
      Returns the current component. If this ComponentWrapper was constructed with an ItemSource, the component is retrieved from the stored item. Otherwise, the stored component.
    • getBuilder

      public B getBuilder()
      Returns the builder of the current component If this ComponentWrapper was constructed with an ItemSource, the builder is retrieved from the component of the stored item. Otherwise, the stored component.
    • getItemStack

      @Nullable public @Nullable org.bukkit.inventory.ItemStack getItemStack()
      Returns the ItemStack associated with this ComponentWrapper, if available.
    • getItemSource

      @Nullable public @Nullable ItemSource<?> getItemSource()
      Returns the ItemSource the ItemStack is sourced from.
    • getDataComponentType

      public abstract io.papermc.paper.datacomponent.DataComponentType.Valued<T> getDataComponentType()
      Returns the DataComponentType of this ComponentWrapper.
    • getComponent

      protected abstract T getComponent(org.bukkit.inventory.ItemStack itemStack)
      Returns the ComponentWrapper component from itemStack.
    • getBuilder

      protected abstract B getBuilder(org.bukkit.inventory.ItemStack itemStack)
      Returns the ComponentWrapper builder of the component from itemStack.
    • setComponent

      protected abstract void setComponent(org.bukkit.inventory.ItemStack itemStack, T component)
      Sets the ComponentWrapper component on itemStack.
    • setBuilder

      protected void setBuilder(org.bukkit.inventory.ItemStack itemStack, B builder)
      Sets the ComponentWrapper builder component on itemStack.
    • applyComponent

      public void applyComponent()
      Apply the current component to the itemSource.
    • applyComponent

      public void applyComponent(@NotNull T component)
      Apply a new component or component to the itemSource.
    • applyBuilder

      public void applyBuilder(@NotNull B builder)
      Apply a new builder to the itemSource.
    • editBuilder

      public void editBuilder(Consumer<B> consumer)
      Edit the ComponentWrapper component of this ComponentWrapper and have changes applied.
    • getBuilder

      protected abstract B getBuilder(T component)
      Convert component to a builder.
      Parameters:
      component - The component.
      Returns:
      The builder.
    • clone

      public abstract ComponentWrapper<T,B> clone()
      Returns a clone of this ComponentWrapper.
      Overrides:
      clone in class Object
    • newComponent

      public abstract T newComponent()
      Returns a new component ComponentWrapper.
    • newBuilder

      public abstract B newBuilder()
      Returns a new builder ComponentWrapper.
    • newWrapper

      public abstract ComponentWrapper<T,B> newWrapper()
      Returns a new ComponentWrapper.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object