Skip to content

Commit

Permalink
some more patches
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Sep 22, 2023
1 parent 78a003e commit 2bc818e
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ index 6aaed8e8bf8c721fc834da5c76ac72a4c3e92458..4b002e8b75d117b726b0de274a76d359
// Many servers tend to restart at a fixed time at xx:00 which causes an uneven distribution of requests on the
// bStats backend. To circumvent this problem, we introduce some randomness into the initial and second delay.
diff --git a/src/main/java/net/minecraft/CrashReport.java b/src/main/java/net/minecraft/CrashReport.java
index 336795dff742b7c6957fbd3476aff31d25a5e659..30a58229aa6dac5039511d0c0df5f2912ea7de9f 100644
index d7995cadda8f48bbf642114935311180d3ebde5b..226cba0c1eeedd9e80acd603c46b802c183db1fa 100644
--- a/src/main/java/net/minecraft/CrashReport.java
+++ b/src/main/java/net/minecraft/CrashReport.java
@@ -230,6 +230,7 @@ public class CrashReport {
Expand All @@ -71,10 +71,10 @@ index 336795dff742b7c6957fbd3476aff31d25a5e659..30a58229aa6dac5039511d0c0df5f291
cause = cause.getCause();
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 498f06aa1d8b2c20f5bf31d6751f08cf1eb4240f..047562e1df93347f629b529ca0647697e22ecf48 100644
index 0fa1d9f299194ff660130a1cf33d9a405d56a842..d50878653132218dd494e0e5ed6fc3a32d4f1465 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -296,7 +296,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -291,7 +291,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public java.util.Queue<Runnable> processQueue = new java.util.concurrent.ConcurrentLinkedQueue<Runnable>();
public int autosavePeriod;
public Commands vanillaCommandDispatcher;
Expand All @@ -83,7 +83,7 @@ index 498f06aa1d8b2c20f5bf31d6751f08cf1eb4240f..047562e1df93347f629b529ca0647697
// CraftBukkit end
// Spigot start
public static final int TPS = 20;
@@ -307,6 +307,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -302,6 +302,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public final io.papermc.paper.configuration.PaperConfigurations paperConfigurations;
public static long currentTickLong = 0L; // Paper

Expand All @@ -92,16 +92,16 @@ index 498f06aa1d8b2c20f5bf31d6751f08cf1eb4240f..047562e1df93347f629b529ca0647697
+
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
AtomicReference<S> atomicreference = new AtomicReference();
Thread thread = new io.papermc.paper.util.TickThread(() -> { // Paper - rewrite chunk system
@@ -883,6 +886,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
Thread thread = new Thread(() -> {
@@ -858,6 +861,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa

// CraftBukkit start
private boolean hasStopped = false;
+ public volatile boolean hasFullyShutdown = false; // Paper
private final Object stopLock = new Object();
public final boolean hasStopped() {
synchronized (this.stopLock) {
@@ -897,6 +901,19 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -872,6 +876,19 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
if (this.hasStopped) return;
this.hasStopped = true;
}
Expand All @@ -121,14 +121,13 @@ index 498f06aa1d8b2c20f5bf31d6751f08cf1eb4240f..047562e1df93347f629b529ca0647697
// CraftBukkit end
if (this.metricsRecorder.isRecording()) {
this.cancelRecordingMetrics();
@@ -953,7 +970,19 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.getProfileCache().save(false); // Paper
@@ -955,6 +972,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
// Spigot end
+
+ // Paper start - move final shutdown items here
+ LOGGER.info("Flushing Chunk IO");
io.papermc.paper.chunk.system.io.RegionFileIOThread.close(true); // Paper // Paper - rewrite chunk system
+ // TODO chunk system patch has a line here
+ LOGGER.info("Closing Thread Pool");
+ Util.shutdownExecutors(); // Paper
+ LOGGER.info("Closing Server");
Expand All @@ -141,15 +140,15 @@ index 498f06aa1d8b2c20f5bf31d6751f08cf1eb4240f..047562e1df93347f629b529ca0647697
}

public String getLocalIp() {
@@ -1048,6 +1077,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1047,6 +1076,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa

protected void runServer() {
try {
+ long serverStartTime = Util.getNanos(); // Paper
if (!this.initServer()) {
throw new IllegalStateException("Failed to initialize server");
}
@@ -1057,6 +1087,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1056,6 +1086,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.status = this.buildServerStatus();

// Spigot start
Expand All @@ -168,7 +167,7 @@ index 498f06aa1d8b2c20f5bf31d6751f08cf1eb4240f..047562e1df93347f629b529ca0647697
org.spigotmc.WatchdogThread.hasStarted = true; // Paper
Arrays.fill( recentTps, 20 );
long start = System.nanoTime(), curTime, tickSection = start; // Paper - Further improve server tick loop
@@ -1117,6 +1159,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1110,6 +1152,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
JvmProfiler.INSTANCE.onServerTick(this.averageTickTime);
}
} catch (Throwable throwable) {
Expand All @@ -181,7 +180,7 @@ index 498f06aa1d8b2c20f5bf31d6751f08cf1eb4240f..047562e1df93347f629b529ca0647697
MinecraftServer.LOGGER.error("Encountered an unexpected exception", throwable);
// Spigot Start
if ( throwable.getCause() != null )
@@ -1147,14 +1195,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1140,14 +1188,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.services.profileCache().clearExecutor();
}

Expand All @@ -199,7 +198,7 @@ index 498f06aa1d8b2c20f5bf31d6751f08cf1eb4240f..047562e1df93347f629b529ca0647697
}

}
@@ -1223,6 +1271,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1211,6 +1259,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa

@Override
public TickTask wrapRunnable(Runnable runnable) {
Expand All @@ -212,15 +211,15 @@ index 498f06aa1d8b2c20f5bf31d6751f08cf1eb4240f..047562e1df93347f629b529ca0647697
return new TickTask(this.tickCount, runnable);
}

@@ -1458,6 +1512,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1451,6 +1505,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
try {
crashreport = CrashReport.forThrowable(throwable, "Exception ticking world");
} catch (Throwable t) {
+ if (throwable instanceof ThreadDeath) { throw (ThreadDeath)throwable; } // Paper
throw new RuntimeException("Error generating crash report", t);
}
// Spigot End
@@ -1958,7 +2013,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1964,7 +2019,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa

this.worldData.setDataConfiguration(worlddataconfiguration);
this.resources.managers.updateRegistryTags(this.registryAccess());
Expand All @@ -238,7 +237,7 @@ index 498f06aa1d8b2c20f5bf31d6751f08cf1eb4240f..047562e1df93347f629b529ca0647697
this.functionManager.replaceLibrary(this.resources.managers.getFunctionLibrary());
this.structureTemplateManager.onResourceManagerReload(this.resources.resourceManager);
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index 56b17a1ce545ec43bf588d4ab438440fb829bc97..ba75c854faed13c60ae5464c4685373b99ef42c2 100644
index 6d2f49204e6a8fe8057a0c83f23adae3e1dbf00c..f72c1a4baff6ac9a3b1df83ece3925e2b1678df9 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -269,7 +269,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
Expand All @@ -260,7 +259,7 @@ index 56b17a1ce545ec43bf588d4ab438440fb829bc97..ba75c854faed13c60ae5464c4685373b
}

@Override
@@ -770,7 +771,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -748,7 +749,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@Override
public void stopServer() {
super.stopServer();
Expand All @@ -270,10 +269,10 @@ index 56b17a1ce545ec43bf588d4ab438440fb829bc97..ba75c854faed13c60ae5464c4685373b
}

diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 5b8b345ade30012371bdda744ba82c585f74db07..0d100788312a234616c1401656f09835458e79f6 100644
index 89310108e94f3198c5f4ecd65e414a2c7af262cb..d1e5db7b0b260002198b1262f914d3c5a30cd2d9 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -547,7 +547,7 @@ public abstract class PlayerList {
@@ -534,7 +534,7 @@ public abstract class PlayerList {
this.cserver.getPluginManager().callEvent(playerQuitEvent);
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());

Expand All @@ -295,10 +294,10 @@ index f5829ae484d93b547a5437b85a9621346384a11b..83701fbfaa56a232593ee8f11a3afb89
}

diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 7a1886585bd00dc8213ce22130b8b6fea52c5cf6..52a44510d0499df56d2ebef0963fe8164eda7301 100644
index 495ab82a3a9d47583eb7239730aa78dd51f16fc6..8b0c85d341c75e86421fc7c72aefcce83a165075 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -904,6 +904,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -896,6 +896,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
try {
tickConsumer.accept(entity);
} catch (Throwable throwable) {
Expand All @@ -307,10 +306,10 @@ index 7a1886585bd00dc8213ce22130b8b6fea52c5cf6..52a44510d0499df56d2ebef0963fe816
final String msg = String.format("Entity threw exception at %s:%s,%s,%s", entity.level().getWorld().getName(), entity.getX(), entity.getY(), entity.getZ());
MinecraftServer.LOGGER.error(msg, throwable);
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
index c3760f22fcc56ccb25e3315823054416c2172386..246606164117e8140ab0892ec1326503b414a1ab 100644
index f229838bf0566d61b2716463ff95fcc0b04d2e97..c9a6a56dfd25601bc0a11e5ddb349dba372c0e18 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
@@ -1180,6 +1180,7 @@ public class LevelChunk extends ChunkAccess {
@@ -1091,6 +1091,7 @@ public class LevelChunk extends ChunkAccess {

gameprofilerfiller.pop();
} catch (Throwable throwable) {
Expand All @@ -319,7 +318,7 @@ index c3760f22fcc56ccb25e3315823054416c2172386..246606164117e8140ab0892ec1326503
final String msg = String.format("BlockEntity threw exception at %s:%s,%s,%s", LevelChunk.this.getLevel().getWorld().getName(), this.getPos().getX(), this.getPos().getY(), this.getPos().getZ());
net.minecraft.server.MinecraftServer.LOGGER.error(msg, throwable);
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
index 2badebc0d7954c6d343bfd66dd14dc2d2d4661d7..f847527bf22fa34817dee79e61a47545b1e1f7bc 100644
index 8c9a6e1b34865c3a15eea40637d6a4b540396a5c..c561677e81095ab6735d81a414a249838b135f7a 100644
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
@@ -178,6 +178,36 @@ public class Main {
Expand Down Expand Up @@ -471,26 +470,26 @@ index 14eadb0f81dfad072d82d7793cce1a4dd3f2c5f0..29b39dff0aceaa902f701162a42d3f2f
String[] split = restartScript.split( " " );
if ( split.length > 0 && new File( split[0] ).isFile() )
diff --git a/src/main/java/org/spigotmc/WatchdogThread.java b/src/main/java/org/spigotmc/WatchdogThread.java
index b47d043144c499b1499f6b4be5a16a3f75c9fcb8..a9bd33b58a6a3296b70eaaaea3adbee74724e448 100644
index 06efdd7aa6d35a670e81c4f303618a7ba301396a..e71041d41eae31cce73d8817c4f95f16c8c600aa 100644
--- a/src/main/java/org/spigotmc/WatchdogThread.java
+++ b/src/main/java/org/spigotmc/WatchdogThread.java
@@ -11,6 +11,7 @@ import org.bukkit.Bukkit;
public final class WatchdogThread extends io.papermc.paper.util.TickThread // Paper - rewrite chunk system
public class WatchdogThread extends Thread
{

+ public static final boolean DISABLE_WATCHDOG = Boolean.getBoolean("disable.watchdog"); // Paper
private static WatchdogThread instance;
private long timeoutTime;
private boolean restart;
@@ -39,6 +40,7 @@ public final class WatchdogThread extends io.papermc.paper.util.TickThread // Pa
@@ -39,6 +40,7 @@ public class WatchdogThread extends Thread
{
if ( WatchdogThread.instance == null )
{
+ if (timeoutTime <= 0) timeoutTime = 300; // Paper
WatchdogThread.instance = new WatchdogThread( timeoutTime * 1000L, restart );
WatchdogThread.instance.start();
} else
@@ -70,12 +72,13 @@ public final class WatchdogThread extends io.papermc.paper.util.TickThread // Pa
@@ -70,12 +72,13 @@ public class WatchdogThread extends Thread
// Paper start
Logger log = Bukkit.getServer().getLogger();
long currentTime = WatchdogThread.monotonicMillis();
Expand All @@ -507,7 +506,7 @@ index b47d043144c499b1499f6b4be5a16a3f75c9fcb8..a9bd33b58a6a3296b70eaaaea3adbee7
lastEarlyWarning = currentTime;
if (isLongTimeout) {
// Paper end
@@ -137,9 +140,24 @@ public final class WatchdogThread extends io.papermc.paper.util.TickThread // Pa
@@ -136,9 +139,24 @@ public class WatchdogThread extends Thread

if ( isLongTimeout )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Prevents pathfinding from spamming failures for things such as
arrow attacks.

diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
index 03cc97b13b1b8eb591b563c1eb52355b00ea3bf1..b376670d11088e524ce246f667e580e90cd119a3 100644
index 68edd488087a6ec1e65797cfbd4118bd0efbab50..b37415d45dda8e658c8995a4519e552dc378bb41 100644
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
@@ -192,9 +192,29 @@ public abstract class PathNavigation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ is important because we clone chunk data after reading it for safety.
So, reduce the impact of the clone on GC.

diff --git a/src/main/java/net/minecraft/nbt/CompoundTag.java b/src/main/java/net/minecraft/nbt/CompoundTag.java
index 64765dab6fed87ffdf4af197d8d5f28a04544db0..1d13bc15c56faa69699fb3ad39210233d6b6934d 100644
index 92095b494a0c4fb89b84f0b1c0376615d28e34ce..ad0251b73d21b36bf19e9aa649817b4da2d0a6b4 100644
--- a/src/main/java/net/minecraft/nbt/CompoundTag.java
+++ b/src/main/java/net/minecraft/nbt/CompoundTag.java
@@ -36,7 +36,7 @@ public class CompoundTag implements Tag {
if (i > 512) {
throw new RuntimeException("Tried to read NBT tag with too high complexity, depth > 512");
} else {
- Map<String, Tag> map = Maps.newHashMap();
+ it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<String, Tag> map = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(8, 0.8f); // Paper - reduce memory footprint of NBTTagCompound
@@ -46,7 +46,7 @@ public class CompoundTag implements Tag {

byte b;
while((b = CompoundTag.readNamedTagType(dataInput, nbtAccounter)) != 0) {
@@ -130,7 +130,7 @@ public class CompoundTag implements Tag {
private static CompoundTag loadCompound(DataInput input, NbtAccounter tracker) throws IOException {
tracker.accountBytes(48L);
- Map<String, Tag> map = Maps.newHashMap();
+ it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<String, Tag> map = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(8, 0.8f); // Paper - reduce memory footprint of NBTTagCompound

byte b;
while((b = input.readByte()) != 0) {
@@ -167,7 +167,7 @@ public class CompoundTag implements Tag {
}

public CompoundTag() {
Expand All @@ -29,7 +29,7 @@ index 64765dab6fed87ffdf4af197d8d5f28a04544db0..1d13bc15c56faa69699fb3ad39210233
}

@Override
@@ -449,8 +449,16 @@ public class CompoundTag implements Tag {
@@ -486,8 +486,16 @@ public class CompoundTag implements Tag {

@Override
public CompoundTag copy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Prevent opening inventories when frozen


diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index c7d4341642df2fc847e139cf03992b13645afa3e..0e7f5d780d8c17a68a6d3cf98febad94f63e3f81 100644
index 3ebcbda84de7817ff1aab5cdac6566f9eb05f2dd..06d257ac2d307cdae1c3eeba50f133814c13b181 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -693,7 +693,7 @@ public class ServerPlayer extends Player {
@@ -652,7 +652,7 @@ public class ServerPlayer extends Player {
containerUpdateDelay = this.level().paperConfig().tickRates.containerUpdate;
}
// Paper end
Expand All @@ -17,7 +17,7 @@ index c7d4341642df2fc847e139cf03992b13645afa3e..0e7f5d780d8c17a68a6d3cf98febad94
this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.CANT_USE); // Paper
this.containerMenu = this.inventoryMenu;
}
@@ -1542,7 +1542,7 @@ public class ServerPlayer extends Player {
@@ -1501,7 +1501,7 @@ public class ServerPlayer extends Player {
} else {
// CraftBukkit start
this.containerMenu = container;
Expand All @@ -27,7 +27,7 @@ index c7d4341642df2fc847e139cf03992b13645afa3e..0e7f5d780d8c17a68a6d3cf98febad94
this.initMenu(container);
return OptionalInt.of(this.containerCounter);
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
index 552fb0be2f31bd52a5ae43526d55aa29828f786e..ec7ea1ef632bea761ca8b9603059a12fb72dfa47 100644
index aa131c233ee9d7926ca77e1afedd27baf7639423..872adf91703baa24d67f417e7a45309f92984da9 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
@@ -325,7 +325,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
Expand Down
Loading

0 comments on commit 2bc818e

Please sign in to comment.