Commits

md_5 authored 3ae3ea08f21
SPIGOT-1550, SPIGOT-2306: Custom payload / book + event fixes
No tags

nms-patches/PlayerConnection.patch

Modified
1590 1590 PlayerConnectionUtils.ensureMainThread(packetplayintabcomplete, this, this.player.x());
1591 1591 + // CraftBukkit start
1592 1592 + if (chatSpamField.addAndGet(this, 10) > 500 && !this.minecraftServer.getPlayerList().isOp(this.player.getProfile())) {
1593 1593 + this.disconnect("disconnect.spam");
1594 1594 + return;
1595 1595 + }
1596 1596 + // CraftBukkit end
1597 1597 ArrayList arraylist = Lists.newArrayList();
1598 1598 Iterator iterator = this.minecraftServer.tabCompleteCommand(this.player, packetplayintabcomplete.a(), packetplayintabcomplete.b(), packetplayintabcomplete.c()).iterator();
1599 1599
1600 -@@ -1334,12 +2409,34 @@
1601 - PlayerConnection.LOGGER.error("Couldn\'t pick item", exception7);
1600 +@@ -1040,10 +2115,13 @@
1601 + }
1602 +
1603 + if (itemstack.getItem() == Items.WRITABLE_BOOK && itemstack.getItem() == itemstack1.getItem()) {
1604 ++ itemstack1 = new ItemStack(Items.WRITABLE_BOOK); // CraftBukkit
1605 + itemstack1.a("pages", (NBTBase) itemstack.getTag().getList("pages", 8));
1606 ++ CraftEventFactory.handleEditBookEvent(player, itemstack1); // CraftBukkit
1607 + }
1608 + } catch (Exception exception) {
1609 + PlayerConnection.LOGGER.error("Couldn\'t handle book info", exception);
1610 ++ this.disconnect("Invalid book data!"); // CraftBukkit
1611 + }
1612 + } else {
1613 + String s1;
1614 +@@ -1067,6 +2145,7 @@
1615 + }
1616 +
1617 + if (itemstack.getItem() == Items.WRITABLE_BOOK && itemstack1.getItem() == Items.WRITABLE_BOOK) {
1618 ++ itemstack1 = new ItemStack(Items.WRITABLE_BOOK); // CraftBukkit
1619 + itemstack1.a("author", (NBTBase) (new NBTTagString(this.player.getName())));
1620 + itemstack1.a("title", (NBTBase) (new NBTTagString(itemstack.getTag().getString("title"))));
1621 + NBTTagList nbttaglist = itemstack.getTag().getList("pages", 8);
1622 +@@ -1081,9 +2160,11 @@
1623 +
1624 + itemstack1.a("pages", (NBTBase) nbttaglist);
1625 + itemstack1.setItem(Items.WRITTEN_BOOK);
1626 ++ CraftEventFactory.handleEditBookEvent(player, itemstack1); // CraftBukkit
1627 + }
1628 + } catch (Exception exception1) {
1629 + PlayerConnection.LOGGER.error("Couldn\'t sign book", exception1);
1630 ++ this.disconnect("Invalid book data!"); // CraftBukkit
1631 + }
1632 + } else if ("MC|TrSel".equals(s)) {
1633 + try {
1634 +@@ -1095,6 +2176,7 @@
1635 + }
1636 + } catch (Exception exception2) {
1637 + PlayerConnection.LOGGER.error("Couldn\'t select trade", exception2);
1638 ++ this.disconnect("Invalid trade data!"); // CraftBukkit
1639 + }
1640 + } else {
1641 + TileEntity tileentity;
1642 +@@ -1144,6 +2226,7 @@
1602 1643 }
1644 + } catch (Exception exception3) {
1645 + PlayerConnection.LOGGER.error("Couldn\'t set command block", exception3);
1646 ++ this.disconnect("Invalid command data!"); // CraftBukkit
1603 1647 }
1648 + } else if ("MC|AutoCmd".equals(s)) {
1649 + if (!this.minecraftServer.getEnableCommandBlock()) {
1650 +@@ -1211,6 +2294,7 @@
1651 + }
1652 + } catch (Exception exception4) {
1653 + PlayerConnection.LOGGER.error("Couldn\'t set command block", exception4);
1654 ++ this.disconnect("Invalid command data!"); // CraftBukkit
1655 + }
1656 + } else {
1657 + int k;
1658 +@@ -1234,6 +2318,7 @@
1659 + }
1660 + } catch (Exception exception5) {
1661 + PlayerConnection.LOGGER.error("Couldn\'t set beacon", exception5);
1662 ++ this.disconnect("Invalid beacon data!"); // CraftBukkit
1663 + }
1664 + }
1665 + } else if ("MC|ItemName".equals(s)) {
1666 +@@ -1320,6 +2405,7 @@
1667 + }
1668 + } catch (Exception exception6) {
1669 + PlayerConnection.LOGGER.error("Couldn\'t set structure block", exception6);
1670 ++ this.disconnect("Invalid structure data!"); // CraftBukkit
1671 + }
1672 + } else if ("MC|PickItem".equals(s)) {
1673 + packetdataserializer = packetplayincustompayload.b();
1674 +@@ -1332,14 +2418,37 @@
1675 + this.player.playerConnection.sendPacket(new PacketPlayOutHeldItemSlot(this.player.inventory.itemInHandIndex));
1676 + } catch (Exception exception7) {
1677 + PlayerConnection.LOGGER.error("Couldn\'t pick item", exception7);
1678 ++ this.disconnect("Invalid item data!"); // CraftBukkit
1679 ++ }
1680 ++ }
1604 1681 + // CraftBukkit start
1605 1682 + else if (packetplayincustompayload.a().equals("REGISTER")) {
1606 1683 + String channels = packetplayincustompayload.b().toString(com.google.common.base.Charsets.UTF_8);
1607 1684 + for (String channel : channels.split("\0")) {
1608 1685 + getPlayer().addChannel(channel);
1609 -+ }
1686 + }
1610 1687 + } else if (packetplayincustompayload.a().equals("UNREGISTER")) {
1611 1688 + String channels = packetplayincustompayload.b().toString(com.google.common.base.Charsets.UTF_8);
1612 1689 + for (String channel : channels.split("\0")) {
1613 1690 + getPlayer().removeChannel(channel);
1614 1691 + }
1615 1692 + } else {
1616 1693 + byte[] data = new byte[packetplayincustompayload.b().readableBytes()];
1617 1694 + packetplayincustompayload.b().readBytes(data);
1618 1695 + server.getMessenger().dispatchIncomingMessage(player.getBukkitEntity(), packetplayincustompayload.a(), data);
1619 -+ }
1696 + }
1620 1697 + // CraftBukkit end
1621 1698 }
1622 1699 }
1623 1700 }
1624 1701
1625 1702 }
1626 1703
1627 1704 + // CraftBukkit start - Add "isDisconnected" method
1628 1705 + public final boolean isDisconnected() {
1629 1706 + return !this.player.joining && !this.networkManager.isConnected();

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut