mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
165 lines
10 KiB
Diff
165 lines
10 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Sat, 27 Apr 2024 20:56:17 -0700
|
|
Subject: [PATCH] General ItemMeta fixes
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
@@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack {
|
|
// Paper end - improve handled tags on type change
|
|
// Paper start
|
|
public static void applyMetaToItem(net.minecraft.world.item.ItemStack itemStack, ItemMeta itemMeta) {
|
|
- final CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator();
|
|
+ // Paper start - support updating profile after resolving it
|
|
+ final CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator() {
|
|
+ @Override
|
|
+ void skullCallback(final com.mojang.authlib.GameProfile gameProfile) {
|
|
+ itemStack.set(DataComponents.PROFILE, new net.minecraft.world.item.component.ResolvableProfile(gameProfile));
|
|
+ }
|
|
+ };
|
|
+ // Paper end - support updating profile after resolving it
|
|
((CraftMetaItem) itemMeta).applyToItem(tag);
|
|
itemStack.applyComponents(tag.build());
|
|
}
|
|
@@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack {
|
|
}
|
|
|
|
if (!((CraftMetaItem) itemMeta).isEmpty()) {
|
|
- CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator();
|
|
+ // Paper start - support updating profile after resolving it
|
|
+ CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator() {
|
|
+ @Override
|
|
+ void skullCallback(final com.mojang.authlib.GameProfile gameProfile) {
|
|
+ item.set(DataComponents.PROFILE, new net.minecraft.world.item.component.ResolvableProfile(gameProfile));
|
|
+ }
|
|
+ };
|
|
+ // Paper end - support updating profile after resolving it
|
|
|
|
((CraftMetaItem) itemMeta).applyToItem(tag);
|
|
item.restorePatch(tag.build());
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
|
|
@@ -0,0 +0,0 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta {
|
|
void applyToItem(CraftMetaItem.Applicator tag) {
|
|
super.applyToItem(tag);
|
|
|
|
+ if (this.patterns.isEmpty()) return; // Paper - don't write empty patterns
|
|
List<BannerPatternLayers.Layer> newPatterns = new ArrayList<>();
|
|
|
|
for (Pattern p : this.patterns) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
|
|
@@ -0,0 +0,0 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta {
|
|
for (Component page : this.pages) {
|
|
list.add(Filterable.passThrough(page));
|
|
}
|
|
- itemData.put(CraftMetaBookSigned.BOOK_CONTENT, new WrittenBookContent(Filterable.from(FilteredText.passThrough(this.title)), this.author, this.generation, list, this.resolved));
|
|
+ itemData.put(CraftMetaBookSigned.BOOK_CONTENT, new WrittenBookContent(Filterable.from(FilteredText.passThrough(this.title == null ? "" : this.title)), this.author == null ? "" : this.author, this.generation, list, this.resolved));
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java
|
|
@@ -0,0 +0,0 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
|
|
}
|
|
|
|
List<FireworkExplosion> effects = new ArrayList<>();
|
|
- for (FireworkEffect effect : this.effects) {
|
|
- effects.add(CraftMetaFirework.getExplosion(effect));
|
|
+ // Paper start - fix NPE with effects list being null
|
|
+ if (this.effects != null) {
|
|
+ for (FireworkEffect effect : this.effects) {
|
|
+ effects.add(CraftMetaFirework.getExplosion(effect));
|
|
+ }
|
|
}
|
|
+ // Paper end
|
|
|
|
itemTag.put(CraftMetaFirework.FIREWORKS, new Fireworks(this.power, effects));
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
}
|
|
}
|
|
|
|
- static final class Applicator {
|
|
+ static abstract class Applicator { // Paper - support updating profile after resolving it
|
|
|
|
final DataComponentPatch.Builder builder = DataComponentPatch.builder();
|
|
+ void skullCallback(com.mojang.authlib.GameProfile gameProfile) {} // Paper - support updating profile after resolving it
|
|
|
|
<T> Applicator put(ItemMetaKeyType<T> key, T value) {
|
|
this.builder.set(key.TYPE, value);
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
|
|
@Override
|
|
public String getAsString() {
|
|
- CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator();
|
|
+ CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator() {}; // Paper - support updating profile after resolving it
|
|
this.applyToItem(tag);
|
|
DataComponentPatch patch = tag.build();
|
|
Tag nbt = DataComponentPatch.CODEC.encodeStart(MinecraftServer.getDefaultRegistryAccess().createSerializationContext(NbtOps.INSTANCE), patch).getOrThrow();
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
|
|
@@ -0,0 +0,0 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
|
|
// Fill in textures
|
|
PlayerProfile ownerProfile = new CraftPlayerProfile(this.profile); // getOwnerProfile may return null
|
|
if (ownerProfile.getTextures().isEmpty()) {
|
|
- ownerProfile.update().thenAccept((filledProfile) -> {
|
|
+ ownerProfile.update().thenAcceptAsync((filledProfile) -> { // Paper - run on main thread
|
|
this.setOwnerProfile(filledProfile);
|
|
- tag.put(CraftMetaSkull.SKULL_PROFILE, new ResolvableProfile(this.profile));
|
|
- });
|
|
+ tag.skullCallback(this.profile); // Paper - actually set profile on itemstack
|
|
+ }, ((org.bukkit.craftbukkit.CraftServer) org.bukkit.Bukkit.getServer()).getServer()); // Paper - run on main thread
|
|
}
|
|
}
|
|
|
|
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java
|
|
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java
|
|
@@ -0,0 +0,0 @@ public class DeprecatedItemMetaCustomValueTest extends AbstractTestingBase {
|
|
public void testNBTTagStoring() {
|
|
CraftMetaItem itemMeta = this.createComplexItemMeta();
|
|
|
|
- CraftMetaItem.Applicator compound = new CraftMetaItem.Applicator();
|
|
+ CraftMetaItem.Applicator compound = new CraftMetaItem.Applicator() {}; // Paper
|
|
itemMeta.applyToItem(compound);
|
|
|
|
assertEquals(itemMeta, new CraftMetaItem(compound.build(), null)); // Paper
|
|
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java
|
|
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java
|
|
@@ -0,0 +0,0 @@ public class PersistentDataContainerTest extends AbstractTestingBase {
|
|
public void testNBTTagStoring() {
|
|
CraftMetaItem itemMeta = this.createComplexItemMeta();
|
|
|
|
- CraftMetaItem.Applicator compound = new CraftMetaItem.Applicator();
|
|
+ CraftMetaItem.Applicator compound = new CraftMetaItem.Applicator() {}; // Paper
|
|
itemMeta.applyToItem(compound);
|
|
|
|
assertEquals(itemMeta, new CraftMetaItem(compound.build(), null)); // Paper
|
|
@@ -0,0 +0,0 @@ public class PersistentDataContainerTest extends AbstractTestingBase {
|
|
assertEquals(List.of(), container.get(PersistentDataContainerTest.requestKey("list"), PersistentDataType.LIST.strings()));
|
|
|
|
// Write and read the entire container to NBT
|
|
- final CraftMetaItem.Applicator storage = new CraftMetaItem.Applicator();
|
|
+ final CraftMetaItem.Applicator storage = new CraftMetaItem.Applicator() {}; // Paper
|
|
craftItem.applyToItem(storage);
|
|
|
|
final CraftMetaItem readItem = new CraftMetaItem(storage.build(), null); // Paper
|