2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Tue, 9 Jun 2020 03:33:03 -0400
|
|
|
|
Subject: [PATCH] Add Plugin Tickets to API Chunk Methods
|
|
|
|
|
|
|
|
Like previous versions, plugins loading chunks kept them loaded until
|
|
|
|
they garbage collected to avoid constant spamming of chunk loads
|
|
|
|
|
|
|
|
This adds tickets to a few more places so that they can be unloaded.
|
|
|
|
|
|
|
|
Additionally, this drops their ticket level to BORDER so they wont be ticking
|
|
|
|
so they will just sit inactive instead.
|
|
|
|
|
|
|
|
Using .loadChunk to keep a chunk ticking was a horrible idea for upstream
|
|
|
|
when we have TWO methods that are able to do that already in the API.
|
|
|
|
|
|
|
|
Also reduce their collection count down to a maximum of 1 second. Barely
|
|
|
|
anyone knows what chunk-gc is in bukkit.yml as its less relevant now, and
|
|
|
|
since this wasn't spigot behavior, this is safe to mostly ignore (unless someone
|
|
|
|
wants it to collect even faster, they can restore that setting back to 1 instead of 20+)
|
|
|
|
|
|
|
|
Not adding it to .getType() though to keep behavior consistent with vanilla for performance reasons.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2024-11-11 20:17:36 +01:00
|
|
|
index 9905555f249db72649bde8401835dd816ed7b428..972e3a1de1d289f82156097a9bf0faf03cb4ff42 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2024-10-27 18:11:15 +01:00
|
|
|
@@ -382,7 +382,7 @@ public final class CraftServer implements Server {
|
2022-02-12 14:20:33 +01:00
|
|
|
this.overrideSpawnLimits();
|
2021-06-14 10:37:14 +02:00
|
|
|
console.autosavePeriod = this.configuration.getInt("ticks-per.autosave");
|
|
|
|
this.warningState = WarningState.value(this.configuration.getString("settings.deprecated-verbose"));
|
|
|
|
- TicketType.PLUGIN.timeout = this.configuration.getInt("chunk-gc.period-in-ticks");
|
|
|
|
+ TicketType.PLUGIN.timeout = Math.min(20, this.configuration.getInt("chunk-gc.period-in-ticks")); // Paper - cap plugin loads to 1 second
|
2024-04-24 08:44:48 +02:00
|
|
|
this.minimumAPI = ApiVersion.getOrCreateVersion(this.configuration.getString("settings.minimum-api"));
|
2021-06-14 10:37:14 +02:00
|
|
|
this.loadIcon();
|
2024-06-13 16:45:27 +02:00
|
|
|
this.loadCompatibilities();
|
2024-10-27 18:11:15 +01:00
|
|
|
@@ -978,7 +978,7 @@ public final class CraftServer implements Server {
|
2022-02-12 14:20:33 +01:00
|
|
|
this.console.setMotd(config.motd);
|
|
|
|
this.overrideSpawnLimits();
|
2021-06-14 10:37:14 +02:00
|
|
|
this.warningState = WarningState.value(this.configuration.getString("settings.deprecated-verbose"));
|
|
|
|
- TicketType.PLUGIN.timeout = this.configuration.getInt("chunk-gc.period-in-ticks");
|
2021-06-11 14:02:28 +02:00
|
|
|
+ TicketType.PLUGIN.timeout = Math.min(20, configuration.getInt("chunk-gc.period-in-ticks")); // Paper - cap plugin loads to 1 second
|
2024-04-24 08:44:48 +02:00
|
|
|
this.minimumAPI = ApiVersion.getOrCreateVersion(this.configuration.getString("settings.minimum-api"));
|
2021-06-14 10:37:14 +02:00
|
|
|
this.printSaveWarning = false;
|
2023-10-27 01:34:58 +02:00
|
|
|
this.console.autosavePeriod = this.configuration.getInt("ticks-per.autosave");
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2024-11-11 20:17:36 +01:00
|
|
|
index 93d1c641a6fa063f3c5a4b9b2d9a15071ae7de01..5ca7db643a1616df57be114faf9ce2e33e8d4eb8 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2024-11-11 20:17:36 +01:00
|
|
|
@@ -262,7 +262,13 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Chunk getChunkAt(int x, int z) {
|
2023-04-07 20:39:13 +02:00
|
|
|
- net.minecraft.world.level.chunk.LevelChunk chunk = (net.minecraft.world.level.chunk.LevelChunk) this.world.getChunk(x, z, ChunkStatus.FULL, true);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper start - add ticket to hold chunk for a little while longer if plugin accesses it
|
2023-04-07 20:39:13 +02:00
|
|
|
+ net.minecraft.world.level.chunk.LevelChunk chunk = this.world.getChunkSource().getChunkAtIfLoadedImmediately(x, z);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (chunk == null) {
|
2023-04-07 20:39:13 +02:00
|
|
|
+ this.addTicket(x, z);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ chunk = this.world.getChunkSource().getChunk(x, z, true);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2023-04-07 20:39:13 +02:00
|
|
|
return new CraftChunk(chunk);
|
|
|
|
}
|
|
|
|
|
2024-11-11 20:17:36 +01:00
|
|
|
@@ -276,6 +282,12 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2023-04-07 20:39:13 +02:00
|
|
|
return new CraftChunk(this.getHandle(), x, z);
|
|
|
|
}
|
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper start
|
|
|
|
+ private void addTicket(int x, int z) {
|
2023-04-07 20:39:13 +02:00
|
|
|
+ io.papermc.paper.util.MCUtil.MAIN_EXECUTOR.execute(() -> this.world.getChunkSource().addRegionTicket(TicketType.PLUGIN, new ChunkPos(x, z), 0, Unit.INSTANCE)); // Paper
|
|
|
|
+ }
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper end
|
2023-04-07 20:39:13 +02:00
|
|
|
+
|
2021-06-11 14:02:28 +02:00
|
|
|
@Override
|
|
|
|
public Chunk getChunkAt(Block block) {
|
2023-04-07 20:39:13 +02:00
|
|
|
Preconditions.checkArgument(block != null, "null block");
|
2024-11-11 20:17:36 +01:00
|
|
|
@@ -327,7 +339,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2021-06-11 14:02:28 +02:00
|
|
|
public boolean unloadChunkRequest(int x, int z) {
|
|
|
|
org.spigotmc.AsyncCatcher.catchOp("chunk unload"); // Spigot
|
2021-06-14 10:37:14 +02:00
|
|
|
if (this.isChunkLoaded(x, z)) {
|
|
|
|
- this.world.getChunkSource().removeRegionTicket(TicketType.PLUGIN, new ChunkPos(x, z), 1, Unit.INSTANCE);
|
|
|
|
+ this.world.getChunkSource().removeRegionTicket(TicketType.PLUGIN, new ChunkPos(x, z), 0, Unit.INSTANCE); // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2024-11-11 20:17:36 +01:00
|
|
|
@@ -439,7 +451,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2024-01-23 15:43:48 +01:00
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2024-01-23 15:43:48 +01:00
|
|
|
if (chunk instanceof net.minecraft.world.level.chunk.LevelChunk) {
|
|
|
|
- this.world.getChunkSource().addRegionTicket(TicketType.PLUGIN, new ChunkPos(x, z), 1, Unit.INSTANCE);
|
|
|
|
+ this.world.getChunkSource().addRegionTicket(TicketType.PLUGIN, new ChunkPos(x, z), 0, Unit.INSTANCE); // Paper
|
|
|
|
return true;
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
2024-11-11 20:17:36 +01:00
|
|
|
@@ -2248,6 +2260,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2024-07-17 19:24:53 +02:00
|
|
|
ca.spottedleaf.moonrise.common.util.ChunkSystem.scheduleChunkLoad(this.getHandle(), x, z, gen, ChunkStatus.FULL, true, priority, (c) -> {
|
2022-09-01 18:51:59 +02:00
|
|
|
net.minecraft.server.MinecraftServer.getServer().scheduleOnMain(() -> {
|
|
|
|
net.minecraft.world.level.chunk.LevelChunk chunk = (net.minecraft.world.level.chunk.LevelChunk)c;
|
2023-04-07 20:39:13 +02:00
|
|
|
+ if (chunk != null) this.addTicket(x, z); // Paper
|
|
|
|
ret.complete(chunk == null ? null : new CraftChunk(chunk));
|
2022-09-01 18:51:59 +02:00
|
|
|
});
|
|
|
|
});
|