SPIGOT-6934: Bring plugin chunk tickets back in line with forceload tickets

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2022-02-20 08:55:27 +11:00
parent 7fe2a47414
commit c48241fce5
2 changed files with 38 additions and 27 deletions

View File

@ -56,7 +56,7 @@
}
if (arraysetsorted.isEmpty()) {
@@ -188,16 +205,29 @@
@@ -188,6 +205,7 @@
}
this.ticketTracker.update(i, getTicketLevelAt(arraysetsorted), false);
@ -64,32 +64,43 @@
}
public <T> void addTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
- this.addTicket(chunkcoordintpair.toLong(), new Ticket<>(tickettype, i, t0));
+ // CraftBukkit start
+ this.addTicketAtLevel(tickettype, chunkcoordintpair, i, t0);
+ }
+
+ public <T> boolean addTicketAtLevel(TicketType<T> ticketType, ChunkCoordIntPair chunkcoordintpair, int level, T identifier) {
+ return this.addTicket(chunkcoordintpair.toLong(), new Ticket<>(ticketType, level, identifier));
+ // CraftBukkit end
}
public <T> void removeTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
- Ticket<T> ticket = new Ticket<>(tickettype, i, t0);
+ // CraftBukkit start
+ this.removeTicketAtLevel(tickettype, chunkcoordintpair, i, t0);
+ }
- this.removeTicket(chunkcoordintpair.toLong(), ticket);
+ public <T> boolean removeTicketAtLevel(TicketType<T> ticketType, ChunkCoordIntPair chunkcoordintpair, int level, T identifier) {
+ Ticket<T> ticket = new Ticket<>(ticketType, level, identifier);
+
+ return this.removeTicket(chunkcoordintpair.toLong(), ticket);
+ // CraftBukkit end
@@ -201,19 +219,33 @@
}
public <T> void addRegionTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
@@ -252,6 +282,7 @@
+ // CraftBukkit start
+ addRegionTicketAtDistance(tickettype, chunkcoordintpair, i, t0);
+ }
+
+ public <T> boolean addRegionTicketAtDistance(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
+ // CraftBukkit end
Ticket<T> ticket = new Ticket<>(tickettype, 33 - i, t0);
long j = chunkcoordintpair.toLong();
- this.addTicket(j, ticket);
+ boolean added = this.addTicket(j, ticket); // CraftBukkit
this.tickingTicketsTracker.addTicket(j, ticket);
+ return added; // CraftBukkit
}
public <T> void removeRegionTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
+ // CraftBukkit start
+ removeRegionTicketAtDistance(tickettype, chunkcoordintpair, i, t0);
+ }
+
+ public <T> boolean removeRegionTicketAtDistance(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
+ // CraftBukkit end
Ticket<T> ticket = new Ticket<>(tickettype, 33 - i, t0);
long j = chunkcoordintpair.toLong();
- this.removeTicket(j, ticket);
+ boolean removed = this.removeTicket(j, ticket); // CraftBukkit
this.tickingTicketsTracker.removeTicket(j, ticket);
+ return removed; // CraftBukkit
}
private ArraySetSorted<Ticket<?>> getTickets(long i) {
@@ -252,6 +284,7 @@
ChunkCoordIntPair chunkcoordintpair = sectionposition.chunk();
long i = chunkcoordintpair.toLong();
ObjectSet<EntityPlayer> objectset = (ObjectSet) this.playersPerChunk.get(i);
@ -97,7 +108,7 @@
objectset.remove(entityplayer);
if (objectset.isEmpty()) {
@@ -347,6 +378,26 @@
@@ -347,6 +380,26 @@
return this.tickingTicketsTracker;
}

View File

@ -365,7 +365,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
ChunkMapDistance chunkDistanceManager = this.world.getChunkSource().chunkMap.distanceManager;
if (chunkDistanceManager.addTicketAtLevel(TicketType.PLUGIN_TICKET, new ChunkCoordIntPair(x, z), 31, plugin)) { // keep in-line with force loading, add at level 31
if (chunkDistanceManager.addRegionTicketAtDistance(TicketType.PLUGIN_TICKET, new ChunkCoordIntPair(x, z), 2, plugin)) { // keep in-line with force loading, add at level 31
this.getChunkAt(x, z); // ensure loaded
return true;
}
@ -378,7 +378,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
Preconditions.checkNotNull(plugin, "null plugin");
ChunkMapDistance chunkDistanceManager = this.world.getChunkSource().chunkMap.distanceManager;
return chunkDistanceManager.removeTicketAtLevel(TicketType.PLUGIN_TICKET, new ChunkCoordIntPair(x, z), 31, plugin); // keep in-line with force loading, remove at level 31
return chunkDistanceManager.removeRegionTicketAtDistance(TicketType.PLUGIN_TICKET, new ChunkCoordIntPair(x, z), 2, plugin); // keep in-line with force loading, remove at level 31
}
@Override