mirror of
https://github.com/PaperMC/Paper.git
synced 2024-09-12 15:08:27 +02:00
Upstream has released updates that appears 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: f009c3dd SPIGOT-5810, SPIGOT-5835: 'Better' handling of Player.isOnGround e677c370 Update ECJ version 5058a35d SPIGOT-5860: Item.setItemStack should be NotNull CraftBukkit Changes:d77f4d9b
SPIGOT-5810, SPIGOT-5835: 'Better' handling of Player.isOnGround53c95627
SPIGOT-5865: Piglin does not trigger EntityPickupItemEvent2ab04d24
Update ECJ version7884e079
SPIGOT-5868: Blocks do not tick in custom nether / end2a848286
SPIGOT-5863: Don't check colour in scoreboard length validationf2cbce30
SPIGOT-5866: Beehive unknown TargetReason Spigot Changes: ad703da0 SPIGOT-5870: /plugins "website" field shows "version" 1a27cfd8 #98: Improve output of /plugins command using text components 732d5bab Disable checkstyle in Spigot blocks 0199a9a6 #97: Add Memory Usage to Ticks Per Second Command. 33ea98fc SPIGOT-5858: NPE: Joining the server with an invalid dimension
123 lines
6.8 KiB
Diff
123 lines
6.8 KiB
Diff
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
|
|
index fe4302431ab15593bf8eae5cc09915994a6fd973..25e01267888762826ffaf93711bdc7952c36da18 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -344,7 +344,7 @@ public final class CraftServer implements Server {
|
|
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();
|
|
}
|
|
@@ -827,7 +827,7 @@ public final class CraftServer implements Server {
|
|
waterAmbientSpawn = configuration.getInt("spawn-limits.water-ambient");
|
|
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
|
|
index b973bd8f60412232df53ac52d97135de6a6f083b..fb24b9d072ff3f57cbd40609b1550ed552ba8bd8 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -401,9 +401,22 @@ public class CraftWorld implements World {
|
|
|
|
@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
|
|
+ net.minecraft.server.Chunk chunk = world.getChunkProvider().getChunkAtIfLoadedImmediately(x, z);
|
|
+ if (chunk == null) {
|
|
+ addTicket(x, z);
|
|
+ chunk = this.world.getChunkProvider().getChunkAt(x, z, true);
|
|
+ }
|
|
+ return chunk.bukkitChunk;
|
|
+ // Paper end
|
|
}
|
|
|
|
+ // 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
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public Chunk getChunkAt(Block block) {
|
|
Preconditions.checkArgument(block != null, "null block");
|
|
@@ -477,7 +490,7 @@ public class CraftWorld implements World {
|
|
public boolean unloadChunkRequest(int x, int z) {
|
|
org.spigotmc.AsyncCatcher.catchOp("chunk unload"); // Spigot
|
|
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
|
|
}
|
|
|
|
return true;
|
|
@@ -554,10 +567,12 @@ public class CraftWorld implements World {
|
|
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);
|
|
+ //IChunkAccess immediate = world.getChunkProvider().getChunkAtImmediately(x, z); // Paper
|
|
if (immediate == null) {
|
|
immediate = world.getChunkProvider().playerChunkMap.getUnloadingChunk(x, z);
|
|
}
|
|
@@ -565,7 +580,7 @@ public class CraftWorld implements World {
|
|
if (!(immediate instanceof ProtoChunkExtension) && !(immediate instanceof net.minecraft.server.Chunk)) {
|
|
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;
|
|
}
|
|
@@ -592,7 +607,7 @@ public class CraftWorld implements World {
|
|
// 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
|
|
@@ -2517,6 +2532,7 @@ public class CraftWorld implements World {
|
|
}
|
|
return this.world.getChunkProvider().getChunkAtAsynchronously(x, z, gen, urgent).thenComposeAsync((either) -> {
|
|
net.minecraft.server.Chunk chunk = (net.minecraft.server.Chunk) either.left().orElse(null);
|
|
+ if (chunk != null) addTicket(x, z); // Paper
|
|
return CompletableFuture.completedFuture(chunk == null ? null : chunk.getBukkitChunk());
|
|
}, MinecraftServer.getServer());
|
|
}
|