2022-06-04 21:48:24 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Tue, 22 Mar 2022 12:44:30 -0700
Subject: [PATCH] Throw exception on world create while being ticked
There are no plans to support creating worlds while worlds are
being ticked themselvess.
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2024-01-18 21:00:40 +00:00
index c1ef4dd08b39adf3ab8dbfe286c6378f3efbf54e..4d4617635c9dc0d011cf8fc57ece6e2300573bad 100644
2022-06-04 21:48:24 +00:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2023-12-06 16:21:56 +00:00
@@ -310,6 +310,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2022-06-04 21:48:24 +00:00
public volatile Thread shutdownThread; // Paper
public volatile boolean abnormalExit = false; // Paper
2024-01-18 17:52:00 +00:00
+ public boolean isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
2022-06-04 21:48:24 +00:00
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
AtomicReference<S> atomicreference = new AtomicReference();
2024-01-14 09:46:04 +00:00
@@ -1633,7 +1634,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2022-09-24 04:48:42 +00:00
this.getFunctions().tick();
MinecraftTimings.commandFunctionsTimer.stopTiming(); // Spigot // Paper
this.profiler.popPush("levels");
- Iterator iterator = this.getAllLevels().iterator();
2024-01-18 17:52:00 +00:00
+ //Iterator iterator = this.getAllLevels().iterator(); // Paper - Throw exception on world create while being ticked; moved down
2022-09-24 04:48:42 +00:00
// CraftBukkit start
// Run tasks that are waiting on processing
2024-01-14 09:46:04 +00:00
@@ -1665,6 +1666,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2022-06-04 21:48:24 +00:00
// Paper end
MinecraftTimings.timeUpdateTimer.stopTiming(); // Spigot // Paper
2024-01-18 17:52:00 +00:00
+ this.isIteratingOverLevels = true; // Paper - Throw exception on world create while being ticked
+ Iterator iterator = this.getAllLevels().iterator(); // Paper - Throw exception on world create while being ticked; move down
2022-06-04 21:48:24 +00:00
while (iterator.hasNext()) {
ServerLevel worldserver = (ServerLevel) iterator.next();
worldserver.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper
2024-01-14 09:46:04 +00:00
@@ -1703,6 +1706,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2022-06-04 21:48:24 +00:00
this.profiler.pop();
worldserver.explosionDensityCache.clear(); // Paper - Optimize explosions
}
2024-01-18 17:52:00 +00:00
+ this.isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
2022-06-04 21:48:24 +00:00
this.profiler.popPush("connection");
2023-12-06 16:21:56 +00:00
MinecraftTimings.connectionTimer.startTiming(); // Spigot // Paper
2022-06-04 21:48:24 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2024-01-18 21:00:40 +00:00
index b76bb0142cbe64064f7835807974414c879f57a5..a12267638500fe5a20f46fb8e0b93c250227c273 100644
2022-06-04 21:48:24 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 02:09:28 +00:00
@@ -874,6 +874,11 @@ public final class CraftServer implements Server {
2022-09-24 05:19:05 +00:00
return new ArrayList<World>(this.worlds.values());
}
+ @Override
+ public boolean isTickingWorlds() {
+ return console.isIteratingOverLevels;
+ }
+
public DedicatedPlayerList getHandle() {
return this.playerList;
}
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 02:09:28 +00:00
@@ -1133,6 +1138,7 @@ public final class CraftServer implements Server {
2022-06-04 21:48:24 +00:00
@Override
public World createWorld(WorldCreator creator) {
2022-08-14 08:03:13 +00:00
Preconditions.checkState(this.console.getAllLevels().iterator().hasNext(), "Cannot create additional worlds on STARTUP");
2022-09-24 05:19:05 +00:00
+ //Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot create a world while worlds are being ticked"); // Paper - Cat - Temp disable. We'll see how this goes.
2023-06-12 23:51:45 +00:00
Preconditions.checkArgument(creator != null, "WorldCreator cannot be null");
2022-06-04 21:48:24 +00:00
String name = creator.name();
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 02:09:28 +00:00
@@ -1310,6 +1316,7 @@ public final class CraftServer implements Server {
2022-07-01 16:14:50 +00:00
@Override
public boolean unloadWorld(World world, boolean save) {
2022-09-24 05:19:05 +00:00
+ //Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot unload a world while worlds are being ticked"); // Paper - Cat - Temp disable. We'll see how this goes.
2022-07-01 16:14:50 +00:00
if (world == null) {
return false;
}