Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 02:50:09 +01:00
Add method isTickingWorlds to Bukkit (#8316)
Co-authored-by: Shane Freeder <theboyetronic@gmail.com> Also, restores un/loading worlds mid tick. This will not be officially supported API contract that such a routine is safe, and these restrictions may be restored in the future.
Dieser Commit ist enthalten in:
Ursprung
6736f390a2
Commit
4d52f1d247
117
patches/api/0383-Add-method-isTickingWorlds-to-Bukkit.patch
Normale Datei
117
patches/api/0383-Add-method-isTickingWorlds-to-Bukkit.patch
Normale Datei
@ -0,0 +1,117 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: BuildTools <46540330+willkroboth@users.noreply.github.com>
|
||||
Date: Fri, 19 Aug 2022 16:11:51 -0400
|
||||
Subject: [PATCH] Add method isTickingWorlds() to Bukkit.
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
|
||||
index 840aaf9e8fc828b5a7ea02252038c6524680f2e0..b5a7d6ab4e458843f2e163bf06b5668627012f91 100644
|
||||
--- a/src/main/java/org/bukkit/Bukkit.java
|
||||
+++ b/src/main/java/org/bukkit/Bukkit.java
|
||||
@@ -753,12 +753,26 @@ public final class Bukkit {
|
||||
return server.getWorlds();
|
||||
}
|
||||
|
||||
+ // Paper start
|
||||
+ /**
|
||||
+ * Gets whether the worlds are being ticked right not or not.
|
||||
+ *
|
||||
+ * @return true if the worlds are being ticked, false otherwise.
|
||||
+ */
|
||||
+ public static boolean isTickingWorlds(){
|
||||
+ return server.isTickingWorlds();
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
/**
|
||||
* Creates or loads a world with the given name using the specified
|
||||
* options.
|
||||
* <p>
|
||||
* If the world is already loaded, it will just return the equivalent of
|
||||
* getWorld(creator.name()).
|
||||
+ * <p>
|
||||
+ * Do note that un/loading worlds mid-tick may have potential side effects, we strongly recommend
|
||||
+ * ensuring that you're not loading worlds midtick by checking {@link Bukkit#isTickingWorlds()}
|
||||
*
|
||||
* @param creator the options to use when creating the world
|
||||
* @return newly created or loaded world
|
||||
@@ -770,6 +784,9 @@ public final class Bukkit {
|
||||
|
||||
/**
|
||||
* Unloads a world with the given name.
|
||||
+ * <p>
|
||||
+ * Do note that un/loading worlds mid-tick may have potential side effects, we strongly recommend
|
||||
+ * ensuring that you're not loading worlds midtick by checking {@link Bukkit#isTickingWorlds()}
|
||||
*
|
||||
* @param name Name of the world to unload
|
||||
* @param save whether to save the chunks before unloading
|
||||
@@ -781,6 +798,9 @@ public final class Bukkit {
|
||||
|
||||
/**
|
||||
* Unloads the given world.
|
||||
+ * <p>
|
||||
+ * Do note that un/loading worlds mid-tick may have potential side effects, we strongly recommend
|
||||
+ * ensuring that you're not loading worlds midtick by checking {@link Bukkit#isTickingWorlds()}
|
||||
*
|
||||
* @param world the world to unload
|
||||
* @param save whether to save the chunks before unloading
|
||||
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
||||
index da5cab4246bd253fcc4e4d9574bdae1867ebb5ab..1982fc2d7f1cb80d3e324ee283211b251a976c6e 100644
|
||||
--- a/src/main/java/org/bukkit/Server.java
|
||||
+++ b/src/main/java/org/bukkit/Server.java
|
||||
@@ -622,34 +622,55 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
|
||||
@NotNull
|
||||
public List<World> getWorlds();
|
||||
|
||||
+ // Paper start
|
||||
+ /**
|
||||
+ * Gets whether the worlds are being ticked right not or not.
|
||||
+ *
|
||||
+ * @return true if the worlds are being ticked, false otherwise.
|
||||
+ */
|
||||
+ public boolean isTickingWorlds();
|
||||
+ // Paper end
|
||||
+
|
||||
/**
|
||||
* Creates or loads a world with the given name using the specified
|
||||
* options.
|
||||
* <p>
|
||||
* If the world is already loaded, it will just return the equivalent of
|
||||
* getWorld(creator.name()).
|
||||
+ * <p>
|
||||
+ * Do note that un/loading worlds mid-tick may have potential side effects, we strongly recommend
|
||||
+ * ensuring that you're not loading worlds midtick by checking {@link Bukkit#isTickingWorlds()}
|
||||
*
|
||||
* @param creator the options to use when creating the world
|
||||
* @return newly created or loaded world
|
||||
+ * @throws IllegalStateException when {@link #isTickingWorlds() isTickingWorlds} is true
|
||||
*/
|
||||
@Nullable
|
||||
public World createWorld(@NotNull WorldCreator creator);
|
||||
|
||||
/**
|
||||
* Unloads a world with the given name.
|
||||
+ * <p>
|
||||
+ * Do note that un/loading worlds mid-tick may have potential side effects, we strongly recommend
|
||||
+ * ensuring that you're not loading worlds midtick by checking {@link Bukkit#isTickingWorlds()}
|
||||
*
|
||||
* @param name Name of the world to unload
|
||||
* @param save whether to save the chunks before unloading
|
||||
* @return true if successful, false otherwise
|
||||
+ * @throws IllegalStateException when {@link #isTickingWorlds() isTickingWorlds} is true
|
||||
*/
|
||||
public boolean unloadWorld(@NotNull String name, boolean save);
|
||||
|
||||
/**
|
||||
* Unloads the given world.
|
||||
+ * <p>
|
||||
+ * Do note that un/loading worlds mid-tick may have potential side effects, we strongly recommend
|
||||
+ * ensuring that you're not loading worlds midtick by checking {@link Bukkit#isTickingWorlds()}
|
||||
*
|
||||
* @param world the world to unload
|
||||
* @param save whether to save the chunks before unloading
|
||||
* @return true if successful, false otherwise
|
||||
+ * @throws IllegalStateException when {@link #isTickingWorlds() isTickingWorlds} is true
|
||||
*/
|
||||
public boolean unloadWorld(@NotNull World world, boolean save);
|
||||
|
@ -45,22 +45,34 @@ index 4d920031300a9801debc2eb39a4d3cb9d8fbb330..f1e14f7850c0a64128839285f09e2aa3
|
||||
this.profiler.popPush("connection");
|
||||
MinecraftTimings.connectionTimer.startTiming(); // Spigot
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
index c75e3cd197bee7caeef3a55b2746c15de3c0c3e4..61b9d44e4edc4cb6ffbd8bf99e8e098bcc9957b3 100644
|
||||
index c75e3cd197bee7caeef3a55b2746c15de3c0c3e4..19a98e502b4ba49485fa3e51c48309a06ded5a9d 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -1139,6 +1139,7 @@ public final class CraftServer implements Server {
|
||||
@@ -855,6 +855,11 @@ public final class CraftServer implements Server {
|
||||
return new ArrayList<World>(this.worlds.values());
|
||||
}
|
||||
|
||||
+ @Override
|
||||
+ public boolean isTickingWorlds() {
|
||||
+ return console.isIteratingOverLevels;
|
||||
+ }
|
||||
+
|
||||
public DedicatedPlayerList getHandle() {
|
||||
return this.playerList;
|
||||
}
|
||||
@@ -1139,6 +1144,7 @@ public final class CraftServer implements Server {
|
||||
@Override
|
||||
public World createWorld(WorldCreator creator) {
|
||||
Preconditions.checkState(this.console.getAllLevels().iterator().hasNext(), "Cannot create additional worlds on STARTUP");
|
||||
+ Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot create a world while worlds are being ticked"); // Paper
|
||||
+ //Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot create a world while worlds are being ticked"); // Paper - Cat - Temp disable. We'll see how this goes.
|
||||
Validate.notNull(creator, "Creator may not be null");
|
||||
|
||||
String name = creator.name();
|
||||
@@ -1263,6 +1264,7 @@ public final class CraftServer implements Server {
|
||||
@@ -1263,6 +1269,7 @@ public final class CraftServer implements Server {
|
||||
|
||||
@Override
|
||||
public boolean unloadWorld(World world, boolean save) {
|
||||
+ Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot unload a world while worlds are being ticked"); // Paper
|
||||
+ //Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot unload a world while worlds are being ticked"); // Paper - Cat - Temp disable. We'll see how this goes.
|
||||
if (world == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -20,10 +20,10 @@ index c0195f73cd2c8721e882c681eaead65471710081..861b348f73867af3199f1cc0dab1ddd4
|
||||
Date date = new Date();
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
index 61b9d44e4edc4cb6ffbd8bf99e8e098bcc9957b3..3c9ba17cd0f016a21f56c6b6f8861c512734637a 100644
|
||||
index 19a98e502b4ba49485fa3e51c48309a06ded5a9d..df0472f275b4fa3a1088db84712a39ea0257f17e 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -1758,7 +1758,7 @@ public final class CraftServer implements Server {
|
||||
@@ -1763,7 +1763,7 @@ public final class CraftServer implements Server {
|
||||
// Paper end
|
||||
Set<CommandSender> recipients = new HashSet<>();
|
||||
for (Permissible permissible : this.getPluginManager().getPermissionSubscriptions(permission)) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren