3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00
Paper/nms-patches/PacketDataSerializer.patch

69 Zeilen
2.3 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/PacketDataSerializer.java
+++ b/net/minecraft/server/PacketDataSerializer.java
2016-02-29 22:32:46 +01:00
@@ -20,6 +20,8 @@
import java.nio.charset.Charset;
import java.util.UUID;
+import org.bukkit.craftbukkit.inventory.CraftItemStack; // CraftBukkit
+
public class PacketDataSerializer extends ByteBuf {
private final ByteBuf a;
2016-03-28 22:19:05 +02:00
@@ -44,8 +46,16 @@
return this;
}
+ // CraftBukkit start - limit length
public byte[] a() {
- byte[] abyte = new byte[this.g()];
+ return readByteArray(Short.MAX_VALUE);
+ }
+
+ public byte[] readByteArray(int limit) {
+ int len = this.g();
+ if (len > limit) throw new DecoderException("The received a byte array longer than allowed " + len + " > " + limit);
+ byte[] abyte = new byte[len];
+ // CraftBukkit end
this.readBytes(abyte);
return abyte;
@@ -99,7 +109,7 @@
2015-02-26 23:41:06 +01:00
}
public <T extends Enum<T>> T a(Class<T> oclass) {
2016-02-29 22:32:46 +01:00
- return ((Enum[]) oclass.getEnumConstants())[this.g()];
+ return ((T[]) oclass.getEnumConstants())[this.g()]; // CraftBukkit - fix decompile error
2015-02-26 23:41:06 +01:00
}
2016-02-29 22:32:46 +01:00
public PacketDataSerializer a(Enum<?> oenum) {
2016-03-28 22:19:05 +02:00
@@ -176,7 +186,7 @@
} else {
try {
NBTCompressedStreamTools.a(nbttagcompound, (DataOutput) (new ByteBufOutputStream(this)));
- } catch (IOException ioexception) {
+ } catch (Exception ioexception) { // CraftBukkit - IOException -> Exception
throw new EncoderException(ioexception);
}
}
2016-03-28 22:19:05 +02:00
@@ -202,7 +212,7 @@
}
2016-02-29 22:32:46 +01:00
public PacketDataSerializer a(ItemStack itemstack) {
- if (itemstack == null) {
+ if (itemstack == null || itemstack.getItem() == null) { // CraftBukkit - NPE fix itemstack.getItem()
this.writeShort(-1);
} else {
this.writeShort(Item.getId(itemstack.getItem()));
2016-03-28 22:19:05 +02:00
@@ -230,6 +240,11 @@
itemstack = new ItemStack(Item.getById(short0), b0, short1);
2016-02-29 22:32:46 +01:00
itemstack.setTag(this.j());
+ // CraftBukkit start
+ if (itemstack.getTag() != null) {
+ CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack));
+ }
+ // CraftBukkit end
}
return itemstack;