aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNassim Jahnke <[email protected]>2024-12-17 21:40:20 +0100
committerNassim Jahnke <[email protected]>2024-12-17 21:40:20 +0100
commitd94e258d01f3b9eb9fedab0ef492021756e296a2 (patch)
treefc1fc6a82bf168b7b367b624008b2db7cf3aa3a5
parent88b2981e09768efa48fb5e8e3bcb05c562883520 (diff)
downloadPaper-d94e258d01f3b9eb9fedab0ef492021756e296a2.tar.gz
Paper-d94e258d01f3b9eb9fedab0ef492021756e296a2.zip
Clean up add/removePluginChunkTicket
No need to be that invasive to Vanilla code for simple, non-hot and small collection checks
-rw-r--r--paper-server/patches/sources/net/minecraft/server/level/DistanceManager.java.patch81
-rw-r--r--paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java11
2 files changed, 35 insertions, 57 deletions
diff --git a/paper-server/patches/sources/net/minecraft/server/level/DistanceManager.java.patch b/paper-server/patches/sources/net/minecraft/server/level/DistanceManager.java.patch
index f2b1b6a10a..eadab866cb 100644
--- a/paper-server/patches/sources/net/minecraft/server/level/DistanceManager.java.patch
+++ b/paper-server/patches/sources/net/minecraft/server/level/DistanceManager.java.patch
@@ -13,71 +13,50 @@
for (ChunkHolder chunkHolder : this.chunksToUpdateFutures) {
chunkHolder.updateHighestAllowedStatus(chunkMap);
}
-@@ -143,7 +_,7 @@
- }
- }
-
-- void addTicket(long chunkPos, Ticket<?> ticket) {
-+ boolean addTicket(long chunkPos, Ticket<?> ticket) { // CraftBukkit - void -> boolean
- SortedArraySet<Ticket<?>> tickets = this.getTickets(chunkPos);
- int ticketLevelAt = getTicketLevelAt(tickets);
- Ticket<?> ticket1 = tickets.addOrGet(ticket);
-@@ -151,11 +_,14 @@
- if (ticket.getTicketLevel() < ticketLevelAt) {
- this.ticketTracker.update(chunkPos, ticket.getTicketLevel(), true);
- }
-+ return ticket == ticket1; // CraftBukkit
- }
-
-- void removeTicket(long chunkPos, Ticket<?> ticket) {
-+ boolean removeTicket(long chunkPos, Ticket<?> ticket) { // CraftBukkit - void -> boolean
- SortedArraySet<Ticket<?>> tickets = this.getTickets(chunkPos);
-+ boolean removed = false; // CraftBukkit
- if (tickets.remove(ticket)) {
-+ removed = true; // CraftBukkit
- }
-
- if (tickets.isEmpty()) {
-@@ -163,6 +_,7 @@
- }
-
- this.ticketTracker.update(chunkPos, getTicketLevelAt(tickets), false);
-+ return removed; // CraftBukkit
- }
-
- public <T> void addTicket(TicketType<T> type, ChunkPos pos, int level, T value) {
-@@ -175,17 +_,29 @@
- }
-
+@@ -177,16 +_,42 @@
public <T> void addRegionTicket(TicketType<T> type, ChunkPos pos, int distance, T value) {
-+ // CraftBukkit start
-+ this.addRegionTicketAtDistance(type, pos, distance, value);
-+ }
-+ public <T> boolean addRegionTicketAtDistance(TicketType<T> type, ChunkPos pos, int distance, T value) {
-+ // CraftBukkit end
Ticket<T> ticket = new Ticket<>(type, ChunkLevel.byStatus(FullChunkStatus.FULL) - distance, value);
long packedChunkPos = pos.toLong();
- this.addTicket(packedChunkPos, ticket);
-+ final boolean addded = this.addTicket(packedChunkPos, ticket); // CraftBukkit
++ this.addTicket(packedChunkPos, ticket); // Paper - diff on change above
this.tickingTicketsTracker.addTicket(packedChunkPos, ticket);
-+ return addded; // CraftBukkit
}
public <T> void removeRegionTicket(TicketType<T> type, ChunkPos pos, int distance, T value) {
-+ // CraftBukkit start
-+ removeRegionTicketAtDistance(type, pos, distance, value);
-+ }
-+ public <T> boolean removeRegionTicketAtDistance(TicketType<T> type, ChunkPos pos, int distance, T value) {
-+ // CraftBukkit end
Ticket<T> ticket = new Ticket<>(type, ChunkLevel.byStatus(FullChunkStatus.FULL) - distance, value);
long packedChunkPos = pos.toLong();
-- this.removeTicket(packedChunkPos, ticket);
-+ final boolean removed = this.removeTicket(packedChunkPos, ticket); // CraftBukkit
++ this.removeTicket(packedChunkPos, ticket); // Paper - diff on change above
++ this.tickingTicketsTracker.removeTicket(packedChunkPos, ticket);
++ }
++
++ // Paper start
++ public boolean addPluginRegionTicket(final ChunkPos pos, final org.bukkit.plugin.Plugin value) {
++ Ticket<org.bukkit.plugin.Plugin> ticket = new Ticket<>(TicketType.PLUGIN_TICKET, ChunkLevel.byStatus(FullChunkStatus.FULL) - 2, value); // Copied from below and keep in-line with force loading, add at level 31
++ final long packedChunkPos = pos.toLong();
++ final Set<Ticket<?>> tickets = this.getTickets(packedChunkPos);
++ if (tickets.contains(ticket)) {
++ return false;
++ }
++ this.addTicket(packedChunkPos, ticket);
++ this.tickingTicketsTracker.addTicket(packedChunkPos, ticket);
++ return true;
++ }
++
++ public boolean removePluginRegionTicket(final ChunkPos pos, final org.bukkit.plugin.Plugin value) {
++ Ticket<org.bukkit.plugin.Plugin> ticket = new Ticket<>(TicketType.PLUGIN_TICKET, ChunkLevel.byStatus(FullChunkStatus.FULL) - 2, value); // Copied from below and keep in-line with force loading, add at level 31
++ final long packedChunkPos = pos.toLong();
++ final Set<Ticket<?>> tickets = this.tickets.get(packedChunkPos); // Don't use getTickets, we don't want to create a new set
++ if (tickets == null || !tickets.contains(ticket)) {
++ return false;
++ }
+ this.removeTicket(packedChunkPos, ticket);
this.tickingTicketsTracker.removeTicket(packedChunkPos, ticket);
-+ return removed; // CraftBukkit
++ return true;
}
++ // Paper end
private SortedArraySet<Ticket<?>> getTickets(long chunkPos) {
+ return this.tickets.computeIfAbsent(chunkPos, l -> SortedArraySet.create(4));
@@ -217,8 +_,12 @@
ChunkPos chunkPos = sectionPos.chunk();
long packedChunkPos = chunkPos.toLong();
diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 619b71eac6..61eac5fbbe 100644
--- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -584,10 +584,9 @@ public class CraftWorld extends CraftRegionAccessor implements World {
Preconditions.checkArgument(plugin != null, "null plugin");
Preconditions.checkArgument(plugin.isEnabled(), "plugin is not enabled");
- DistanceManager chunkDistanceManager = this.world.getChunkSource().chunkMap.distanceManager;
-
- if (chunkDistanceManager.addRegionTicketAtDistance(TicketType.PLUGIN_TICKET, new ChunkPos(x, z), 2, plugin)) { // keep in-line with force loading, add at level 31
- this.getChunkAt(x, z); // ensure loaded
+ final DistanceManager distanceManager = this.world.getChunkSource().chunkMap.distanceManager;
+ if (distanceManager.addPluginRegionTicket(new ChunkPos(x, z), plugin)) {
+ this.getChunkAt(x, z); // ensure it's loaded
return true;
}
@@ -598,8 +597,8 @@ public class CraftWorld extends CraftRegionAccessor implements World {
public boolean removePluginChunkTicket(int x, int z, Plugin plugin) {
Preconditions.checkNotNull(plugin, "null plugin");
- DistanceManager chunkDistanceManager = this.world.getChunkSource().chunkMap.distanceManager;
- return chunkDistanceManager.removeRegionTicketAtDistance(TicketType.PLUGIN_TICKET, new ChunkPos(x, z), 2, plugin); // keep in-line with force loading, remove at level 31
+ final DistanceManager distanceManager = this.world.getChunkSource().chunkMap.distanceManager;
+ return distanceManager.removePluginRegionTicket(new ChunkPos(x, z), plugin);
}
@Override