From 44dd60ac27b4d48f612a4290f8bb4e7cc71b3003 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Fri, 26 May 2017 20:20:59 -0700 Subject: SPIGOT-3272: Fix duplicate creative inventory This change properly identifies the creative inventory as one with 5 crafting slots (as that's the default set in ContainerPlayer, and handled properly in other containers), instead of having the same inventory twice (which breaks slot identification). --- nms-patches/PlayerConnection.patch | 31 +++++++++++----------- .../craftbukkit/inventory/CraftInventoryView.java | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/nms-patches/PlayerConnection.patch b/nms-patches/PlayerConnection.patch index e0d19a92..ee45a75d 100644 --- a/nms-patches/PlayerConnection.patch +++ b/nms-patches/PlayerConnection.patch @@ -1421,7 +1421,7 @@ this.player.resetIdleTimer(); if (this.player.activeContainer.windowId == packetplayinenchantitem.a() && this.player.activeContainer.c(this.player) && !this.player.isSpectator()) { this.player.activeContainer.a(this.player, packetplayinenchantitem.b()); -@@ -993,7 +2001,46 @@ +@@ -993,7 +2001,45 @@ } boolean flag1 = packetplayinsetcreativeslot.a() >= 1 && packetplayinsetcreativeslot.a() <= 45; @@ -1430,8 +1430,7 @@ + boolean flag2 = itemstack.isEmpty() || itemstack.getData() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty() && !invalidItems.contains(Item.getId(itemstack.getItem())); + if (flag || (flag1 && !ItemStack.matches(this.player.defaultContainer.getSlot(packetplayinsetcreativeslot.a()).getItem(), packetplayinsetcreativeslot.getItemStack()))) { // Insist on valid slot + // CraftBukkit start - Call click event -+ org.bukkit.entity.HumanEntity player = this.player.getBukkitEntity(); -+ InventoryView inventory = new CraftInventoryView(player, player.getInventory(), this.player.defaultContainer); ++ InventoryView inventory = this.player.defaultContainer.getBukkitView(); + org.bukkit.inventory.ItemStack item = CraftItemStack.asBukkitCopy(packetplayinsetcreativeslot.getItemStack()); + + SlotType type = SlotType.QUICKBAR; @@ -1469,7 +1468,7 @@ if (flag1 && flag2) { if (itemstack.isEmpty()) { -@@ -1017,6 +2064,7 @@ +@@ -1017,6 +2063,7 @@ public void a(PacketPlayInTransaction packetplayintransaction) { PlayerConnectionUtils.ensureMainThread(packetplayintransaction, this, this.player.x()); @@ -1477,7 +1476,7 @@ Short oshort = (Short) this.k.get(this.player.activeContainer.windowId); if (oshort != null && packetplayintransaction.b() == oshort.shortValue() && this.player.activeContainer.windowId == packetplayintransaction.a() && !this.player.activeContainer.c(this.player) && !this.player.isSpectator()) { -@@ -1027,6 +2075,7 @@ +@@ -1027,6 +2074,7 @@ public void a(PacketPlayInUpdateSign packetplayinupdatesign) { PlayerConnectionUtils.ensureMainThread(packetplayinupdatesign, this, this.player.x()); @@ -1485,7 +1484,7 @@ this.player.resetIdleTimer(); WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension); BlockPosition blockposition = packetplayinupdatesign.a(); -@@ -1043,14 +2092,30 @@ +@@ -1043,14 +2091,30 @@ if (!tileentitysign.a() || tileentitysign.e() != this.player) { this.minecraftServer.warning("Player " + this.player.getName() + " just tried to change non-editable sign"); @@ -1517,7 +1516,7 @@ tileentitysign.update(); worldserver.notify(blockposition, iblockdata, iblockdata, 3); -@@ -1073,11 +2138,27 @@ +@@ -1073,11 +2137,27 @@ public void a(PacketPlayInAbilities packetplayinabilities) { PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.x()); @@ -1546,7 +1545,7 @@ ArrayList arraylist = Lists.newArrayList(); Iterator iterator = this.minecraftServer.tabCompleteCommand(this.player, packetplayintabcomplete.a(), packetplayintabcomplete.b(), packetplayintabcomplete.c()).iterator(); -@@ -1103,6 +2184,13 @@ +@@ -1103,6 +2183,13 @@ ItemStack itemstack1; if ("MC|BEdit".equals(s)) { @@ -1560,7 +1559,7 @@ packetdataserializer = packetplayincustompayload.b(); try { -@@ -1121,15 +2209,25 @@ +@@ -1121,15 +2208,25 @@ } if (itemstack.getItem() == Items.WRITABLE_BOOK && itemstack.getItem() == itemstack1.getItem()) { @@ -1586,7 +1585,7 @@ packetdataserializer = packetplayincustompayload.b(); try { -@@ -1163,10 +2261,11 @@ +@@ -1163,10 +2260,11 @@ } itemstack2.a("pages", (NBTBase) nbttaglist); @@ -1599,7 +1598,7 @@ } } else if ("MC|TrSel".equals(s)) { try { -@@ -1178,6 +2277,7 @@ +@@ -1178,6 +2276,7 @@ } } catch (Exception exception2) { PlayerConnection.LOGGER.error("Couldn\'t select trade", exception2); @@ -1607,7 +1606,7 @@ } } else { TileEntity tileentity; -@@ -1227,6 +2327,7 @@ +@@ -1227,6 +2326,7 @@ } } catch (Exception exception3) { PlayerConnection.LOGGER.error("Couldn\'t set command block", exception3); @@ -1615,7 +1614,7 @@ } } else if ("MC|AutoCmd".equals(s)) { if (!this.minecraftServer.getEnableCommandBlock()) { -@@ -1294,6 +2395,7 @@ +@@ -1294,6 +2394,7 @@ } } catch (Exception exception4) { PlayerConnection.LOGGER.error("Couldn\'t set command block", exception4); @@ -1623,7 +1622,7 @@ } } else { int k; -@@ -1317,6 +2419,7 @@ +@@ -1317,6 +2418,7 @@ } } catch (Exception exception5) { PlayerConnection.LOGGER.error("Couldn\'t set beacon", exception5); @@ -1631,7 +1630,7 @@ } } } else if ("MC|ItemName".equals(s)) { -@@ -1403,6 +2506,7 @@ +@@ -1403,6 +2505,7 @@ } } catch (Exception exception6) { PlayerConnection.LOGGER.error("Couldn\'t set structure block", exception6); @@ -1639,7 +1638,7 @@ } } else if ("MC|PickItem".equals(s)) { packetdataserializer = packetplayincustompayload.b(); -@@ -1415,11 +2519,49 @@ +@@ -1415,11 +2518,49 @@ this.player.playerConnection.sendPacket(new PacketPlayOutHeldItemSlot(this.player.inventory.itemInHandIndex)); } catch (Exception exception7) { PlayerConnection.LOGGER.error("Couldn\'t pick item", exception7); diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java index b6c2f73e..8ca0ccc5 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java @@ -127,7 +127,7 @@ public class CraftInventoryView extends InventoryView { } else { if (slot == -999 || slot == -1) { type = SlotType.OUTSIDE; - } else if (inventory.getType() == InventoryType.CRAFTING) { + } else if (inventory.getType() == InventoryType.CRAFTING) { // Also includes creative inventory if (slot < 9) { type = SlotType.ARMOR; } else if (slot > 35) { -- cgit v1.2.3