Skip to content

Commit 17ddb5c

Browse files
committed
don't use PaperNBTApplier on unsupported component types
1 parent 2417126 commit 17ddb5c

12 files changed

Lines changed: 22 additions & 11 deletions

File tree

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.github.projectunified</groupId>
88
<artifactId>craftitem</artifactId>
9-
<version>1.6.1</version>
9+
<version>1.6.2</version>
1010
</parent>
1111

1212
<artifactId>craftitem-core</artifactId>

modifier/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.github.projectunified</groupId>
88
<artifactId>craftitem</artifactId>
9-
<version>1.6.1</version>
9+
<version>1.6.2</version>
1010
</parent>
1111

1212
<artifactId>craftitem-modifier</artifactId>

nbt/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.github.projectunified</groupId>
88
<artifactId>craftitem</artifactId>
9-
<version>1.6.1</version>
9+
<version>1.6.2</version>
1010
</parent>
1111

1212
<artifactId>craftitem-nbt</artifactId>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.projectunified</groupId>
88
<artifactId>craftitem</artifactId>
9-
<version>1.6.1</version>
9+
<version>1.6.2</version>
1010
<packaging>pom</packaging>
1111

1212
<name>CraftItem</name>

spigot/core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.github.projectunified</groupId>
88
<artifactId>craftitem-spigot</artifactId>
9-
<version>1.6.1</version>
9+
<version>1.6.2</version>
1010
</parent>
1111

1212
<artifactId>craftitem-spigot-core</artifactId>

spigot/modifier/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.github.projectunified</groupId>
88
<artifactId>craftitem-spigot</artifactId>
9-
<version>1.6.1</version>
9+
<version>1.6.2</version>
1010
</parent>
1111

1212
<artifactId>craftitem-spigot-modifier</artifactId>

spigot/nbt/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.github.projectunified</groupId>
88
<artifactId>craftitem-spigot</artifactId>
9-
<version>1.6.1</version>
9+
<version>1.6.2</version>
1010
</parent>
1111

1212
<artifactId>craftitem-spigot-nbt</artifactId>

spigot/nbt/src/main/java/io/github/projectunified/craftitem/spigot/nbt/NBTModifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private void applyNBT(SpigotItem item, String nbtString, boolean useDataComponen
8484
if (useDataComponent) {
8585
ItemStack nbtItemStack = Bukkit.getItemFactory().createItemStack(nbtString);
8686
try {
87-
if (PaperNBTApplier.SUPPORTED) {
87+
if (PaperNBTApplier.SUPPORTED && PaperNBTApplier.hasAllSupportedComponentTypes(nbtItemStack)) {
8888
item.edit(itemStack -> PaperNBTApplier.mergeComponent(itemStack, nbtItemStack));
8989
return;
9090
}

spigot/nbt/src/main/java/io/github/projectunified/craftitem/spigot/nbt/PaperNBTApplier.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class PaperNBTApplier {
1515
Class.forName("io.papermc.paper.datacomponent.DataComponentType");
1616
Class.forName("io.papermc.paper.datacomponent.DataComponentType$Valued");
1717
Class.forName("io.papermc.paper.datacomponent.DataComponentType$NonValued");
18+
Class.forName("io.papermc.paper.datacomponent.PaperDataComponentType$Unimplemented");
1819

1920
Class<?> dataComponentHolderClass = Class.forName("io.papermc.paper.datacomponent.DataComponentHolder");
2021
supported = dataComponentHolderClass.isAssignableFrom(ItemStack.class);
@@ -24,6 +25,16 @@ class PaperNBTApplier {
2425
SUPPORTED = supported;
2526
}
2627

28+
@SuppressWarnings("UnstableApiUsage")
29+
static boolean hasAllSupportedComponentTypes(ItemStack referenceItem) {
30+
for (DataComponentType type : referenceItem.getDataTypes()) {
31+
if (!(type instanceof DataComponentType.Valued) && !(type instanceof DataComponentType.NonValued)) {
32+
return false;
33+
}
34+
}
35+
return true;
36+
}
37+
2738
@SuppressWarnings({"UnstableApiUsage", "unchecked"})
2839
static void mergeComponent(ItemStack currentItem, ItemStack referenceItem) {
2940
Material material = currentItem.getType();

spigot/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.github.projectunified</groupId>
88
<artifactId>craftitem</artifactId>
9-
<version>1.6.1</version>
9+
<version>1.6.2</version>
1010
</parent>
1111

1212
<artifactId>craftitem-spigot</artifactId>

0 commit comments

Comments
 (0)