summaryrefslogtreecommitdiffstats
path: root/nms-patches/PacketDataSerializer.patch
blob: d257ef48f1ed08aebffb36829b709493997c0446 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
--- a/net/minecraft/server/PacketDataSerializer.java
+++ b/net/minecraft/server/PacketDataSerializer.java
@@ -21,6 +21,8 @@
 import java.util.UUID;
 import javax.annotation.Nullable;
 
+import org.bukkit.craftbukkit.inventory.CraftItemStack; // CraftBukkit
+
 public class PacketDataSerializer extends ByteBuf {
 
     private final ByteBuf a;
@@ -128,7 +130,7 @@
     }
 
     public <T extends Enum<T>> T a(Class<T> oclass) {
-        return ((Enum[]) oclass.getEnumConstants())[this.g()];
+        return ((T[]) oclass.getEnumConstants())[this.g()]; // CraftBukkit - fix decompile error
     }
 
     public PacketDataSerializer a(Enum<?> oenum) {
@@ -205,7 +207,7 @@
         } else {
             try {
                 NBTCompressedStreamTools.a(nbttagcompound, (DataOutput) (new ByteBufOutputStream(this)));
-            } catch (IOException ioexception) {
+            } catch (Exception ioexception) { // CraftBukkit - IOException -> Exception
                 throw new EncoderException(ioexception);
             }
         }
@@ -232,7 +234,7 @@
     }
 
     public PacketDataSerializer a(ItemStack itemstack) {
-        if (itemstack.isEmpty()) {
+        if (itemstack.isEmpty() || itemstack.getItem() == null) { // CraftBukkit - NPE fix itemstack.getItem()
             this.writeShort(-1);
         } else {
             this.writeShort(Item.getId(itemstack.getItem()));
@@ -261,6 +263,11 @@
             ItemStack itemstack = new ItemStack(Item.getById(short0), b0, short1);
 
             itemstack.setTag(this.j());
+            // CraftBukkit start
+            if (itemstack.getTag() != null) {
+                CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack));
+            }
+            // CraftBukkit end
             return itemstack;
         }
     }