Skip to content

Commit

Permalink
Merge pull request #109 from project-poseidon-plugin-devs/pistonfix
Browse files Browse the repository at this point in the history
Fix various piston exploits
  • Loading branch information
sshshark authored Dec 10, 2024
2 parents 498abba + d36e337 commit 532b908
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ private void write() {
generateConfigOption("world.settings.block-tree-growth.info", "This setting allows for server owners to easily block trees growing from automatically destroying certain blocks. The list must be a string with numerical item ids separated by commas.");
generateConfigOption("world.settings.block-pistons-pushing-furnaces.info", "This workaround prevents pistons from pushing furnaces which prevents a malicious server crash.");
generateConfigOption("world.settings.block-pistons-pushing-furnaces.enabled", true);
generateConfigOption("world.settings.pistons.transmutation-fix.enabled", true);
generateConfigOption("world.settings.pistons.transmutation-fix.info", "This setting fixes block transmutation exploits.");
generateConfigOption("world.settings.pistons.sand-gravel-duping-fix.enabled", true);
generateConfigOption("world.settings.pistons.sand-gravel-duping-fix.info", "This setting fixes sand/gravel duplication exploits.");
generateConfigOption("world.settings.pistons.other-fixes.enabled", true);
generateConfigOption("world.settings.pistons.other-fixes.info", "This setting fixes various other piston exploits like creating illegal pistons, breaking bedrock and duplicating redstone torches.");
generateConfigOption("world.settings.skeleton-shooting-sound-fix.info", "This setting fixes the sound of skeletons and players shooting not playing on clients.");
generateConfigOption("world.settings.skeleton-shooting-sound-fix.enabled", true);
generateConfigOption("world.settings.speed-hack-check.enable", true);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/net/minecraft/server/BlockPiston.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@ private boolean i(World world, int i, int j, int k, int l) {
}

Block.byId[i2].g(world, i1, j1, k1, world.getData(i1, j1, k1));
world.setTypeId(i1, j1, k1, 0);
if (PoseidonConfig.getInstance().getConfigBoolean("world.settings.pistons.other-fixes.enabled", true)) {
world.setRawTypeId(i1, j1, k1, 0);
} else {
world.setTypeId(i1, j1, k1, 0);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public BlockPistonExtension(int i, int j) {
public void remove(World world, int i, int j, int k) {
super.remove(world, i, j, k);
int l = world.getData(i, j, k);
if (l > 5 || l < 0) return; // CraftBukkit - fixed a piston AIOOBE issue.
if (l < 0 || l == 6 || l == 7 || l > 13) return; // CraftBukkit - fixed a piston AIOOBE issue.
int i1 = PistonBlockTextures.a[b(l)];

i += PistonBlockTextures.b[i1];
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/minecraft/server/BlockRedstoneTorch.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.minecraft.server;

import com.legacyminecraft.poseidon.PoseidonConfig;
import org.bukkit.event.block.BlockRedstoneEvent;

import java.util.ArrayList;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void c(World world, int i, int j, int k) {
}

public void remove(World world, int i, int j, int k) {
if (this.isOn) {
if (this.isOn && (!PoseidonConfig.getInstance().getConfigBoolean("world.settings.pistons.transmutation-fix.enabled", true) || world.getTypeId(i, j, k) == this.id || world.getTypeId(i, j, k) == 75)) {
world.applyPhysics(i, j - 1, k, this.id);
world.applyPhysics(i, j + 1, k, this.id);
world.applyPhysics(i - 1, j, k, this.id);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/minecraft/server/BlockSand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.minecraft.server;

import com.legacyminecraft.poseidon.PoseidonConfig;

import java.util.Random;

public class BlockSand extends Block {
Expand Down Expand Up @@ -27,6 +29,9 @@ private void g(World world, int i, int j, int k) {
byte b0 = 32;

if (!instaFall && world.a(i - b0, j - b0, k - b0, i + b0, j + b0, k + b0)) {
if (PoseidonConfig.getInstance().getConfigBoolean("world.settings.pistons.sand-gravel-duping-fix.enabled", true)) {
world.setTypeId(i, j, k, 0);
}
EntityFallingSand entityfallingsand = new EntityFallingSand(world, i + 0.5D, j + 0.5D, k + 0.5D, this.id);

world.addEntity(entityfallingsand);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/net/minecraft/server/BlockTorch.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.minecraft.server;

import com.legacyminecraft.poseidon.PoseidonConfig;

import java.util.Random;

public class BlockTorch extends Block {
Expand Down Expand Up @@ -30,6 +32,7 @@ public boolean canPlace(World world, int i, int j, int k) {
}

public void postPlace(World world, int i, int j, int k, int l) {
if (PoseidonConfig.getInstance().getConfigBoolean("world.settings.pistons.transmutation-fix.enabled", true) && world.getTypeId(i, j, k) != this.id) return;
int i1 = world.getData(i, j, k);

if (l == 1 && this.g(world, i, j - 1, k)) {
Expand Down Expand Up @@ -111,7 +114,7 @@ public void doPhysics(World world, int i, int j, int k, int l) {
}

private boolean h(World world, int i, int j, int k) {
if (!this.canPlace(world, i, j, k)) {
if (!this.canPlace(world, i, j, k) && (!PoseidonConfig.getInstance().getConfigBoolean("world.settings.pistons.other-fixes.enabled") || world.getTypeId(i, j, k) == this.id)) {
this.g(world, i, j, k, world.getData(i, j, k));
world.setTypeId(i, j, k, 0);
return false;
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/net/minecraft/server/Chunk.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.minecraft.server;

import com.legacyminecraft.poseidon.PoseidonConfig;

import java.util.*;

public class Chunk {
Expand Down Expand Up @@ -233,11 +235,18 @@ public boolean a(int i, int j, int k, int l, int i1) {
int i2 = this.z * 16 + k;

this.b[i << 11 | k << 7 | j] = (byte) (b0 & 255);
if (k1 != 0 && !this.world.isStatic) {
Block.byId[k1].remove(this.world, l1, j, i2);
if (PoseidonConfig.getInstance().getConfigBoolean("world.settings.pistons.transmutation-fix.enabled", true)) {
this.e.a(i, j, k, i1);
if (k1 != 0 && !this.world.isStatic) {
Block.byId[k1].remove(this.world, l1, j, i2);
}
} else {
if (k1 != 0 && !this.world.isStatic) {
Block.byId[k1].remove(this.world, l1, j, i2);
}
this.e.a(i, j, k, i1);
}

this.e.a(i, j, k, i1);
if (!this.world.worldProvider.e) {
if (Block.q[b0 & 255] != 0) {
if (j >= j1) {
Expand All @@ -252,7 +261,6 @@ public boolean a(int i, int j, int k, int l, int i1) {

this.world.a(EnumSkyBlock.BLOCK, l1, j, i2, l1, j, i2);
this.c(i, k);
this.e.a(i, j, k, i1);
if (l != 0) {
Block.byId[l].c(this.world, l1, j, i2);
}
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/net/minecraft/server/ItemBlock.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.minecraft.server;

// CraftBukkit start
import com.legacyminecraft.poseidon.PoseidonConfig;
import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.block.BlockPlaceEvent;
Expand Down Expand Up @@ -101,12 +102,18 @@ public boolean a(ItemStack itemstack, EntityHuman entityhuman, World world, int
return true;

}
world.update(i, j, k, this.id); // <-- world.setTypeIdAndData does this on success (tell the world)

// CraftBukkit end

Block.byId[this.id].postPlace(world, i, j, k, l);
Block.byId[this.id].postPlace(world, i, j, k, entityhuman);
if (PoseidonConfig.getInstance().getConfigBoolean("world.settings.pistons.other-fixes.enabled", true) && (this.id == 29 || this.id == 33)) {
Block.byId[this.id].postPlace(world, i, j, k, l);
Block.byId[this.id].postPlace(world, i, j, k, entityhuman);
world.update(i, j, k, this.id); // <-- world.setTypeIdAndData does this on success (tell the world)
} else {
world.update(i, j, k, this.id);
Block.byId[this.id].postPlace(world, i, j, k, l);
Block.byId[this.id].postPlace(world, i, j, k, entityhuman);
}

world.makeSound((double) ((float) i + 0.5F), (double) ((float) j + 0.5F), (double) ((float) k + 0.5F), block.stepSound.getName(), (block.stepSound.getVolume1() + 1.0F) / 2.0F, block.stepSound.getVolume2() * 0.8F);
--itemstack.count;
}
Expand Down

0 comments on commit 532b908

Please sign in to comment.