diff --git a/nms-patches/PlayerConnection.patch b/nms-patches/PlayerConnection.patch index caa5ed528d..a5db41fbfa 100644 --- a/nms-patches/PlayerConnection.patch +++ b/nms-patches/PlayerConnection.patch @@ -682,7 +682,7 @@ EnumInteractionResult enuminteractionresult = this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock); if (enumdirection == EnumDirection.UP && !enuminteractionresult.a() && blockposition.getY() >= this.minecraftServer.getMaxBuildHeight() - 1 && a(this.player, itemstack)) { -@@ -855,12 +1263,51 @@ +@@ -855,12 +1263,46 @@ @Override public void a(PacketPlayInBlockPlace packetplayinblockplace) { PlayerConnectionUtils.ensureMainThread(packetplayinblockplace, this, this.player.getWorldServer()); @@ -717,14 +717,9 @@ + org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack, enumhand); + cancelled = event.useItemInHand() == Event.Result.DENY; + } else { -+ if (player.playerInteractManager.firedInteract) { -+ player.playerInteractManager.firedInteract = false; -+ cancelled = player.playerInteractManager.interactResult; -+ } else { -+ MovingObjectPositionBlock movingobjectpositionblock = (MovingObjectPositionBlock) movingobjectposition; -+ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPosition(), movingobjectpositionblock.getDirection(), itemstack, true, enumhand); -+ cancelled = event.useItemInHand() == Event.Result.DENY; -+ } ++ MovingObjectPositionBlock movingobjectpositionblock = (MovingObjectPositionBlock) movingobjectposition; ++ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPosition(), movingobjectpositionblock.getDirection(), itemstack, true, enumhand); ++ cancelled = event.useItemInHand() == Event.Result.DENY; + } + + if (cancelled) { @@ -734,7 +729,7 @@ EnumInteractionResult enuminteractionresult = this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand); if (enuminteractionresult.b()) { -@@ -881,7 +1328,7 @@ +@@ -881,7 +1323,7 @@ Entity entity = packetplayinspectate.a(worldserver); if (entity != null) { @@ -743,7 +738,7 @@ return; } } -@@ -890,7 +1337,12 @@ +@@ -890,7 +1332,12 @@ } @Override @@ -757,7 +752,7 @@ @Override public void a(PacketPlayInBoatMove packetplayinboatmove) { -@@ -905,11 +1357,26 @@ +@@ -905,11 +1352,26 @@ @Override public void a(IChatBaseComponent ichatbasecomponent) { @@ -785,7 +780,7 @@ if (this.isExemptPlayer()) { PlayerConnection.LOGGER.info("Stopping singleplayer server as player logged out"); this.minecraftServer.safeShutdown(false); -@@ -935,6 +1402,15 @@ +@@ -935,6 +1397,15 @@ } } @@ -801,7 +796,7 @@ try { this.networkManager.sendPacket(packet, genericfuturelistener); } catch (Throwable throwable) { -@@ -951,7 +1427,16 @@ +@@ -951,7 +1422,16 @@ @Override public void a(PacketPlayInHeldItemSlot packetplayinhelditemslot) { PlayerConnectionUtils.ensureMainThread(packetplayinhelditemslot, this, this.player.getWorldServer()); @@ -818,7 +813,7 @@ if (this.player.inventory.itemInHandIndex != packetplayinhelditemslot.b() && this.player.getRaisedHand() == EnumHand.MAIN_HAND) { this.player.clearActiveItem(); } -@@ -960,13 +1445,24 @@ +@@ -960,13 +1440,24 @@ this.player.resetIdleTimer(); } else { PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getDisplayName().getString()); @@ -845,7 +840,7 @@ this.sendPacket(new PacketPlayOutChat((new ChatMessage("chat.cannotSend")).a(EnumChatFormat.RED), ChatMessageType.SYSTEM, SystemUtils.b)); } else { this.player.resetIdleTimer(); -@@ -974,41 +1470,254 @@ +@@ -974,41 +1465,254 @@ for (int i = 0; i < s.length(); ++i) { if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) { @@ -1107,7 +1102,7 @@ this.player.resetIdleTimer(); IJumpable ijumpable; -@@ -1066,6 +1775,7 @@ +@@ -1066,6 +1770,7 @@ @Override public void a(PacketPlayInUseEntity packetplayinuseentity) { PlayerConnectionUtils.ensureMainThread(packetplayinuseentity, this, this.player.getWorldServer()); @@ -1115,7 +1110,7 @@ WorldServer worldserver = this.player.getWorldServer(); Entity entity = packetplayinuseentity.a((World) worldserver); -@@ -1079,18 +1789,72 @@ +@@ -1079,18 +1784,72 @@ ItemStack itemstack = enumhand != null ? this.player.b(enumhand).cloneItemStack() : ItemStack.b; Optional optional = Optional.empty(); @@ -1189,7 +1184,7 @@ } if (optional.isPresent() && ((EnumInteractionResult) optional.get()).a()) { -@@ -1137,15 +1901,21 @@ +@@ -1137,15 +1896,21 @@ @Override public void a(PacketPlayInCloseWindow packetplayinclosewindow) { PlayerConnectionUtils.ensureMainThread(packetplayinclosewindow, this, this.player.getWorldServer()); @@ -1213,7 +1208,7 @@ NonNullList nonnulllist = NonNullList.a(); for (int i = 0; i < this.player.activeContainer.slots.size(); ++i) { -@@ -1154,8 +1924,274 @@ +@@ -1154,8 +1919,274 @@ this.player.a(this.player.activeContainer, nonnulllist); } else { @@ -1225,7 +1220,7 @@ + + InventoryView inventory = this.player.activeContainer.getBukkitView(); + SlotType type = inventory.getSlotType(packetplayinwindowclick.c()); -+ + + InventoryClickEvent event; + ClickType click = ClickType.UNKNOWN; + InventoryAction action = InventoryAction.UNKNOWN; @@ -1422,7 +1417,7 @@ + if (this.player.activeContainer != oldContainer) { + return; + } - ++ + switch (event.getResult()) { + case ALLOW: + case DEFAULT: @@ -1489,7 +1484,7 @@ if (ItemStack.matches(packetplayinwindowclick.f(), itemstack)) { this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.b(), packetplayinwindowclick.e(), true)); this.player.e = true; -@@ -1195,6 +2231,7 @@ +@@ -1195,6 +2226,7 @@ @Override public void a(PacketPlayInEnchantItem packetplayinenchantitem) { PlayerConnectionUtils.ensureMainThread(packetplayinenchantitem, this, this.player.getWorldServer()); @@ -1497,7 +1492,7 @@ this.player.resetIdleTimer(); if (this.player.activeContainer.windowId == packetplayinenchantitem.b() && this.player.activeContainer.c(this.player) && !this.player.isSpectator()) { this.player.activeContainer.a((EntityHuman) this.player, packetplayinenchantitem.c()); -@@ -1227,6 +2264,43 @@ +@@ -1227,6 +2259,43 @@ boolean flag1 = packetplayinsetcreativeslot.b() >= 1 && packetplayinsetcreativeslot.b() <= 45; boolean flag2 = itemstack.isEmpty() || itemstack.getDamage() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty(); @@ -1541,7 +1536,7 @@ if (flag1 && flag2) { if (itemstack.isEmpty()) { -@@ -1248,6 +2322,7 @@ +@@ -1248,6 +2317,7 @@ @Override public void a(PacketPlayInTransaction packetplayintransaction) { PlayerConnectionUtils.ensureMainThread(packetplayintransaction, this, this.player.getWorldServer()); @@ -1549,7 +1544,7 @@ int i = this.player.activeContainer.windowId; if (i == packetplayintransaction.b() && this.k.getOrDefault(i, (short) (packetplayintransaction.c() + 1)) == packetplayintransaction.c() && !this.player.activeContainer.c(this.player) && !this.player.isSpectator()) { -@@ -1259,6 +2334,7 @@ +@@ -1259,6 +2329,7 @@ @Override public void a(PacketPlayInUpdateSign packetplayinupdatesign) { PlayerConnectionUtils.ensureMainThread(packetplayinupdatesign, this, this.player.getWorldServer()); @@ -1557,7 +1552,7 @@ this.player.resetIdleTimer(); WorldServer worldserver = this.player.getWorldServer(); BlockPosition blockposition = packetplayinupdatesign.b(); -@@ -1275,14 +2351,30 @@ +@@ -1275,14 +2346,30 @@ if (!tileentitysign.d() || tileentitysign.f() != this.player) { PlayerConnection.LOGGER.warn("Player {} just tried to change non-editable sign", this.player.getDisplayName().getString()); @@ -1589,7 +1584,7 @@ tileentitysign.update(); worldserver.notify(blockposition, iblockdata, iblockdata, 3); -@@ -1292,6 +2384,7 @@ +@@ -1292,6 +2379,7 @@ @Override public void a(PacketPlayInKeepAlive packetplayinkeepalive) { @@ -1597,7 +1592,7 @@ if (this.awaitingKeepAlive && packetplayinkeepalive.b() == this.h) { int i = (int) (SystemUtils.getMonotonicMillis() - this.lastKeepAlive); -@@ -1306,7 +2399,17 @@ +@@ -1306,7 +2394,17 @@ @Override public void a(PacketPlayInAbilities packetplayinabilities) { PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.getWorldServer()); @@ -1616,7 +1611,7 @@ } @Override -@@ -1315,8 +2418,50 @@ +@@ -1315,8 +2413,50 @@ this.player.a(packetplayinsettings); } diff --git a/nms-patches/PlayerInteractManager.patch b/nms-patches/PlayerInteractManager.patch index 7b0c2090fe..634295b847 100644 --- a/nms-patches/PlayerInteractManager.patch +++ b/nms-patches/PlayerInteractManager.patch @@ -162,10 +162,10 @@ + if (nmsBlock != null && !event.isCancelled() && !this.isCreative() && this.player.hasBlock(nmsBlock.getBlockData())) { + event.setExpToDrop(nmsBlock.getExpDrop(nmsData, this.world, blockposition, itemstack)); + } ++ ++ this.world.getServer().getPluginManager().callEvent(event); - if (!this.player.getItemInMainHand().getItem().a(iblockdata, (World) this.world, blockposition, (EntityHuman) this.player)) { -+ this.world.getServer().getPluginManager().callEvent(event); -+ + if (event.isCancelled()) { + if (isSwordNoBreak) { + return false; @@ -243,13 +243,11 @@ } } } -@@ -287,12 +423,40 @@ +@@ -287,12 +423,37 @@ } } + // CraftBukkit start - whole method -+ public boolean interactResult = false; -+ public boolean firedInteract = false; public EnumInteractionResult a(EntityPlayer entityplayer, World world, ItemStack itemstack, EnumHand enumhand, MovingObjectPositionBlock movingobjectpositionblock) { BlockPosition blockposition = movingobjectpositionblock.getBlockPosition(); IBlockData iblockdata = world.getType(blockposition); @@ -266,8 +264,7 @@ + } + + PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(entityplayer, Action.RIGHT_CLICK_BLOCK, blockposition, movingobjectpositionblock.getDirection(), itemstack, cancelledBlock, enumhand); -+ firedInteract = true; -+ interactResult = event.useItemInHand() == Event.Result.DENY; ++ boolean interactResult = event.useItemInHand() == Event.Result.DENY; + + if (event.useInteractedBlock() == Event.Result.DENY) { + // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door. @@ -284,7 +281,7 @@ if (itileinventory != null) { entityplayer.openContainer(itileinventory); -@@ -306,7 +470,7 @@ +@@ -306,7 +467,7 @@ ItemStack itemstack1 = itemstack.cloneItemStack(); if (!flag1) { @@ -293,7 +290,7 @@ if (enuminteractionresult.a()) { CriterionTriggers.M.a(entityplayer, blockposition, itemstack1); -@@ -314,17 +478,17 @@ +@@ -314,17 +475,17 @@ } } @@ -314,7 +311,7 @@ } if (enuminteractionresult1.a()) { -@@ -332,10 +496,10 @@ +@@ -332,10 +493,10 @@ } return enuminteractionresult1;