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
|
2022-06-07 19:03:07 +02:00
|
|
|
index 0c736a05aaaaaaba65730ca9c731045ac1c9338c..212e43114e4797669338ffdd47548d0100365380 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
|
2022-04-16 10:29:50 +02:00
|
|
|
@@ -359,7 +359,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
|
|
|
|
this.minimumAPI = this.configuration.getString("settings.minimum-api");
|
|
|
|
this.loadIcon();
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
2022-04-16 10:29:50 +02:00
|
|
|
@@ -925,7 +925,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
|
2021-06-14 10:37:14 +02:00
|
|
|
this.minimumAPI = this.configuration.getString("settings.minimum-api");
|
|
|
|
this.printSaveWarning = false;
|
|
|
|
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
|
2022-06-02 04:08:51 +02:00
|
|
|
index 6bdf3679ea9461475b139a0622857b1dc56ea5b2..3c3959240c72fe705db5ee79cf8faaaddd361ee9 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
|
2022-05-17 11:51:46 +02:00
|
|
|
@@ -277,8 +277,21 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Chunk getChunkAt(int x, int z) {
|
|
|
|
- return this.world.getChunkSource().getChunk(x, z, true).bukkitChunk;
|
|
|
|
+ // Paper start - add ticket to hold chunk for a little while longer if plugin accesses it
|
|
|
|
+ net.minecraft.world.level.chunk.LevelChunk chunk = world.getChunkSource().getChunkAtIfLoadedImmediately(x, z);
|
|
|
|
+ if (chunk == null) {
|
|
|
|
+ addTicket(x, z);
|
|
|
|
+ chunk = this.world.getChunkSource().getChunk(x, z, true);
|
|
|
|
+ }
|
|
|
|
+ return chunk.bukkitChunk;
|
|
|
|
+ // Paper end
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Paper start
|
|
|
|
+ private void addTicket(int x, int z) {
|
2021-06-14 10:37:14 +02:00
|
|
|
+ net.minecraft.server.MCUtil.MAIN_EXECUTOR.execute(() -> world.getChunkSource().addRegionTicket(TicketType.PLUGIN, new ChunkPos(x, z), 0, Unit.INSTANCE)); // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Chunk getChunkAt(Block block) {
|
2022-05-17 11:51:46 +02:00
|
|
|
@@ -345,7 +358,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;
|
2022-06-02 04:08:51 +02:00
|
|
|
@@ -428,9 +441,12 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2021-06-11 14:02:28 +02:00
|
|
|
org.spigotmc.AsyncCatcher.catchOp("chunk load"); // Spigot
|
|
|
|
// Paper start - Optimize this method
|
|
|
|
ChunkPos chunkPos = new ChunkPos(x, z);
|
|
|
|
+ ChunkAccess immediate = world.getChunkSource().getChunkAtIfLoadedImmediately(x, z); // Paper
|
|
|
|
+ if (immediate != null) return true; // Paper
|
|
|
|
|
|
|
|
if (!generate) {
|
|
|
|
- ChunkAccess immediate = world.getChunkSource().getChunkAtImmediately(x, z);
|
|
|
|
+
|
|
|
|
+ //IChunkAccess immediate = world.getChunkProvider().getChunkAtImmediately(x, z); // Paper
|
|
|
|
if (immediate == null) {
|
|
|
|
immediate = world.getChunkSource().chunkMap.getUnloadingChunk(x, z);
|
|
|
|
}
|
2022-06-02 04:08:51 +02:00
|
|
|
@@ -438,7 +454,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2021-06-11 14:02:28 +02:00
|
|
|
if (!(immediate instanceof ImposterProtoChunk) && !(immediate instanceof net.minecraft.world.level.chunk.LevelChunk)) {
|
|
|
|
return false; // not full status
|
|
|
|
}
|
|
|
|
- world.getChunkSource().addRegionTicket(TicketType.PLUGIN, chunkPos, 1, Unit.INSTANCE);
|
|
|
|
+ world.getChunkSource().addRegionTicket(TicketType.PLUGIN, chunkPos, 0, Unit.INSTANCE); // Paper
|
|
|
|
world.getChunk(x, z); // make sure we're at ticket level 32 or lower
|
|
|
|
return true;
|
|
|
|
}
|
2022-06-02 04:08:51 +02:00
|
|
|
@@ -464,7 +480,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2021-06-11 14:02:28 +02:00
|
|
|
// we do this so we do not re-read the chunk data on disk
|
|
|
|
}
|
|
|
|
|
|
|
|
- world.getChunkSource().addRegionTicket(TicketType.PLUGIN, chunkPos, 1, Unit.INSTANCE);
|
|
|
|
+ world.getChunkSource().addRegionTicket(TicketType.PLUGIN, chunkPos, 0, Unit.INSTANCE); // Paper
|
|
|
|
world.getChunkSource().getChunk(x, z, ChunkStatus.FULL, true);
|
|
|
|
return true;
|
|
|
|
// Paper end
|
2022-06-02 04:08:51 +02:00
|
|
|
@@ -1984,6 +2000,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2021-06-14 10:37:14 +02:00
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
return this.world.getChunkSource().getChunkAtAsynchronously(x, z, gen, urgent).thenComposeAsync((either) -> {
|
|
|
|
net.minecraft.world.level.chunk.LevelChunk chunk = (net.minecraft.world.level.chunk.LevelChunk) either.left().orElse(null);
|
|
|
|
+ if (chunk != null) addTicket(x, z); // Paper
|
2021-06-14 10:37:14 +02:00
|
|
|
return java.util.concurrent.CompletableFuture.completedFuture(chunk == null ? null : chunk.getBukkitChunk());
|
2021-06-11 14:02:28 +02:00
|
|
|
}, net.minecraft.server.MinecraftServer.getServer());
|
|
|
|
}
|