Skip to content

Commit

Permalink
Fixes #1244 - [de]serializeItem to/from byte[] should include amount (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ens-gijs authored Jan 10, 2025
1 parent 2bf1918 commit ae2190c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -296,6 +297,7 @@ public byte[] serializeItem(ItemStack item)
final ByteArrayOutputStream bao = new ByteArrayOutputStream();
try
{
bao.write(ByteBuffer.allocate(4).putInt(item.getAmount()).array());
final ObjectOutputStream oos = new BukkitObjectOutputStreamMock(bao);
oos.writeObject(item);
return bao.toByteArray();
Expand All @@ -314,8 +316,11 @@ public ItemStack deserializeItem(byte[] data)
final ByteArrayInputStream bai = new ByteArrayInputStream(data);
try
{
int amount = ByteBuffer.wrap(bai.readNBytes(4)).getInt();
final ObjectInputStream ois = new BukkitObjectInputStreamMock(bai);
return (ItemStackMock) ois.readObject();
ItemStackMock stack = (ItemStackMock) ois.readObject();
stack.setAmount(amount);
return stack;
}
catch (IOException | ClassNotFoundException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static Stream<Arguments> provideTestItems() throws IOException
{
continue;
}
ItemStack item = new ItemStackMock(material);
ItemStack item = new ItemStackMock(material, 10);
args.add(Arguments.of(Named.of(material.name(), item)));
}
ItemStack item = new ItemStackMock(Material.STONE);
Expand Down

0 comments on commit ae2190c

Please sign in to comment.