From 3ae3ea08f210b013a5746143c55deb06cfff5514 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 11 Jun 2016 12:17:35 +1000 Subject: [PATCH] SPIGOT-1550, SPIGOT-2306: Custom payload / book + event fixes --- nms-patches/PlayerConnection.patch | 87 ++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 5 deletions(-) diff --git a/nms-patches/PlayerConnection.patch b/nms-patches/PlayerConnection.patch index 627b84a41e..dcfc048029 100644 --- a/nms-patches/PlayerConnection.patch +++ b/nms-patches/PlayerConnection.patch @@ -1597,16 +1597,93 @@ ArrayList arraylist = Lists.newArrayList(); Iterator iterator = this.minecraftServer.tabCompleteCommand(this.player, packetplayintabcomplete.a(), packetplayintabcomplete.b(), packetplayintabcomplete.c()).iterator(); -@@ -1334,12 +2409,34 @@ - PlayerConnection.LOGGER.error("Couldn\'t pick item", exception7); - } +@@ -1040,10 +2115,13 @@ + } + + if (itemstack.getItem() == Items.WRITABLE_BOOK && itemstack.getItem() == itemstack1.getItem()) { ++ itemstack1 = new ItemStack(Items.WRITABLE_BOOK); // CraftBukkit + itemstack1.a("pages", (NBTBase) itemstack.getTag().getList("pages", 8)); ++ CraftEventFactory.handleEditBookEvent(player, itemstack1); // CraftBukkit + } + } catch (Exception exception) { + PlayerConnection.LOGGER.error("Couldn\'t handle book info", exception); ++ this.disconnect("Invalid book data!"); // CraftBukkit + } + } else { + String s1; +@@ -1067,6 +2145,7 @@ } + + if (itemstack.getItem() == Items.WRITABLE_BOOK && itemstack1.getItem() == Items.WRITABLE_BOOK) { ++ itemstack1 = new ItemStack(Items.WRITABLE_BOOK); // CraftBukkit + itemstack1.a("author", (NBTBase) (new NBTTagString(this.player.getName()))); + itemstack1.a("title", (NBTBase) (new NBTTagString(itemstack.getTag().getString("title")))); + NBTTagList nbttaglist = itemstack.getTag().getList("pages", 8); +@@ -1081,9 +2160,11 @@ + + itemstack1.a("pages", (NBTBase) nbttaglist); + itemstack1.setItem(Items.WRITTEN_BOOK); ++ CraftEventFactory.handleEditBookEvent(player, itemstack1); // CraftBukkit + } + } catch (Exception exception1) { + PlayerConnection.LOGGER.error("Couldn\'t sign book", exception1); ++ this.disconnect("Invalid book data!"); // CraftBukkit + } + } else if ("MC|TrSel".equals(s)) { + try { +@@ -1095,6 +2176,7 @@ + } + } catch (Exception exception2) { + PlayerConnection.LOGGER.error("Couldn\'t select trade", exception2); ++ this.disconnect("Invalid trade data!"); // CraftBukkit + } + } else { + TileEntity tileentity; +@@ -1144,6 +2226,7 @@ + } + } catch (Exception exception3) { + PlayerConnection.LOGGER.error("Couldn\'t set command block", exception3); ++ this.disconnect("Invalid command data!"); // CraftBukkit + } + } else if ("MC|AutoCmd".equals(s)) { + if (!this.minecraftServer.getEnableCommandBlock()) { +@@ -1211,6 +2294,7 @@ + } + } catch (Exception exception4) { + PlayerConnection.LOGGER.error("Couldn\'t set command block", exception4); ++ this.disconnect("Invalid command data!"); // CraftBukkit + } + } else { + int k; +@@ -1234,6 +2318,7 @@ + } + } catch (Exception exception5) { + PlayerConnection.LOGGER.error("Couldn\'t set beacon", exception5); ++ this.disconnect("Invalid beacon data!"); // CraftBukkit + } + } + } else if ("MC|ItemName".equals(s)) { +@@ -1320,6 +2405,7 @@ + } + } catch (Exception exception6) { + PlayerConnection.LOGGER.error("Couldn\'t set structure block", exception6); ++ this.disconnect("Invalid structure data!"); // CraftBukkit + } + } else if ("MC|PickItem".equals(s)) { + packetdataserializer = packetplayincustompayload.b(); +@@ -1332,14 +2418,37 @@ + this.player.playerConnection.sendPacket(new PacketPlayOutHeldItemSlot(this.player.inventory.itemInHandIndex)); + } catch (Exception exception7) { + PlayerConnection.LOGGER.error("Couldn\'t pick item", exception7); ++ this.disconnect("Invalid item data!"); // CraftBukkit ++ } ++ } + // CraftBukkit start + else if (packetplayincustompayload.a().equals("REGISTER")) { + String channels = packetplayincustompayload.b().toString(com.google.common.base.Charsets.UTF_8); + for (String channel : channels.split("\0")) { + getPlayer().addChannel(channel); -+ } + } + } else if (packetplayincustompayload.a().equals("UNREGISTER")) { + String channels = packetplayincustompayload.b().toString(com.google.common.base.Charsets.UTF_8); + for (String channel : channels.split("\0")) { @@ -1616,7 +1693,7 @@ + byte[] data = new byte[packetplayincustompayload.b().readableBytes()]; + packetplayincustompayload.b().readBytes(data); + server.getMessenger().dispatchIncomingMessage(player.getBukkitEntity(), packetplayincustompayload.a(), data); -+ } + } + // CraftBukkit end } }