mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-10 18:27:41 +01:00
b3a8254758
By: md_5 <git@md-5.net>
139 lines
5.7 KiB
Diff
139 lines
5.7 KiB
Diff
--- a/net/minecraft/server/level/ChunkMapDistance.java
|
|
+++ b/net/minecraft/server/level/ChunkMapDistance.java
|
|
@@ -73,7 +73,7 @@
|
|
while (objectiterator.hasNext()) {
|
|
Entry<ArraySetSorted<Ticket<?>>> entry = (Entry) objectiterator.next();
|
|
|
|
- if (((ArraySetSorted) entry.getValue()).removeIf((ticket) -> {
|
|
+ if ((entry.getValue()).removeIf((ticket) -> { // CraftBukkit - decompile error
|
|
return ticket.b(this.ticketTickCounter);
|
|
})) {
|
|
this.ticketTracker.update(entry.getLongKey(), getLowestTicketLevel((ArraySetSorted) entry.getValue()), false);
|
|
@@ -109,10 +109,25 @@
|
|
}
|
|
|
|
if (!this.chunksToUpdateFutures.isEmpty()) {
|
|
- this.chunksToUpdateFutures.forEach((playerchunk) -> {
|
|
+ // CraftBukkit start
|
|
+ // Iterate pending chunk updates with protection against concurrent modification exceptions
|
|
+ java.util.Iterator<PlayerChunk> iter = this.chunksToUpdateFutures.iterator();
|
|
+ int expectedSize = this.chunksToUpdateFutures.size();
|
|
+ do {
|
|
+ PlayerChunk playerchunk = iter.next();
|
|
+ iter.remove();
|
|
+ expectedSize--;
|
|
+
|
|
playerchunk.a(playerchunkmap, this.mainThreadExecutor);
|
|
- });
|
|
- this.chunksToUpdateFutures.clear();
|
|
+
|
|
+ // Reset iterator if set was modified using add()
|
|
+ if (this.chunksToUpdateFutures.size() != expectedSize) {
|
|
+ expectedSize = this.chunksToUpdateFutures.size();
|
|
+ iter = this.chunksToUpdateFutures.iterator();
|
|
+ }
|
|
+ } while (iter.hasNext());
|
|
+ // CraftBukkit end
|
|
+
|
|
return true;
|
|
} else {
|
|
if (!this.ticketsToRelease.isEmpty()) {
|
|
@@ -148,23 +163,25 @@
|
|
}
|
|
}
|
|
|
|
- void addTicket(long i, Ticket<?> ticket) {
|
|
+ boolean addTicket(long i, Ticket<?> ticket) { // CraftBukkit - void -> boolean
|
|
ArraySetSorted<Ticket<?>> arraysetsorted = this.e(i);
|
|
int j = getLowestTicketLevel(arraysetsorted);
|
|
- Ticket<?> ticket1 = (Ticket) arraysetsorted.a((Object) ticket);
|
|
+ Ticket<?> ticket1 = (Ticket) arraysetsorted.a(ticket); // CraftBukkit - decompile error
|
|
|
|
ticket1.a(this.ticketTickCounter);
|
|
if (ticket.b() < j) {
|
|
this.ticketTracker.update(i, ticket.b(), true);
|
|
}
|
|
|
|
+ return ticket == ticket1; // CraftBukkit
|
|
}
|
|
|
|
- void removeTicket(long i, Ticket<?> ticket) {
|
|
+ boolean removeTicket(long i, Ticket<?> ticket) { // CraftBukkit - void -> boolean
|
|
ArraySetSorted<Ticket<?>> arraysetsorted = this.e(i);
|
|
|
|
+ boolean removed = false; // CraftBukkit
|
|
if (arraysetsorted.remove(ticket)) {
|
|
- ;
|
|
+ removed = true; // CraftBukkit
|
|
}
|
|
|
|
if (arraysetsorted.isEmpty()) {
|
|
@@ -172,16 +189,29 @@
|
|
}
|
|
|
|
this.ticketTracker.update(i, getLowestTicketLevel(arraysetsorted), false);
|
|
+ return removed; // CraftBukkit
|
|
}
|
|
|
|
public <T> void a(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
|
|
- this.addTicket(chunkcoordintpair.pair(), 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.pair(), new Ticket<>(ticketType, level, identifier));
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
public <T> void b(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.pair(), 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.pair(), ticket);
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
public <T> void addTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
|
|
@@ -224,6 +254,7 @@
|
|
public void b(SectionPosition sectionposition, EntityPlayer entityplayer) {
|
|
long i = sectionposition.r().pair();
|
|
ObjectSet<EntityPlayer> objectset = (ObjectSet) this.playersPerChunk.get(i);
|
|
+ if (objectset == null) return; // CraftBukkit - SPIGOT-6208
|
|
|
|
objectset.remove(entityplayer);
|
|
if (objectset.isEmpty()) {
|
|
@@ -300,6 +331,26 @@
|
|
|
|
}
|
|
|
|
+ // CraftBukkit start
|
|
+ public <T> void removeAllTicketsFor(TicketType<T> ticketType, int ticketLevel, T ticketIdentifier) {
|
|
+ Ticket<T> target = new Ticket<>(ticketType, ticketLevel, ticketIdentifier);
|
|
+
|
|
+ for (java.util.Iterator<Entry<ArraySetSorted<Ticket<?>>>> iterator = this.tickets.long2ObjectEntrySet().fastIterator(); iterator.hasNext();) {
|
|
+ Entry<ArraySetSorted<Ticket<?>>> entry = iterator.next();
|
|
+ ArraySetSorted<Ticket<?>> tickets = entry.getValue();
|
|
+ if (tickets.remove(target)) {
|
|
+ // copied from removeTicket
|
|
+ this.ticketTracker.update(entry.getLongKey(), getLowestTicketLevel(tickets), false);
|
|
+
|
|
+ // can't use entry after it's removed
|
|
+ if (tickets.isEmpty()) {
|
|
+ iterator.remove();
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
private class a extends ChunkMap {
|
|
|
|
public a() {
|