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 componentB
- The builder type ofComponentWrapper
- 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 Summary
ConstructorsConstructorDescriptionComponentWrapper
(B builder) Constructs aComponentWrapper
that only references to a built component.ComponentWrapper
(ItemSource<?> itemSource) Constructs aComponentWrapper
with the givenItemSource
.ComponentWrapper
(org.bukkit.inventory.ItemStack itemStack) ComponentWrapper
(T component) Constructs aComponentWrapper
that only references to a component. -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyBuilder
(B builder) Apply a newbuilder
to theitemSource
.void
Apply the currentcomponent
to theitemSource
.void
applyComponent
(T component) Apply a newcomponent
orcomponent
to theitemSource
.abstract ComponentWrapper
<T, B> clone()
Returns a clone of thisComponentWrapper
.void
editBuilder
(Consumer<B> consumer) Edit theComponentWrapper
component of thisComponentWrapper
and have changes applied.boolean
Returns the builder of the current component If thisComponentWrapper
was constructed with anItemSource
, the builder is retrieved from the component of the stored item.protected abstract B
getBuilder
(org.bukkit.inventory.ItemStack itemStack) Returns theComponentWrapper
builder of the component fromitemStack
.protected abstract B
getBuilder
(T component) Convertcomponent
to a builder.Returns the current component.protected abstract T
getComponent
(org.bukkit.inventory.ItemStack itemStack) Returns theComponentWrapper
component fromitemStack
.abstract io.papermc.paper.datacomponent.DataComponentType.Valued
<T> Returns theDataComponentType
of thisComponentWrapper
.@Nullable ItemSource
<?> Returns theItemSource
theItemStack
is sourced from.@Nullable org.bukkit.inventory.ItemStack
Returns theItemStack
associated with thisComponentWrapper
, if available.abstract B
Returns a new builderComponentWrapper
.abstract T
Returns a new componentComponentWrapper
.abstract ComponentWrapper
<T, B> Returns a newComponentWrapper
.protected void
setBuilder
(org.bukkit.inventory.ItemStack itemStack, B builder) Sets theComponentWrapper
builder component onitemStack
.protected abstract void
setComponent
(org.bukkit.inventory.ItemStack itemStack, T component) Sets theComponentWrapper
component onitemStack
.toString()
-
Constructor Details
-
ComponentWrapper
public ComponentWrapper(org.bukkit.inventory.ItemStack itemStack) - Parameters:
itemStack
- The originalItemStack
.- See Also:
-
ComponentWrapper
Constructs aComponentWrapper
with the givenItemSource
. Ensures up-to-date component data retrieval and modification on theItemStack
of theItemSource
.- Parameters:
itemSource
- TheItemSource
representing the original source of theItemStack
.
-
ComponentWrapper
Constructs aComponentWrapper
that only references to a component. -
ComponentWrapper
Constructs aComponentWrapper
that only references to a built component.
-
-
Method Details
-
getComponent
Returns the current component. If thisComponentWrapper
was constructed with anItemSource
, the component is retrieved from the stored item. Otherwise, the storedcomponent
. -
getBuilder
Returns the builder of the current component If thisComponentWrapper
was constructed with anItemSource
, the builder is retrieved from the component of the stored item. Otherwise, the storedcomponent
. -
getItemStack
@Nullable public @Nullable org.bukkit.inventory.ItemStack getItemStack()Returns theItemStack
associated with thisComponentWrapper
, if available. -
getItemSource
Returns theItemSource
theItemStack
is sourced from. -
getDataComponentType
Returns theDataComponentType
of thisComponentWrapper
. -
getComponent
Returns theComponentWrapper
component fromitemStack
. -
getBuilder
Returns theComponentWrapper
builder of the component fromitemStack
. -
setComponent
Sets theComponentWrapper
component onitemStack
. -
setBuilder
Sets theComponentWrapper
builder component onitemStack
. -
applyComponent
public void applyComponent()Apply the currentcomponent
to theitemSource
. -
applyComponent
Apply a newcomponent
orcomponent
to theitemSource
. -
applyBuilder
Apply a newbuilder
to theitemSource
. -
editBuilder
Edit theComponentWrapper
component of thisComponentWrapper
and have changes applied. -
getBuilder
Convertcomponent
to a builder.- Parameters:
component
- The component.- Returns:
- The builder.
-
clone
Returns a clone of thisComponentWrapper
. -
newComponent
Returns a new componentComponentWrapper
. -
newBuilder
Returns a new builderComponentWrapper
. -
newWrapper
Returns a newComponentWrapper
. -
equals
-
toString
-