Limit TNT Detonations per tick

This gives a per-world control on how much TNT will be processed per-tick,
preventing a massive TNT detonation from lagging out the server.

By: Aikar <aikar@aikar.co>
This commit is contained in:
CraftBukkit/Spigot 2014-08-20 18:12:32 -04:00
parent c34736a0d2
commit d7f3ba3df3
3 changed files with 28 additions and 8 deletions

View file

@ -21,7 +21,15 @@
public PrimedTnt(EntityType<? extends PrimedTnt> type, Level world) {
super(type, world);
@@ -107,10 +114,13 @@
@@ -94,6 +101,7 @@
@Override
public void tick() {
+ if (this.level().spigotConfig.maxTntTicksPerTick > 0 && ++this.level().spigotConfig.currentPrimedTnt > this.level().spigotConfig.maxTntTicksPerTick) { return; } // Spigot
this.handlePortal();
this.applyGravity();
this.move(MoverType.SELF, this.getDeltaMovement());
@@ -107,10 +115,13 @@
this.setFuse(i);
if (i <= 0) {
@ -36,7 +44,7 @@
} else {
this.updateInWaterStateAndDoFluidPushing();
if (this.level().isClientSide) {
@@ -121,7 +131,13 @@
@@ -121,7 +132,13 @@
}
private void explode() {

View file

@ -208,7 +208,7 @@
LevelChunk chunk = this.getChunkAt(pos);
Block block = state.getBlock();
- BlockState iblockdata1 = chunk.setBlockState(pos, state, (flags & 64) != 0);
+
+ // CraftBukkit start - capture blockstates
+ boolean captured = false;
+ if (this.captureBlockStates && !this.capturedBlockStates.containsKey(pos)) {
@ -217,7 +217,7 @@
+ captured = true;
+ }
+ // CraftBukkit end
+
+ BlockState iblockdata1 = chunk.setBlockState(pos, state, (flags & 64) != 0, (flags & 1024) == 0); // CraftBukkit custom NO_PLACE flag
+
if (iblockdata1 == null) {
@ -373,13 +373,14 @@
Iterator<TickingBlockEntity> iterator = this.blockEntityTickers.iterator();
boolean flag = this.tickRateManager().runsNormally();
@@ -459,13 +661,16 @@
@@ -459,13 +661,17 @@
}
}
+ this.timings.tileEntityTick.stopTiming(); // Spigot
this.tickingBlockEntities = false;
gameprofilerfiller.pop();
+ this.spigotConfig.currentPrimedTnt = 0; // Spigot
}
public <T extends Entity> void guardEntityTick(Consumer<T> tickConsumer, T entity) {
@ -390,7 +391,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking entity");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being ticked");
@@ -510,13 +715,29 @@
@@ -510,13 +716,29 @@
@Nullable
@Override
public BlockEntity getBlockEntity(BlockPos pos) {
@ -421,7 +422,7 @@
this.getChunkAt(blockposition).addAndRegisterBlockEntity(blockEntity);
}
}
@@ -643,7 +864,7 @@
@@ -643,7 +865,7 @@
for (int k = 0; k < j; ++k) {
EnderDragonPart entitycomplexpart = aentitycomplexpart[k];
@ -430,7 +431,7 @@
if (t0 != null && predicate.test(t0)) {
result.add(t0);
@@ -912,7 +1133,7 @@
@@ -912,7 +1134,7 @@
public static enum ExplosionInteraction implements StringRepresentable {

View file

@ -356,4 +356,15 @@ public class SpigotWorldConfig
this.sprintMultiplier = (float) this.getDouble( "hunger.sprint-multiplier", 0.1 );
this.otherMultiplier = (float) this.getDouble( "hunger.other-multiplier", 0.0 );
}
public int currentPrimedTnt = 0;
public int maxTntTicksPerTick;
private void maxTntPerTick() {
if ( SpigotConfig.version < 7 )
{
this.set( "max-tnt-per-tick", 100 );
}
this.maxTntTicksPerTick = this.getInt( "max-tnt-per-tick", 100 );
this.log( "Max TNT Explosions: " + this.maxTntTicksPerTick );
}
}