SPIGOT-6413: Server Corruption Changing Blocks in Piston Events

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2021-04-07 15:03:30 +10:00
parent 834f035a21
commit 0601c47be5

View File

@ -76,7 +76,7 @@
this.portalTravelAgent = new PortalTravelAgent(this); this.portalTravelAgent = new PortalTravelAgent(this);
this.Q(); this.Q();
this.R(); this.R();
@@ -201,14 +238,48 @@ @@ -201,14 +238,50 @@
iworlddataserver.setGameType(minecraftserver.getGamemode()); iworlddataserver.setGameType(minecraftserver.getGamemode());
} }
@ -116,8 +116,10 @@
+ +
+ if (type instanceof ITileEntity) { + if (type instanceof ITileEntity) {
+ TileEntity replacement = ((ITileEntity) type).createTile(this); + TileEntity replacement = ((ITileEntity) type).createTile(this);
+ replacement.setLocation(this, pos); + if (replacement != null) {
+ this.setTileEntity(pos, replacement); + replacement.setLocation(this, pos);
+ this.setTileEntity(pos, replacement);
+ }
+ return replacement; + return replacement;
+ } else { + } else {
+ return found; + return found;
@ -127,7 +129,7 @@
public void a(int i, int j, boolean flag, boolean flag1) { public void a(int i, int j, boolean flag, boolean flag1) {
this.worldDataServer.setClearWeatherTime(i); this.worldDataServer.setClearWeatherTime(i);
@@ -299,6 +370,7 @@ @@ -299,6 +372,7 @@
this.rainLevel = MathHelper.a(this.rainLevel, 0.0F, 1.0F); this.rainLevel = MathHelper.a(this.rainLevel, 0.0F, 1.0F);
} }
@ -135,7 +137,7 @@
if (this.lastRainLevel != this.rainLevel) { if (this.lastRainLevel != this.rainLevel) {
this.server.getPlayerList().a((Packet) (new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.h, this.rainLevel)), this.getDimensionKey()); this.server.getPlayerList().a((Packet) (new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.h, this.rainLevel)), this.getDimensionKey());
} }
@@ -317,18 +389,47 @@ @@ -317,18 +391,47 @@
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.h, this.rainLevel)); this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.h, this.rainLevel));
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.i, this.thunderLevel)); this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.i, this.thunderLevel));
} }
@ -188,7 +190,7 @@
if (this.getGameRules().getBoolean(GameRules.DO_WEATHER_CYCLE)) { if (this.getGameRules().getBoolean(GameRules.DO_WEATHER_CYCLE)) {
this.clearWeather(); this.clearWeather();
} }
@@ -350,7 +451,7 @@ @@ -350,7 +453,7 @@
this.ak(); this.ak();
this.ticking = false; this.ticking = false;
gameprofilerfiller.exitEnter("entities"); gameprofilerfiller.exitEnter("entities");
@ -197,7 +199,7 @@
if (flag3) { if (flag3) {
this.resetEmptyTime(); this.resetEmptyTime();
@@ -369,6 +470,7 @@ @@ -369,6 +472,7 @@
Entity entity = (Entity) entry.getValue(); Entity entity = (Entity) entry.getValue();
Entity entity1 = entity.getVehicle(); Entity entity1 = entity.getVehicle();
@ -205,7 +207,7 @@
if (!this.server.getSpawnAnimals() && (entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal)) { if (!this.server.getSpawnAnimals() && (entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal)) {
entity.die(); entity.die();
} }
@@ -376,6 +478,7 @@ @@ -376,6 +480,7 @@
if (!this.server.getSpawnNPCs() && entity instanceof NPC) { if (!this.server.getSpawnNPCs() && entity instanceof NPC) {
entity.die(); entity.die();
} }
@ -213,7 +215,7 @@
gameprofilerfiller.enter("checkDespawn"); gameprofilerfiller.enter("checkDespawn");
if (!entity.dead) { if (!entity.dead) {
@@ -450,7 +553,7 @@ @@ -450,7 +555,7 @@
} }
private void wakeupPlayers() { private void wakeupPlayers() {
@ -222,7 +224,7 @@
entityplayer.wakeup(false, false); entityplayer.wakeup(false, false);
}); });
} }
@@ -477,14 +580,14 @@ @@ -477,14 +582,14 @@
entityhorseskeleton.t(true); entityhorseskeleton.t(true);
entityhorseskeleton.setAgeRaw(0); entityhorseskeleton.setAgeRaw(0);
entityhorseskeleton.setPosition((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ()); entityhorseskeleton.setPosition((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
@ -239,7 +241,7 @@
} }
} }
@@ -495,11 +598,11 @@ @@ -495,11 +600,11 @@
BiomeBase biomebase = this.getBiome(blockposition); BiomeBase biomebase = this.getBiome(blockposition);
if (biomebase.a(this, blockposition1)) { if (biomebase.a(this, blockposition1)) {
@ -253,7 +255,7 @@
} }
if (flag && this.getBiome(blockposition1).c() == BiomeBase.Precipitation.RAIN) { if (flag && this.getBiome(blockposition1).c() == BiomeBase.Precipitation.RAIN) {
@@ -546,7 +649,7 @@ @@ -546,7 +651,7 @@
protected BlockPosition a(BlockPosition blockposition) { protected BlockPosition a(BlockPosition blockposition) {
BlockPosition blockposition1 = this.getHighestBlockYAt(HeightMap.Type.MOTION_BLOCKING, blockposition); BlockPosition blockposition1 = this.getHighestBlockYAt(HeightMap.Type.MOTION_BLOCKING, blockposition);
AxisAlignedBB axisalignedbb = (new AxisAlignedBB(blockposition1, new BlockPosition(blockposition1.getX(), this.getBuildHeight(), blockposition1.getZ()))).g(3.0D); AxisAlignedBB axisalignedbb = (new AxisAlignedBB(blockposition1, new BlockPosition(blockposition1.getX(), this.getBuildHeight(), blockposition1.getZ()))).g(3.0D);
@ -262,7 +264,7 @@
return entityliving != null && entityliving.isAlive() && this.e(entityliving.getChunkCoordinates()); return entityliving != null && entityliving.isAlive() && this.e(entityliving.getChunkCoordinates());
}); });
@@ -575,7 +678,7 @@ @@ -575,7 +680,7 @@
while (iterator.hasNext()) { while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next(); EntityPlayer entityplayer = (EntityPlayer) iterator.next();
@ -271,7 +273,7 @@
++i; ++i;
} else if (entityplayer.isSleeping()) { } else if (entityplayer.isSleeping()) {
++j; ++j;
@@ -593,10 +696,22 @@ @@ -593,10 +698,22 @@
} }
private void clearWeather() { private void clearWeather() {
@ -296,7 +298,7 @@
} }
public void resetEmptyTime() { public void resetEmptyTime() {
@@ -637,6 +752,7 @@ @@ -637,6 +754,7 @@
}); });
gameprofilerfiller.c("tickNonPassenger"); gameprofilerfiller.c("tickNonPassenger");
entity.tick(); entity.tick();
@ -304,7 +306,7 @@
gameprofilerfiller.exit(); gameprofilerfiller.exit();
} }
@@ -669,6 +785,7 @@ @@ -669,6 +787,7 @@
}); });
gameprofilerfiller.c("tickPassenger"); gameprofilerfiller.c("tickPassenger");
entity1.passengerTick(); entity1.passengerTick();
@ -312,7 +314,7 @@
gameprofilerfiller.exit(); gameprofilerfiller.exit();
} }
@@ -725,6 +842,7 @@ @@ -725,6 +844,7 @@
ChunkProviderServer chunkproviderserver = this.getChunkProvider(); ChunkProviderServer chunkproviderserver = this.getChunkProvider();
if (!flag1) { if (!flag1) {
@ -320,7 +322,7 @@
if (iprogressupdate != null) { if (iprogressupdate != null) {
iprogressupdate.a(new ChatMessage("menu.savingLevel")); iprogressupdate.a(new ChatMessage("menu.savingLevel"));
} }
@@ -736,11 +854,19 @@ @@ -736,11 +856,19 @@
chunkproviderserver.save(flag); chunkproviderserver.save(flag);
} }
@ -341,7 +343,7 @@
} }
this.getChunkProvider().getWorldPersistentData().a(); this.getChunkProvider().getWorldPersistentData().a();
@@ -801,11 +927,24 @@ @@ -801,11 +929,24 @@
@Override @Override
public boolean addEntity(Entity entity) { public boolean addEntity(Entity entity) {
@ -368,7 +370,7 @@
} }
public void addEntityTeleport(Entity entity) { public void addEntityTeleport(Entity entity) {
@@ -855,13 +994,18 @@ @@ -855,13 +996,18 @@
this.registerEntity(entityplayer); this.registerEntity(entityplayer);
} }
@ -389,7 +391,7 @@
IChunkAccess ichunkaccess = this.getChunkAt(MathHelper.floor(entity.locX() / 16.0D), MathHelper.floor(entity.locZ() / 16.0D), ChunkStatus.FULL, entity.attachedToPlayer); IChunkAccess ichunkaccess = this.getChunkAt(MathHelper.floor(entity.locX() / 16.0D), MathHelper.floor(entity.locZ() / 16.0D), ChunkStatus.FULL, entity.attachedToPlayer);
if (!(ichunkaccess instanceof Chunk)) { if (!(ichunkaccess instanceof Chunk)) {
@@ -890,7 +1034,7 @@ @@ -890,7 +1036,7 @@
if (entity1 == null) { if (entity1 == null) {
return false; return false;
} else { } else {
@ -398,7 +400,7 @@
return true; return true;
} }
} }
@@ -919,10 +1063,16 @@ @@ -919,10 +1065,16 @@
} }
public boolean addAllEntitiesSafely(Entity entity) { public boolean addAllEntitiesSafely(Entity entity) {
@ -416,7 +418,7 @@
return true; return true;
} }
} }
@@ -973,10 +1123,17 @@ @@ -973,10 +1125,17 @@
} }
this.getScoreboard().a(entity); this.getScoreboard().a(entity);
@ -434,7 +436,7 @@
} }
private void registerEntity(Entity entity) { private void registerEntity(Entity entity) {
@@ -997,9 +1154,16 @@ @@ -997,9 +1156,16 @@
this.entitiesByUUID.put(entity.getUniqueID(), entity); this.entitiesByUUID.put(entity.getUniqueID(), entity);
this.getChunkProvider().addEntity(entity); this.getChunkProvider().addEntity(entity);
@ -451,7 +453,7 @@
} }
} }
@@ -1015,7 +1179,7 @@ @@ -1015,7 +1181,7 @@
} }
private void removeEntityFromChunk(Entity entity) { private void removeEntityFromChunk(Entity entity) {
@ -460,7 +462,7 @@
if (ichunkaccess instanceof Chunk) { if (ichunkaccess instanceof Chunk) {
((Chunk) ichunkaccess).b(entity); ((Chunk) ichunkaccess).b(entity);
@@ -1029,10 +1193,33 @@ @@ -1029,10 +1195,33 @@
this.everyoneSleeping(); this.everyoneSleeping();
} }
@ -494,7 +496,7 @@
while (iterator.hasNext()) { while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next(); EntityPlayer entityplayer = (EntityPlayer) iterator.next();
@@ -1041,6 +1228,12 @@ @@ -1041,6 +1230,12 @@
double d1 = (double) blockposition.getY() - entityplayer.locY(); double d1 = (double) blockposition.getY() - entityplayer.locY();
double d2 = (double) blockposition.getZ() - entityplayer.locZ(); double d2 = (double) blockposition.getZ() - entityplayer.locZ();
@ -507,7 +509,7 @@
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) { if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
entityplayer.playerConnection.sendPacket(new PacketPlayOutBlockBreakAnimation(i, blockposition, j)); entityplayer.playerConnection.sendPacket(new PacketPlayOutBlockBreakAnimation(i, blockposition, j));
} }
@@ -1079,7 +1272,18 @@ @@ -1079,7 +1274,18 @@
Iterator iterator = this.navigators.iterator(); Iterator iterator = this.navigators.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
@ -527,7 +529,7 @@
if (!navigationabstract.i()) { if (!navigationabstract.i()) {
navigationabstract.b(blockposition); navigationabstract.b(blockposition);
@@ -1101,10 +1305,20 @@ @@ -1101,10 +1307,20 @@
@Override @Override
public Explosion createExplosion(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, Explosion.Effect explosion_effect) { public Explosion createExplosion(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, Explosion.Effect explosion_effect) {
@ -548,7 +550,7 @@
if (explosion_effect == Explosion.Effect.NONE) { if (explosion_effect == Explosion.Effect.NONE) {
explosion.clearBlocks(); explosion.clearBlocks();
} }
@@ -1169,13 +1383,20 @@ @@ -1169,13 +1385,20 @@
} }
public <T extends ParticleParam> int a(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) { public <T extends ParticleParam> int a(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
@ -571,7 +573,7 @@
++j; ++j;
} }
} }
@@ -1217,7 +1438,7 @@ @@ -1217,7 +1440,7 @@
@Nullable @Nullable
public BlockPosition a(StructureGenerator<?> structuregenerator, BlockPosition blockposition, int i, boolean flag) { public BlockPosition a(StructureGenerator<?> structuregenerator, BlockPosition blockposition, int i, boolean flag) {
@ -580,7 +582,7 @@
} }
@Nullable @Nullable
@@ -1255,7 +1476,13 @@ @@ -1255,7 +1478,13 @@
@Override @Override
public WorldMap a(String s) { public WorldMap a(String s) {
return (WorldMap) this.getMinecraftServer().E().getWorldPersistentData().b(() -> { return (WorldMap) this.getMinecraftServer().E().getWorldPersistentData().b(() -> {
@ -595,7 +597,7 @@
}, s); }, s);
} }
@@ -1386,9 +1613,9 @@ @@ -1386,9 +1615,9 @@
reputationhandler.a(reputationevent, entity); reputationhandler.a(reputationevent, entity);
} }
@ -607,7 +609,7 @@
Throwable throwable = null; Throwable throwable = null;
try { try {
@@ -1432,7 +1659,7 @@ @@ -1432,7 +1661,7 @@
CrashReport crashreport = new CrashReport("Level dump", new Exception("dummy")); CrashReport crashreport = new CrashReport("Level dump", new Exception("dummy"));
this.a(crashreport); this.a(crashreport);
@ -616,7 +618,7 @@
Throwable throwable3 = null; Throwable throwable3 = null;
try { try {
@@ -1455,8 +1682,8 @@ @@ -1455,8 +1684,8 @@
} }
@ -627,7 +629,7 @@
Throwable throwable6 = null; Throwable throwable6 = null;
try { try {
@@ -1479,8 +1706,8 @@ @@ -1479,8 +1708,8 @@
} }
@ -638,7 +640,7 @@
Throwable throwable9 = null; Throwable throwable9 = null;
try { try {
@@ -1503,8 +1730,8 @@ @@ -1503,8 +1732,8 @@
} }
@ -649,7 +651,7 @@
Throwable throwable12 = null; Throwable throwable12 = null;
try { try {
@@ -1566,6 +1793,11 @@ @@ -1566,6 +1795,11 @@
@Override @Override
public void update(BlockPosition blockposition, Block block) { public void update(BlockPosition blockposition, Block block) {
if (!this.isDebugWorld()) { if (!this.isDebugWorld()) {
@ -661,7 +663,7 @@
this.applyPhysics(blockposition, block); this.applyPhysics(blockposition, block);
} }
@@ -1580,12 +1812,12 @@ @@ -1580,12 +1814,12 @@
} }
public boolean isFlatWorld() { public boolean isFlatWorld() {
@ -676,7 +678,7 @@
} }
@Nullable @Nullable
@@ -1605,9 +1837,9 @@ @@ -1605,9 +1839,9 @@
@VisibleForTesting @VisibleForTesting
public String F() { public String F() {
@ -688,7 +690,7 @@
return IRegistry.BLOCK_ENTITY_TYPE.getKey(tileentity.getTileType()); return IRegistry.BLOCK_ENTITY_TYPE.getKey(tileentity.getTileType());
}), this.getBlockTickList().a(), this.getFluidTickList().a(), this.P()); }), this.getBlockTickList().a(), this.getFluidTickList().a(), this.P());
} }
@@ -1615,7 +1847,7 @@ @@ -1615,7 +1849,7 @@
private static <T> String a(Collection<T> collection, Function<T, MinecraftKey> function) { private static <T> String a(Collection<T> collection, Function<T, MinecraftKey> function) {
try { try {
Object2IntOpenHashMap<MinecraftKey> object2intopenhashmap = new Object2IntOpenHashMap(); Object2IntOpenHashMap<MinecraftKey> object2intopenhashmap = new Object2IntOpenHashMap();
@ -697,7 +699,7 @@
while (iterator.hasNext()) { while (iterator.hasNext()) {
T t0 = iterator.next(); T t0 = iterator.next();
@@ -1624,7 +1856,8 @@ @@ -1624,7 +1858,8 @@
object2intopenhashmap.addTo(minecraftkey, 1); object2intopenhashmap.addTo(minecraftkey, 1);
} }
@ -707,7 +709,7 @@
return it_unimi_dsi_fastutil_objects_object2intmap_entry.getKey() + ":" + it_unimi_dsi_fastutil_objects_object2intmap_entry.getIntValue(); return it_unimi_dsi_fastutil_objects_object2intmap_entry.getKey() + ":" + it_unimi_dsi_fastutil_objects_object2intmap_entry.getIntValue();
}).collect(Collectors.joining(",")); }).collect(Collectors.joining(","));
} catch (Exception exception) { } catch (Exception exception) {
@@ -1633,16 +1866,32 @@ @@ -1633,16 +1868,32 @@
} }
public static void a(WorldServer worldserver) { public static void a(WorldServer worldserver) {