Skip to content

Commit

Permalink
Fix really stupid edge case of writeCompound
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Oct 22, 2024
1 parent 4cd1186 commit 243a5c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public static Object getCraftItemHandle(ItemStack item) {
public static void writeApiNBT(NBTCompound comp, OutputStream stream) {
try {
Object workingtag = comp.getResolvedObject();
if(workingtag == null) {
workingtag = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance();
}
ReflectionMethod.NBTFILE_WRITE.run(null, workingtag, stream);
} catch (Exception e) {
throw new NbtApiException("Exception while writing NBT!", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NBTContainer;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.nbtapi.plugin.tests.Test;
Expand All @@ -21,6 +25,11 @@ public void test() throws Exception {
if (!container.toString().equals(base.getOrCreateCompound("sub").toString())) {
throw new NbtApiException("Component content did not match! " + base.getCompound("sub") + " " + container);
}
ItemStack item = new ItemStack(Material.STICK);

NBT.modify(item, nbt -> {
nbt.writeCompound(outStream);
});
}

}

0 comments on commit 243a5c2

Please sign in to comment.