From a4944dd2a6754377e5c2c3677efd11cb4edd9bc1 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Thu, 11 Jun 2020 17:29:42 -0700 Subject: [PATCH] PaperPR - 3550 - Fix more exploits --- .../com/destroystokyo/paper/PaperConfig.java | 7 ++-- src/main/java/net/minecraft/server/Block.java | 3 +- .../net/minecraft/server/BlockPiston.java | 35 ++++++++++++++++--- .../minecraft/server/EntityEnderDragon.java | 4 ++- .../minecraft/server/EntityFallingBlock.java | 11 ++++++ .../minecraft/server/PlayerConnection.java | 5 +++ .../minecraft/server/TileEntityPiston.java | 2 +- 7 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java index 863bec74a6..8444819f07 100644 --- a/src/main/java/com/destroystokyo/paper/PaperConfig.java +++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java @@ -442,8 +442,9 @@ public class PaperConfig { consoleHasAllPermissions = getBoolean("settings.console-has-all-permissions", consoleHasAllPermissions); } - public static boolean allowTntDuplication = false; - private static void allowTntDuplication() { - allowTntDuplication = getBoolean("settings.unsupported-settings.allow-tnt-duplication", allowTntDuplication); + public static boolean allowPistonDuplication; + private static void allowPistonDuplication() { + allowPistonDuplication = getBoolean("settings.unsupported-settings.allow-piston-duplication", config.getBoolean("settings.unsupported-settings.allow-tnt-duplication", false)); + set("settings.unsupported-settings.allow-tnt-duplication", null); } } diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java index 8985d0ee9d..6db195e023 100644 --- a/src/main/java/net/minecraft/server/Block.java +++ b/src/main/java/net/minecraft/server/Block.java @@ -37,7 +37,8 @@ public class Block implements IMaterial { this != Blocks.BEDROCK && this != Blocks.END_PORTAL_FRAME && this != Blocks.END_PORTAL && - this != Blocks.END_GATEWAY; + this != Blocks.END_GATEWAY && // Purpur + this != Blocks.MOVING_PISTON; // Purpur - try to prevent creation of headless pistons } public co.aikar.timings.Timing timing; public co.aikar.timings.Timing getTiming() { diff --git a/src/main/java/net/minecraft/server/BlockPiston.java b/src/main/java/net/minecraft/server/BlockPiston.java index 2b15aa959f..1d4d0d3eb3 100644 --- a/src/main/java/net/minecraft/server/BlockPiston.java +++ b/src/main/java/net/minecraft/server/BlockPiston.java @@ -175,6 +175,12 @@ public class BlockPiston extends BlockDirectional { @Override public boolean a(IBlockData iblockdata, World world, BlockPosition blockposition, int i, int j) { EnumDirection enumdirection = (EnumDirection) iblockdata.get(BlockPiston.FACING); + // Purpur start - prevent retracting when we're facing the wrong way (we were replaced before retraction could occur) + EnumDirection directionQueuedAs = EnumDirection.fromType1(j & 7); // Paper - copied from below + if (!com.destroystokyo.paper.PaperConfig.allowBlockPermanentBreakingExploits && enumdirection != directionQueuedAs) { + return false; + } + // Purpur end - prevent retracting when we're facing the wrong way if (!world.isClientSide) { boolean flag = this.a(world, blockposition, enumdirection); @@ -204,7 +210,7 @@ public class BlockPiston extends BlockDirectional { } world.setTypeAndData(blockposition, (IBlockData) ((IBlockData) Blocks.MOVING_PISTON.getBlockData().set(BlockPistonMoving.a, enumdirection)).set(BlockPistonMoving.b, this.sticky ? BlockPropertyPistonType.STICKY : BlockPropertyPistonType.DEFAULT), 3); - world.setTileEntity(blockposition, BlockPistonMoving.a((IBlockData) this.getBlockData().set(BlockPiston.FACING, EnumDirection.fromType1(j & 7)), enumdirection, false, true)); + world.setTileEntity(blockposition, BlockPistonMoving.a((IBlockData) this.getBlockData().set(BlockPiston.FACING, EnumDirection.fromType1(j & 7)), enumdirection, false, true)); // Purpur - diff on change, j is facing direction if (this.sticky) { BlockPosition blockposition1 = blockposition.b(enumdirection.getAdjacentX() * 2, enumdirection.getAdjacentY() * 2, enumdirection.getAdjacentZ() * 2); IBlockData iblockdata1 = world.getType(blockposition1); @@ -232,7 +238,14 @@ public class BlockPiston extends BlockDirectional { } } } else { - world.a(blockposition.shift(enumdirection), false); + // Purpur start - fix headless pistons breaking blocks + BlockPosition headPos = blockposition.shift(enumdirection); + if (com.destroystokyo.paper.PaperConfig.allowBlockPermanentBreakingExploits || world.getType(headPos) == Blocks.PISTON_HEAD.getBlockData().set(FACING, enumdirection)) { // double check to make sure we're not a headless piston. + world.setAir(headPos, false); + } else { + ((WorldServer)world).getChunkProvider().flagDirty(headPos); // ... fix client desync + } + // Purpur end - fix headless pistons breaking blocks } world.playSound((EntityHuman) null, blockposition, SoundEffects.BLOCK_PISTON_CONTRACT, SoundCategory.BLOCKS, 0.5F, world.random.nextFloat() * 0.15F + 0.6F); @@ -373,12 +386,24 @@ public class BlockPiston extends BlockDirectional { } for (k = list.size() - 1; k >= 0; --k) { - blockposition3 = (BlockPosition) list.get(k); - iblockdata1 = world.getType(blockposition3); if (!com.destroystokyo.paper.PaperConfig.allowTntDuplication) map.replace(blockposition3, iblockdata1); // Paper start - fix piston physics inconsistency + // Purpur start - fix a variety of piston desync dupes + boolean allowDesync = com.destroystokyo.paper.PaperConfig.allowPistonDuplication; + BlockPosition oldPos = blockposition3 = (BlockPosition) list.get(k); + iblockdata1 = allowDesync ? world.getType(oldPos) : null; + // Purpur end - fix a variety of piston desync dupes blockposition3 = blockposition3.shift(enumdirection1); map.remove(blockposition3); world.setTypeAndData(blockposition3, (IBlockData) Blocks.MOVING_PISTON.getBlockData().set(BlockPiston.FACING, enumdirection), 68); - world.setTileEntity(blockposition3, BlockPistonMoving.a(com.destroystokyo.paper.PaperConfig.allowTntDuplication ? list1.get(k) : iblockdata1, enumdirection, flag, false)); // Paper - fix piston physics inconsistency + // Purpur start - fix a variety of piston desync dupes + if (!allowDesync) { + iblockdata1 = world.getType(oldPos); + map.replace(oldPos, iblockdata1); + } + world.setTileEntity(blockposition3, BlockPistonMoving.a(allowDesync ? list1.get(k) : iblockdata1, enumdirection, flag, false)); + if (!allowDesync) { + world.setTypeAndData(oldPos, Blocks.AIR.getBlockData(), 4 | 16 | 1024); // set air to prevent later physics updates from seeing this block + } + // Purpur end - fix a variety of piston desync dupes --j; aiblockdata[j] = iblockdata1; } diff --git a/src/main/java/net/minecraft/server/EntityEnderDragon.java b/src/main/java/net/minecraft/server/EntityEnderDragon.java index f06fde3242..6abe47f776 100644 --- a/src/main/java/net/minecraft/server/EntityEnderDragon.java +++ b/src/main/java/net/minecraft/server/EntityEnderDragon.java @@ -33,7 +33,7 @@ public class EntityEnderDragon extends EntityInsentient implements IMonster { public float bx; public float by; public boolean bz; - public int bA; + public int bA; public final int getDeathTicks() { return this.bA; } public final void setDeathTicks(final int value) { this.bA = value; } // Purpur public float bB; @Nullable public EntityEnderCrystal currentEnderCrystal; @@ -908,6 +908,7 @@ public class EntityEnderDragon extends EntityInsentient implements IMonster { public void b(NBTTagCompound nbttagcompound) { super.b(nbttagcompound); nbttagcompound.setInt("DragonPhase", this.bO.a().getControllerPhase().b()); + nbttagcompound.setInt("Paper.DeathTick", this.getDeathTicks()); // Purpur } @Override @@ -916,6 +917,7 @@ public class EntityEnderDragon extends EntityInsentient implements IMonster { if (nbttagcompound.hasKey("DragonPhase")) { this.bO.setControllerPhase(DragonControllerPhase.getById(nbttagcompound.getInt("DragonPhase"))); } + this.setDeathTicks(nbttagcompound.getInt("Paper.DeathTick")); // Purpur } diff --git a/src/main/java/net/minecraft/server/EntityFallingBlock.java b/src/main/java/net/minecraft/server/EntityFallingBlock.java index 6683f7c5f3..7969b1cd57 100644 --- a/src/main/java/net/minecraft/server/EntityFallingBlock.java +++ b/src/main/java/net/minecraft/server/EntityFallingBlock.java @@ -64,6 +64,11 @@ public class EntityFallingBlock extends Entity { @Override public void tick() { + // Purpur start - fix sand duping + if (this.dead) { + return; + } + // Purpur end - fix sand duping if (this.block.isAir()) { this.die(); } else { @@ -86,6 +91,12 @@ public class EntityFallingBlock extends Entity { this.move(EnumMoveType.SELF, this.getMot()); + // Purpur start - fix sand duping + if (this.dead) { + return; + } + // Purpur end - fix sand duping + // Paper start - Configurable EntityFallingBlock height nerf if (this.world.paperConfig.fallingBlockHeightNerf != 0 && this.locY() > this.world.paperConfig.fallingBlockHeightNerf) { if (this.dropItem && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) { diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java index 3a1aa1d4da..c13296935c 100644 --- a/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/PlayerConnection.java @@ -1104,6 +1104,11 @@ public class PlayerConnection implements PacketListenerPlayIn { } this.player.move(EnumMoveType.PLAYER, new Vec3D(d7, d8, d9)); + // Purpur start - prevent position desync + if (this.teleportPos != null) { + return; // ... thanks Mojang for letting move calls teleport across dimensions. + } + // Purpur end - prevent position desync this.player.onGround = packetplayinflying.b(); double d12 = d8; diff --git a/src/main/java/net/minecraft/server/TileEntityPiston.java b/src/main/java/net/minecraft/server/TileEntityPiston.java index 634e378430..d700e8281f 100644 --- a/src/main/java/net/minecraft/server/TileEntityPiston.java +++ b/src/main/java/net/minecraft/server/TileEntityPiston.java @@ -275,7 +275,7 @@ public class TileEntityPiston extends TileEntity implements ITickable { IBlockData iblockdata = Block.b(this.a, (GeneratorAccess) this.world, this.position); if (iblockdata.isAir()) { - this.world.setTypeAndData(this.position, this.a, 84 | (com.destroystokyo.paper.PaperConfig.allowTntDuplication ? 0 : 2)); // Paper - force notify (flag 2), it's possible the set type by the piston block (which doesn't notify) set this block to air + this.world.setTypeAndData(this.position, this.a, com.destroystokyo.paper.PaperConfig.allowPistonDuplication ? 84 : (84 | 2)); // Paper - force notify (flag 2), it's possible the set type by the piston block (which doesn't notify) set this block to air Block.a(this.a, iblockdata, this.world, this.position, 3); } else { if (iblockdata.b((IBlockState) BlockProperties.C) && (Boolean) iblockdata.get(BlockProperties.C)) { -- 2.26.2