2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/server/level/ChunkMapDistance.java
|
|
|
|
+++ b/net/minecraft/server/level/ChunkMapDistance.java
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -121,10 +121,25 @@
|
2019-07-13 20:23:41 +02:00
|
|
|
}
|
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
if (!this.chunksToUpdateFutures.isEmpty()) {
|
|
|
|
- this.chunksToUpdateFutures.forEach((playerchunk) -> {
|
2019-07-13 20:23:41 +02:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ // Iterate pending chunk updates with protection against concurrent modification exceptions
|
2021-06-11 07:00:00 +02:00
|
|
|
+ java.util.Iterator<PlayerChunk> iter = this.chunksToUpdateFutures.iterator();
|
|
|
|
+ int expectedSize = this.chunksToUpdateFutures.size();
|
2019-07-13 20:23:41 +02:00
|
|
|
+ do {
|
|
|
|
+ PlayerChunk playerchunk = iter.next();
|
|
|
|
+ iter.remove();
|
|
|
|
+ expectedSize--;
|
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
playerchunk.updateFutures(playerchunkmap, this.mainThreadExecutor);
|
2019-07-13 20:23:41 +02:00
|
|
|
- });
|
2021-06-11 07:00:00 +02:00
|
|
|
- this.chunksToUpdateFutures.clear();
|
2019-07-13 20:23:41 +02:00
|
|
|
+
|
|
|
|
+ // Reset iterator if set was modified using add()
|
2021-06-11 07:00:00 +02:00
|
|
|
+ if (this.chunksToUpdateFutures.size() != expectedSize) {
|
|
|
|
+ expectedSize = this.chunksToUpdateFutures.size();
|
|
|
|
+ iter = this.chunksToUpdateFutures.iterator();
|
2019-07-13 20:23:41 +02:00
|
|
|
+ }
|
|
|
|
+ } while (iter.hasNext());
|
|
|
|
+ // CraftBukkit end
|
|
|
|
+
|
|
|
|
return true;
|
|
|
|
} else {
|
2021-06-11 07:00:00 +02:00
|
|
|
if (!this.ticketsToRelease.isEmpty()) {
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -160,7 +175,7 @@
|
2019-07-08 04:14:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
- void addTicket(long i, Ticket<?> ticket) {
|
|
|
|
+ boolean addTicket(long i, Ticket<?> ticket) { // CraftBukkit - void -> boolean
|
2021-11-21 23:00:00 +01:00
|
|
|
ArraySetSorted<Ticket<?>> arraysetsorted = this.getTickets(i);
|
|
|
|
int j = getTicketLevelAt(arraysetsorted);
|
|
|
|
Ticket<?> ticket1 = (Ticket) arraysetsorted.addOrGet(ticket);
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -170,13 +185,15 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
this.ticketTracker.update(i, ticket.getTicketLevel(), true);
|
2019-07-08 04:14:16 +02:00
|
|
|
}
|
|
|
|
|
2019-12-10 23:00:00 +01:00
|
|
|
+ return ticket == ticket1; // CraftBukkit
|
2019-07-08 04:14:16 +02:00
|
|
|
}
|
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
- void removeTicket(long i, Ticket<?> ticket) {
|
|
|
|
+ boolean removeTicket(long i, Ticket<?> ticket) { // CraftBukkit - void -> boolean
|
2021-11-21 23:00:00 +01:00
|
|
|
ArraySetSorted<Ticket<?>> arraysetsorted = this.getTickets(i);
|
2019-07-08 04:14:16 +02:00
|
|
|
|
|
|
|
+ boolean removed = false; // CraftBukkit
|
2019-12-10 23:00:00 +01:00
|
|
|
if (arraysetsorted.remove(ticket)) {
|
2019-07-08 04:14:16 +02:00
|
|
|
- ;
|
|
|
|
+ removed = true; // CraftBukkit
|
|
|
|
}
|
|
|
|
|
2019-12-10 23:00:00 +01:00
|
|
|
if (arraysetsorted.isEmpty()) {
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -184,6 +201,7 @@
|
2019-07-08 04:14:16 +02:00
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
this.ticketTracker.update(i, getTicketLevelAt(arraysetsorted), false);
|
2019-07-08 04:14:16 +02:00
|
|
|
+ return removed; // CraftBukkit
|
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
public <T> void addTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -197,19 +215,33 @@
|
2022-02-19 22:55:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public <T> void addRegionTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
|
2019-07-08 04:14:16 +02:00
|
|
|
+ // CraftBukkit start
|
2022-02-19 22:55:27 +01:00
|
|
|
+ addRegionTicketAtDistance(tickettype, chunkcoordintpair, i, t0);
|
2019-07-08 04:14:16 +02:00
|
|
|
+ }
|
2019-07-20 01:00:00 +02:00
|
|
|
+
|
2022-02-19 22:55:27 +01:00
|
|
|
+ public <T> boolean addRegionTicketAtDistance(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
|
2019-07-08 04:14:16 +02:00
|
|
|
+ // CraftBukkit end
|
2023-06-07 17:30:00 +02:00
|
|
|
Ticket<T> ticket = new Ticket<>(tickettype, ChunkLevel.byStatus(FullChunkStatus.FULL) - i, t0);
|
2022-02-19 22:55:27 +01:00
|
|
|
long j = chunkcoordintpair.toLong();
|
|
|
|
|
|
|
|
- this.addTicket(j, ticket);
|
|
|
|
+ boolean added = this.addTicket(j, ticket); // CraftBukkit
|
|
|
|
this.tickingTicketsTracker.addTicket(j, ticket);
|
|
|
|
+ return added; // CraftBukkit
|
2019-07-08 04:14:16 +02:00
|
|
|
}
|
|
|
|
|
2022-02-19 22:55:27 +01:00
|
|
|
public <T> void removeRegionTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
|
2019-07-08 04:14:16 +02:00
|
|
|
+ // CraftBukkit start
|
2022-02-19 22:55:27 +01:00
|
|
|
+ removeRegionTicketAtDistance(tickettype, chunkcoordintpair, i, t0);
|
2019-07-08 04:14:16 +02:00
|
|
|
+ }
|
2019-07-20 01:00:00 +02:00
|
|
|
+
|
2022-02-19 22:55:27 +01:00
|
|
|
+ public <T> boolean removeRegionTicketAtDistance(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
|
2019-07-08 04:14:16 +02:00
|
|
|
+ // CraftBukkit end
|
2023-06-07 17:30:00 +02:00
|
|
|
Ticket<T> ticket = new Ticket<>(tickettype, ChunkLevel.byStatus(FullChunkStatus.FULL) - i, t0);
|
2022-02-19 22:55:27 +01:00
|
|
|
long j = chunkcoordintpair.toLong();
|
|
|
|
|
|
|
|
- this.removeTicket(j, ticket);
|
|
|
|
+ boolean removed = this.removeTicket(j, ticket); // CraftBukkit
|
|
|
|
this.tickingTicketsTracker.removeTicket(j, ticket);
|
|
|
|
+ return removed; // CraftBukkit
|
2019-07-08 04:14:16 +02:00
|
|
|
}
|
|
|
|
|
2022-02-19 22:55:27 +01:00
|
|
|
private ArraySetSorted<Ticket<?>> getTickets(long i) {
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -248,6 +280,7 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
ChunkCoordIntPair chunkcoordintpair = sectionposition.chunk();
|
|
|
|
long i = chunkcoordintpair.toLong();
|
2021-06-11 07:00:00 +02:00
|
|
|
ObjectSet<EntityPlayer> objectset = (ObjectSet) this.playersPerChunk.get(i);
|
2021-01-31 04:26:05 +01:00
|
|
|
+ if (objectset == null) return; // CraftBukkit - SPIGOT-6208
|
|
|
|
|
|
|
|
objectset.remove(entityplayer);
|
|
|
|
if (objectset.isEmpty()) {
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -377,6 +410,26 @@
|
2022-02-28 16:00:00 +01:00
|
|
|
return !this.tickets.isEmpty();
|
2019-07-08 04:14:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ public <T> void removeAllTicketsFor(TicketType<T> ticketType, int ticketLevel, T ticketIdentifier) {
|
2019-12-10 23:00:00 +01:00
|
|
|
+ Ticket<T> target = new Ticket<>(ticketType, ticketLevel, ticketIdentifier);
|
2019-07-08 04:14:16 +02:00
|
|
|
+
|
2020-03-22 10:02:22 +01:00
|
|
|
+ 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
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.ticketTracker.update(entry.getLongKey(), getTicketLevelAt(tickets), false);
|
2019-07-08 04:14:16 +02:00
|
|
|
+
|
2020-03-22 10:02:22 +01:00
|
|
|
+ // can't use entry after it's removed
|
|
|
|
+ if (tickets.isEmpty()) {
|
|
|
|
+ iterator.remove();
|
|
|
|
+ }
|
2019-07-08 04:14:16 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
+
|
2021-06-11 07:00:00 +02:00
|
|
|
private class a extends ChunkMap {
|
2019-07-08 04:14:16 +02:00
|
|
|
|
2023-06-07 17:30:00 +02:00
|
|
|
private static final int MAX_LEVEL = ChunkLevel.MAX_LEVEL + 1;
|