From 0011dd0d9a2337e38ec4b87fc109c3d3e749fac1 Mon Sep 17 00:00:00 2001 From: Sergey Shatunov Date: Tue, 5 Jan 2016 14:20:01 +0700 Subject: [PATCH] Limit TNT detonations per world per tick --- .../entity/item/EntityTNTPrimed.java.patch | 14 ++++++++-- .../minecraft/world/WorldServer.java.patch | 28 ++++++++++++------- src/main/java/org/spigotmc/SpigotConfig.java | 11 +++++--- .../java/org/spigotmc/SpigotWorldConfig.java | 11 ++++++++ 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/patches/net/minecraft/entity/item/EntityTNTPrimed.java.patch b/patches/net/minecraft/entity/item/EntityTNTPrimed.java.patch index fb2f909..51b6d61 100644 --- a/patches/net/minecraft/entity/item/EntityTNTPrimed.java.patch +++ b/patches/net/minecraft/entity/item/EntityTNTPrimed.java.patch @@ -16,7 +16,15 @@ public EntityTNTPrimed(World p_i1729_1_) { -@@ -68,12 +72,14 @@ +@@ -50,6 +54,7 @@ + + public void onUpdate() + { ++ if (worldObj.spigotConfig.currentPrimedTnt++ > worldObj.spigotConfig.maxTntTicksPerTick) { return; } // Spigot + this.prevPosX = this.posX; + this.prevPosY = this.posY; + this.prevPosZ = this.posZ; +@@ -68,12 +73,14 @@ if (this.fuse-- <= 0) { @@ -33,7 +41,7 @@ } else { -@@ -83,8 +89,19 @@ +@@ -83,8 +90,19 @@ private void explode() { @@ -55,7 +63,7 @@ } protected void writeEntityToNBT(NBTTagCompound p_70014_1_) -@@ -107,4 +124,11 @@ +@@ -107,4 +125,11 @@ { return this.tntPlacedBy; } diff --git a/patches/net/minecraft/world/WorldServer.java.patch b/patches/net/minecraft/world/WorldServer.java.patch index 1a9dc31..7b278c6 100644 --- a/patches/net/minecraft/world/WorldServer.java.patch +++ b/patches/net/minecraft/world/WorldServer.java.patch @@ -389,7 +389,15 @@ { if (this.updateEntityTick++ >= 1200) { -@@ -506,7 +686,16 @@ +@@ -487,6 +667,7 @@ + } + + super.updateEntities(); ++ spigotConfig.currentPrimedTnt = 0; // Spigot + } + + public void resetUpdateEntityTick() +@@ -506,7 +687,16 @@ { if (i > 1000) { @@ -407,7 +415,7 @@ } this.theProfiler.startSection("cleaning"); -@@ -651,7 +840,37 @@ +@@ -651,7 +841,37 @@ protected IChunkProvider createChunkProvider() { IChunkLoader ichunkloader = this.saveHandler.getChunkLoader(this.provider); @@ -446,7 +454,7 @@ return this.theChunkProviderServer; } -@@ -659,29 +878,31 @@ +@@ -659,29 +879,31 @@ { ArrayList arraylist = new ArrayList(); @@ -493,7 +501,7 @@ return arraylist; } -@@ -733,7 +954,28 @@ +@@ -733,7 +955,28 @@ int i = 0; int j = this.provider.getAverageGroundLevel(); int k = 0; @@ -522,7 +530,7 @@ if (chunkposition != null) { i = chunkposition.chunkPosX; -@@ -876,6 +1118,20 @@ +@@ -876,6 +1119,20 @@ public boolean addWeatherEffect(Entity p_72942_1_) { @@ -543,7 +551,7 @@ if (super.addWeatherEffect(p_72942_1_)) { this.mcServer.getConfigurationManager().sendToAllNear(p_72942_1_.posX, p_72942_1_.posY, p_72942_1_.posZ, 512.0D, this.provider.dimensionId, new S2CPacketSpawnGlobalEntity(p_72942_1_)); -@@ -894,13 +1150,23 @@ +@@ -894,13 +1151,23 @@ public Explosion newExplosion(Entity p_72885_1_, double p_72885_2_, double p_72885_4_, double p_72885_6_, float p_72885_8_, boolean p_72885_9_, boolean p_72885_10_) { @@ -568,7 +576,7 @@ if (!p_72885_10_) { explosion.affectedBlockPositions.clear(); -@@ -977,7 +1243,7 @@ +@@ -977,7 +1244,7 @@ { boolean flag = this.isRaining(); super.updateWeather(); @@ -577,7 +585,7 @@ if (this.prevRainingStrength != this.rainingStrength) { this.mcServer.getConfigurationManager().sendPacketToAllPlayersInDimension(new S2BPacketChangeGameState(7, this.rainingStrength), this.provider.dimensionId); -@@ -988,10 +1254,6 @@ +@@ -988,10 +1255,6 @@ this.mcServer.getConfigurationManager().sendPacketToAllPlayersInDimension(new S2BPacketChangeGameState(8, this.thunderingStrength), this.provider.dimensionId); } @@ -588,7 +596,7 @@ if (flag != this.isRaining()) { if (flag) -@@ -1006,6 +1268,33 @@ +@@ -1006,6 +1269,33 @@ this.mcServer.getConfigurationManager().sendPacketToAllPlayersInDimension(new S2BPacketChangeGameState(7, this.rainingStrength), this.provider.dimensionId); this.mcServer.getConfigurationManager().sendPacketToAllPlayersInDimension(new S2BPacketChangeGameState(8, this.thunderingStrength), this.provider.dimensionId); } @@ -622,7 +630,7 @@ } protected int func_152379_p() -@@ -1069,4 +1358,51 @@ +@@ -1069,4 +1359,51 @@ this(); } } diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java index 833f5e5..b721cc4 100644 --- a/src/main/java/org/spigotmc/SpigotConfig.java +++ b/src/main/java/org/spigotmc/SpigotConfig.java @@ -50,8 +50,8 @@ public class SpigotConfig commands = new HashMap(); - version = getInt( "config-version", 5 ); - set( "config-version", 5 ); + version = getInt( "config-version", 7 ); + set( "config-version", 7 ); readConfig( SpigotConfig.class, null ); } @@ -152,7 +152,7 @@ public class SpigotConfig public static String unknownCommandMessage; public static String serverFullMessage; public static String outdatedClientMessage = "Outdated client! Please use {}"; - public static String outdatedServerMessage = "Outdated server! I\'m still on {0}"; + public static String outdatedServerMessage = "Outdated server! I\'m still on {}"; private static String transform(String s) { return ChatColor.translateAlternateColorCodes( '&', s ).replaceAll( "\\n", "\n" ); @@ -199,7 +199,10 @@ public class SpigotConfig private static void nettyThreads() { - int count = getInt( "settings.netty-threads", 4 ); + if (version < 7) + set("settings.netty-threads", -1); + int count = getInt( "settings.netty-threads", -1 ); + count = count == -1 ? Runtime.getRuntime().availableProcessors() : count; System.setProperty( "io.netty.eventLoopThreads", Integer.toString( count ) ); Bukkit.getLogger().log( Level.INFO, "Using {0} threads for Netty based IO", count ); } diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java index 02f4d3f..60f8ae8 100644 --- a/src/main/java/org/spigotmc/SpigotWorldConfig.java +++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java @@ -287,4 +287,15 @@ public class SpigotWorldConfig entityMaxTickTime = getInt("max-tick-time.entity", 50); log("Tile Max Tick Time: " + tileMaxTickTime + "ms Entity max Tick Time: " + entityMaxTickTime + "ms"); } + + public int currentPrimedTnt = 0; + public int maxTntTicksPerTick; + private void maxTntPerTick() { + if ( SpigotConfig.version < 7 ) + { + set( "max-tnt-per-tick", 100 ); + } + maxTntTicksPerTick = getInt( "max-tnt-per-tick", 100 ); + log( "Max TNT Explosions: " + maxTntTicksPerTick ); + } }