From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Sun, 11 Feb 2018 10:43:46 +0000 Subject: [PATCH] Extend Player Interact cancellation GUIs are opened on the client, meaning that the server cannot block them from opening, However, it is possible to close these GUIs from the server. Flower pots are also not updated on the client when interaction is cancelled, this patch also resolves this. Update adjacent blocks of doors, double plants, pistons and beds when cancelling interaction. diff --git a/src/main/java/net/minecraft/server/PlayerInteractManager.java b/src/main/java/net/minecraft/server/PlayerInteractManager.java index ee59d76d31b8b8cfd39d612b1e6040891f2256f4..36cf4c332054a350ae193637f895a45a8b04da9b 100644 --- a/src/main/java/net/minecraft/server/PlayerInteractManager.java +++ b/src/main/java/net/minecraft/server/PlayerInteractManager.java @@ -148,6 +148,11 @@ public class PlayerInteractManager { PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, blockposition, enumdirection, this.player.inventory.getItemInHand(), EnumHand.MAIN_HAND); if (event.isCancelled()) { // Let the client know the block still exists + // Paper start - brute force neighbor blocks for any attached blocks + for (EnumDirection dir : EnumDirection.values()) { + this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(world, blockposition.shift(dir))); + } + // Paper end this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(this.world, blockposition)); // Update any tile entity data for this block TileEntity tileentity = this.world.getTileEntity(blockposition); @@ -446,13 +451,32 @@ public class PlayerInteractManager { 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. if (iblockdata.getBlock() instanceof BlockDoor) { boolean bottom = iblockdata.get(BlockDoor.HALF) == BlockPropertyDoubleBlockHalf.LOWER; entityplayer.playerConnection.sendPacket(new PacketPlayOutBlockChange(world, bottom ? blockposition.up() : blockposition.down())); } else if (iblockdata.getBlock() instanceof BlockCake) { entityplayer.getBukkitEntity().sendHealthUpdate(); // SPIGOT-1341 - reset health for cake + // Paper start - extend Player Interact cancellation // TODO: consider merging this into the extracted method + } else if (iblockdata.getBlock() instanceof BlockStructure) { + entityplayer.playerConnection.sendPacket(new PacketPlayOutCloseWindow()); + } else if (iblockdata.getBlock() instanceof BlockCommand) { + entityplayer.playerConnection.sendPacket(new PacketPlayOutCloseWindow()); + } else if (iblockdata.getBlock() instanceof BlockFlowerPot) { + // Send a block change to air and then send back the correct block, just to make the client happy + PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(this.world, blockposition); + packet.block = Blocks.AIR.getBlockData(); + this.player.playerConnection.sendPacket(packet); + + this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(this.world, blockposition)); + + TileEntity tileentity = this.world.getTileEntity(blockposition); + if (tileentity != null) { + player.playerConnection.sendPacket(tileentity.getUpdatePacket()); + } } + // Paper end - extend Player Interact cancellation entityplayer.getBukkitEntity().updateInventory(); // SPIGOT-2867 enuminteractionresult = (event.useItemInHand() != Event.Result.ALLOW) ? EnumInteractionResult.SUCCESS : EnumInteractionResult.PASS; } else if (this.gamemode == EnumGamemode.SPECTATOR) {