2020-06-10 01:13:51 +00: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
|
2021-03-16 07:19:45 +00:00
|
|
|
index 32e68e403950be62bd0330b268738225c2e70edd..d0c951878600a4227e558bc68d68098c59fb7b2b 100644
|
2020-06-10 01:13:51 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2021-02-21 20:55:01 +00:00
|
|
|
@@ -346,7 +346,7 @@ public final class CraftServer implements Server {
|
2020-06-10 01:13:51 +00:00
|
|
|
ambientSpawn = configuration.getInt("spawn-limits.ambient");
|
|
|
|
console.autosavePeriod = configuration.getInt("ticks-per.autosave");
|
|
|
|
warningState = WarningState.value(configuration.getString("settings.deprecated-verbose"));
|
|
|
|
- TicketType.PLUGIN.loadPeriod = configuration.getInt("chunk-gc.period-in-ticks");
|
|
|
|
+ TicketType.PLUGIN.loadPeriod = Math.min(20, configuration.getInt("chunk-gc.period-in-ticks")); // Paper - cap plugin loads to 1 second
|
|
|
|
minimumAPI = configuration.getString("settings.minimum-api");
|
|
|
|
loadIcon();
|
|
|
|
}
|
2021-02-21 20:55:01 +00:00
|
|
|
@@ -837,7 +837,7 @@ public final class CraftServer implements Server {
|
2020-06-26 16:20:03 +00:00
|
|
|
waterAmbientSpawn = configuration.getInt("spawn-limits.water-ambient");
|
2020-06-10 01:13:51 +00:00
|
|
|
ambientSpawn = configuration.getInt("spawn-limits.ambient");
|
|
|
|
warningState = WarningState.value(configuration.getString("settings.deprecated-verbose"));
|
|
|
|
- TicketType.PLUGIN.loadPeriod = configuration.getInt("chunk-gc.period-in-ticks");
|
|
|
|
+ TicketType.PLUGIN.loadPeriod = Math.min(20, configuration.getInt("chunk-gc.period-in-ticks")); // Paper - cap plugin loads to 1 second
|
|
|
|
minimumAPI = configuration.getString("settings.minimum-api");
|
|
|
|
printSaveWarning = false;
|
|
|
|
console.autosavePeriod = configuration.getInt("ticks-per.autosave");
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2021-04-11 08:49:43 +00:00
|
|
|
index ebd648897e309f10091fef2e24e5a6fd07a1c6e9..d3a1d5e29d01f5c033e5d8ba0998678eba798032 100644
|
2020-06-10 01:13:51 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2021-03-16 15:50:45 +00:00
|
|
|
@@ -30,6 +30,7 @@ import net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect;
|
|
|
|
import net.minecraft.network.protocol.game.PacketPlayOutUpdateTime;
|
|
|
|
import net.minecraft.network.protocol.game.PacketPlayOutWorldEvent;
|
|
|
|
import net.minecraft.resources.MinecraftKey;
|
|
|
|
+import net.minecraft.server.MCUtil;
|
|
|
|
import net.minecraft.server.level.ChunkMapDistance;
|
|
|
|
import net.minecraft.server.level.PlayerChunk;
|
|
|
|
import net.minecraft.server.level.PlayerChunkMap;
|
|
|
|
@@ -407,8 +408,21 @@ public class CraftWorld implements World {
|
2020-06-10 01:13:51 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Chunk getChunkAt(int x, int z) {
|
|
|
|
- return this.world.getChunkProvider().getChunkAt(x, z, true).bukkitChunk;
|
|
|
|
+ // Paper start - add ticket to hold chunk for a little while longer if plugin accesses it
|
2021-03-16 15:50:45 +00:00
|
|
|
+ net.minecraft.world.level.chunk.Chunk chunk = world.getChunkProvider().getChunkAtIfLoadedImmediately(x, z);
|
2020-06-10 01:13:51 +00:00
|
|
|
+ if (chunk == null) {
|
|
|
|
+ addTicket(x, z);
|
|
|
|
+ chunk = this.world.getChunkProvider().getChunkAt(x, z, true);
|
|
|
|
+ }
|
|
|
|
+ return chunk.bukkitChunk;
|
|
|
|
+ // Paper end
|
2021-03-16 07:19:45 +00:00
|
|
|
+ }
|
|
|
|
+
|
2020-06-10 01:13:51 +00:00
|
|
|
+ // Paper start
|
|
|
|
+ private void addTicket(int x, int z) {
|
|
|
|
+ MCUtil.MAIN_EXECUTOR.execute(() -> world.getChunkProvider().addTicket(TicketType.PLUGIN, new ChunkCoordIntPair(x, z), 0, Unit.INSTANCE)); // Paper
|
2021-03-16 07:19:45 +00:00
|
|
|
}
|
2020-06-10 01:13:51 +00:00
|
|
|
+ // Paper end
|
2021-03-16 07:19:45 +00:00
|
|
|
|
2020-06-10 01:13:51 +00:00
|
|
|
@Override
|
|
|
|
public Chunk getChunkAt(Block block) {
|
2021-03-16 15:50:45 +00:00
|
|
|
@@ -483,7 +497,7 @@ public class CraftWorld implements World {
|
2020-06-23 08:30:45 +00:00
|
|
|
public boolean unloadChunkRequest(int x, int z) {
|
2020-06-10 01:13:51 +00:00
|
|
|
org.spigotmc.AsyncCatcher.catchOp("chunk unload"); // Spigot
|
2020-06-23 08:30:45 +00:00
|
|
|
if (isChunkLoaded(x, z)) {
|
|
|
|
- world.getChunkProvider().removeTicket(TicketType.PLUGIN, new ChunkCoordIntPair(x, z), 1, Unit.INSTANCE);
|
|
|
|
+ world.getChunkProvider().removeTicket(TicketType.PLUGIN, new ChunkCoordIntPair(x, z), 0, Unit.INSTANCE); // Paper
|
2020-06-10 01:13:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2021-03-16 15:50:45 +00:00
|
|
|
@@ -560,9 +574,12 @@ public class CraftWorld implements World {
|
2020-06-10 01:13:51 +00:00
|
|
|
org.spigotmc.AsyncCatcher.catchOp("chunk load"); // Spigot
|
|
|
|
// Paper start - Optimize this method
|
|
|
|
ChunkCoordIntPair chunkPos = new ChunkCoordIntPair(x, z);
|
|
|
|
+ IChunkAccess immediate = world.getChunkProvider().getChunkAtIfLoadedImmediately(x, z); // Paper
|
|
|
|
+ if (immediate != null) return true; // Paper
|
|
|
|
|
|
|
|
if (!generate) {
|
|
|
|
- IChunkAccess immediate = world.getChunkProvider().getChunkAtImmediately(x, z);
|
2021-03-16 07:19:45 +00:00
|
|
|
+
|
2020-06-10 01:13:51 +00:00
|
|
|
+ //IChunkAccess immediate = world.getChunkProvider().getChunkAtImmediately(x, z); // Paper
|
|
|
|
if (immediate == null) {
|
|
|
|
immediate = world.getChunkProvider().playerChunkMap.getUnloadingChunk(x, z);
|
|
|
|
}
|
2021-03-16 15:50:45 +00:00
|
|
|
@@ -570,7 +587,7 @@ public class CraftWorld implements World {
|
2021-03-16 07:19:45 +00:00
|
|
|
if (!(immediate instanceof ProtoChunkExtension) && !(immediate instanceof net.minecraft.world.level.chunk.Chunk)) {
|
2020-06-10 01:13:51 +00:00
|
|
|
return false; // not full status
|
|
|
|
}
|
|
|
|
- world.getChunkProvider().addTicket(TicketType.PLUGIN, chunkPos, 1, Unit.INSTANCE);
|
|
|
|
+ world.getChunkProvider().addTicket(TicketType.PLUGIN, chunkPos, 0, Unit.INSTANCE); // Paper
|
|
|
|
world.getChunkAt(x, z); // make sure we're at ticket level 32 or lower
|
|
|
|
return true;
|
|
|
|
}
|
2021-03-16 15:50:45 +00:00
|
|
|
@@ -597,7 +614,7 @@ public class CraftWorld implements World {
|
2020-06-10 01:13:51 +00:00
|
|
|
// we do this so we do not re-read the chunk data on disk
|
|
|
|
}
|
|
|
|
|
|
|
|
- world.getChunkProvider().addTicket(TicketType.PLUGIN, chunkPos, 1, Unit.INSTANCE);
|
|
|
|
+ world.getChunkProvider().addTicket(TicketType.PLUGIN, chunkPos, 0, Unit.INSTANCE); // Paper
|
|
|
|
world.getChunkProvider().getChunkAt(x, z, ChunkStatus.FULL, true);
|
|
|
|
return true;
|
|
|
|
// Paper end
|
2021-04-11 08:49:43 +00:00
|
|
|
@@ -2554,6 +2571,7 @@ public class CraftWorld implements World {
|
2020-06-10 01:13:51 +00:00
|
|
|
}
|
|
|
|
return this.world.getChunkProvider().getChunkAtAsynchronously(x, z, gen, urgent).thenComposeAsync((either) -> {
|
2021-03-16 07:19:45 +00:00
|
|
|
net.minecraft.world.level.chunk.Chunk chunk = (net.minecraft.world.level.chunk.Chunk) either.left().orElse(null);
|
2020-06-10 01:13:51 +00:00
|
|
|
+ if (chunk != null) addTicket(x, z); // Paper
|
|
|
|
return CompletableFuture.completedFuture(chunk == null ? null : chunk.getBukkitChunk());
|
2021-03-16 07:19:45 +00:00
|
|
|
}, net.minecraft.server.MinecraftServer.getServer());
|
2020-06-10 01:13:51 +00:00
|
|
|
}
|