3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-21 05:50:05 +01:00
Paper/nms-patches/ChunkMapDistance.patch

176 Zeilen
7.6 KiB
Diff

--- a/net/minecraft/server/ChunkMapDistance.java
+++ b/net/minecraft/server/ChunkMapDistance.java
2019-07-20 01:00:00 +02:00
@@ -32,7 +32,7 @@
private static final Logger LOGGER = LogManager.getLogger();
private static final int b = 33 + ChunkStatus.a(ChunkStatus.FULL) - 2;
private final Long2ObjectMap<ObjectSet<EntityPlayer>> c = new Long2ObjectOpenHashMap();
- private final Long2ObjectOpenHashMap<ObjectSortedSet<Ticket<?>>> tickets = new Long2ObjectOpenHashMap();
+ public final Long2ObjectOpenHashMap<ObjectSortedSet<Ticket<?>>> tickets = new Long2ObjectOpenHashMap(); // CraftBukkit - private -> public
private final ChunkMapDistance.a e = new ChunkMapDistance.a();
private final ChunkMapDistance.b f = new ChunkMapDistance.b(8);
private final ChunkMapDistance.c g = new ChunkMapDistance.c(33);
2019-07-20 01:00:00 +02:00
@@ -62,7 +62,7 @@
while (objectiterator.hasNext()) {
Entry<ObjectSortedSet<Ticket<?>>> entry = (Entry) objectiterator.next();
- if (((ObjectSortedSet) entry.getValue()).removeIf((ticket) -> {
+ if ((entry.getValue()).removeIf((ticket) -> { // Craftbukkit - decompile error
return ticket.a(this.currentTick);
})) {
this.e.b(entry.getLongKey(), this.a((ObjectSortedSet) entry.getValue()), false);
2019-07-20 01:00:00 +02:00
@@ -100,10 +100,25 @@
}
2019-07-20 01:00:00 +02:00
if (!this.pendingChunkUpdates.isEmpty()) {
- this.pendingChunkUpdates.forEach((playerchunk) -> {
+ // CraftBukkit start
+ // Iterate pending chunk updates with protection against concurrent modification exceptions
2019-07-20 01:00:00 +02:00
+ java.util.Iterator<PlayerChunk> iter = this.pendingChunkUpdates.iterator();
+ int expectedSize = this.pendingChunkUpdates.size();
+ do {
+ PlayerChunk playerchunk = iter.next();
+ iter.remove();
+ expectedSize--;
+
playerchunk.a(playerchunkmap);
- });
2019-07-20 01:00:00 +02:00
- this.pendingChunkUpdates.clear();
+
+ // Reset iterator if set was modified using add()
2019-07-20 01:00:00 +02:00
+ if (this.pendingChunkUpdates.size() != expectedSize) {
+ expectedSize = this.pendingChunkUpdates.size();
+ iter = this.pendingChunkUpdates.iterator();
+ }
+ } while (iter.hasNext());
+ // CraftBukkit end
+
return true;
} else {
if (!this.l.isEmpty()) {
2019-07-20 01:00:00 +02:00
@@ -125,7 +140,7 @@
completablefuture.thenAccept((either) -> {
this.m.execute(() -> {
- this.k.a((Object) ChunkTaskQueueSorter.a(() -> {
+ this.k.a(ChunkTaskQueueSorter.a(() -> { // Craftbukkit - decompile error
}, j, false));
});
});
2019-07-20 01:00:00 +02:00
@@ -139,7 +154,7 @@
}
}
2019-07-20 01:00:00 +02:00
- private void addTicket(long i, Ticket<?> ticket) {
+ private boolean addTicket(long i, Ticket<?> ticket) { // CraftBukkit - void -> boolean
ObjectSortedSet<Ticket<?>> objectsortedset = this.e(i);
ObjectBidirectionalIterator<Ticket<?>> objectbidirectionaliterator = objectsortedset.iterator();
int j;
2019-07-20 01:00:00 +02:00
@@ -150,21 +165,24 @@
j = PlayerChunkMap.GOLDEN_TICKET + 1;
}
+ boolean ret = false; // CraftBukkit
if (objectsortedset.add(ticket)) {
- ;
+ ret = true; // CraftBukkit
}
if (ticket.b() < j) {
this.e.b(i, ticket.b(), true);
}
+ return ret; // CraftBukkit
}
2019-07-20 01:00:00 +02:00
- private void removeTicket(long i, Ticket<?> ticket) {
+ private boolean removeTicket(long i, Ticket<?> ticket) { // CraftBukkit - void -> boolean
ObjectSortedSet<Ticket<?>> objectsortedset = this.e(i);
+ boolean removed = false; // CraftBukkit
if (objectsortedset.remove(ticket)) {
- ;
+ removed = true; // CraftBukkit
}
if (objectsortedset.isEmpty()) {
2019-07-20 01:00:00 +02:00
@@ -172,16 +190,29 @@
}
this.e.b(i, this.a(objectsortedset), false);
+ return removed; // CraftBukkit
}
public <T> void a(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
2019-07-20 01:00:00 +02:00
- this.addTicket(chunkcoordintpair.pair(), new Ticket<>(tickettype, i, t0, this.currentTick));
+ // CraftBukkit start
+ this.addTicketAtLevel(tickettype, chunkcoordintpair, i, t0);
+ }
2019-07-20 01:00:00 +02:00
+
+ public <T> boolean addTicketAtLevel(TicketType<T> ticketType, ChunkCoordIntPair chunkcoordintpair, int level, T identifier) {
+ return this.addTicket(chunkcoordintpair.pair(), new Ticket<>(ticketType, level, identifier, this.currentTick));
+ // CraftBukkit end
}
public <T> void b(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
- Ticket<T> ticket = new Ticket<>(tickettype, i, t0, this.currentTick);
+ // CraftBukkit start
+ this.removeTicketAtLevel(tickettype, chunkcoordintpair, i, t0);
+ }
2019-07-20 01:00:00 +02:00
- 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, this.currentTick);
+
+ return this.removeTicket(chunkcoordintpair.pair(), ticket);
+ // CraftBukkit end
}
public <T> void addTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
2019-07-20 01:00:00 +02:00
@@ -265,6 +296,21 @@
return this.i.a();
}
+ // CraftBukkit start
+ public <T> void removeAllTicketsFor(TicketType<T> ticketType, int ticketLevel, T ticketIdentifier) {
+ Ticket<T> target = new Ticket<>(ticketType, ticketLevel, ticketIdentifier, this.currentTick);
+
+ for (java.util.Iterator<ObjectSortedSet<Ticket<?>>> iterator = this.tickets.values().iterator(); iterator.hasNext();) {
+ ObjectSortedSet<Ticket<?>> tickets = iterator.next();
+ tickets.remove(target);
+
+ if (tickets.isEmpty()) {
+ iterator.remove();
+ }
+ }
+ }
+ // CraftBukkit end
+
class a extends ChunkMap {
public a() {
2019-07-20 01:00:00 +02:00
@@ -351,13 +397,13 @@
Ticket<?> ticket = new Ticket<>(TicketType.PLAYER, ChunkMapDistance.b, new ChunkCoordIntPair(i), ChunkMapDistance.this.currentTick);
if (flag1) {
- ChunkMapDistance.this.j.a((Object) ChunkTaskQueueSorter.a(() -> {
+ ChunkMapDistance.this.j.a(ChunkTaskQueueSorter.a(() -> { // Craftbukkit - decompile error
ChunkMapDistance.this.m.execute(() -> {
2019-07-20 01:00:00 +02:00
if (this.c(this.c(i))) {
ChunkMapDistance.this.addTicket(i, ticket);
ChunkMapDistance.this.l.add(i);
} else {
- ChunkMapDistance.this.k.a((Object) ChunkTaskQueueSorter.a(() -> {
+ ChunkMapDistance.this.k.a(ChunkTaskQueueSorter.a(() -> { // Craftbukkit - decompile error
}, i, false));
}
@@ -366,7 +412,7 @@
return j;
}));
} else {
- ChunkMapDistance.this.k.a((Object) ChunkTaskQueueSorter.a(() -> {
+ ChunkMapDistance.this.k.a(ChunkTaskQueueSorter.a(() -> { // Craftbukkit - decompile error
ChunkMapDistance.this.m.execute(() -> {
2019-07-20 01:00:00 +02:00
ChunkMapDistance.this.removeTicket(i, ticket);
});