Add Plugin Chunk Ticket API

Allows plugins to force certain chunks to be kept loaded for as long as they are enabled.

By: Spottedleaf <Spottedleaf@users.noreply.github.com>
This commit is contained in:
CraftBukkit/Spigot
2019-07-08 12:14:16 +10:00
parent 09309c363f
commit aedce73dd1
6 changed files with 268 additions and 2 deletions

View File

@@ -0,0 +1,137 @@
--- a/net/minecraft/server/ChunkMapDistance.java
+++ b/net/minecraft/server/ChunkMapDistance.java
@@ -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);
@@ -61,7 +61,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);
@@ -124,7 +124,7 @@
completablefuture.thenAccept((either) -> {
this.m.execute(() -> {
- this.k.a((Object) ChunkTaskQueueSorter.a(() -> {
+ this.k.a(ChunkTaskQueueSorter.a(() -> { // Craftbukkit - decompile error
}, j, false));
});
});
@@ -138,7 +138,7 @@
}
}
- private void a(long i, Ticket<?> ticket) {
+ private boolean a(long i, Ticket<?> ticket) { // CraftBukkit - void -> boolean // PAIL addTicket
ObjectSortedSet<Ticket<?>> objectsortedset = this.e(i);
ObjectBidirectionalIterator<Ticket<?>> objectbidirectionaliterator = objectsortedset.iterator();
int j;
@@ -149,21 +149,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
}
- private void b(long i, Ticket<?> ticket) {
+ private boolean b(long i, Ticket<?> ticket) { // CraftBukkit - void -> boolean // PAIL removeTicket
ObjectSortedSet<Ticket<?>> objectsortedset = this.e(i);
+ boolean removed = false; // CraftBukkit
if (objectsortedset.remove(ticket)) {
- ;
+ removed = true; // CraftBukkit
}
if (objectsortedset.isEmpty()) {
@@ -171,16 +174,27 @@
}
this.e.b(i, this.a(objectsortedset), false);
+ return removed; // CraftBukkit
}
public <T> void a(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
- this.a(chunkcoordintpair.pair(), new Ticket<>(tickettype, i, t0, this.currentTick));
+ // CraftBukkit start
+ this.addTicketAtLevel(tickettype, chunkcoordintpair, i, t0);
+ }
+ public <T> boolean addTicketAtLevel(TicketType<T> ticketType, ChunkCoordIntPair chunkPos, int level, T identifier) {
+ return this.a(chunkPos.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);
+ }
+ public <T> boolean removeTicketAtLevel(TicketType<T> ticketType, ChunkCoordIntPair chunkPos, int level, T identifier) {
+ Ticket<T> ticket = new Ticket<>(ticketType, level, identifier, this.currentTick);
- this.b(chunkcoordintpair.pair(), ticket);
+ return this.b(chunkPos.pair(), ticket);
+ // CraftBukkit end
}
public <T> void addTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
@@ -247,6 +261,21 @@
return this.f.a.containsKey(i);
}
+ // 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() {
@@ -333,7 +362,7 @@
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(() -> {
ChunkMapDistance.this.a(i, ticket);
ChunkMapDistance.this.l.add(i);
@@ -342,7 +371,7 @@
return j;
}));
} else {
- ChunkMapDistance.this.k.a((Object) ChunkTaskQueueSorter.a(() -> {
+ ChunkMapDistance.this.k.a(ChunkTaskQueueSorter.a(() -> { // Craftbukkit - decompile error
ChunkMapDistance.this.m.execute(() -> {
ChunkMapDistance.this.b(i, ticket);
});

View File

@@ -8,6 +8,15 @@
public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
@@ -58,7 +59,7 @@
private final Mailbox<ChunkTaskQueueSorter.a<Runnable>> mailboxWorldGen;
private final Mailbox<ChunkTaskQueueSorter.a<Runnable>> mailboxMain;
public final WorldLoadListener worldLoadListener;
- private final PlayerChunkMap.a u;
+ public final PlayerChunkMap.a u; // CraftBukkit - private -> public // PAIL chunkDistanceManager
private final AtomicInteger v;
private final DefinedStructureManager definedStructureManager;
private final File x;
@@ -184,9 +185,12 @@
return completablefuture1.thenApply((list1) -> {

View File

@@ -0,0 +1,20 @@
--- a/net/minecraft/server/Ticket.java
+++ b/net/minecraft/server/Ticket.java
@@ -6,7 +6,7 @@
private final TicketType<T> a;
private final int b;
- private final T c;
+ public final T c; // CraftBukkit - private -> public // PAIL identifier
private final long d;
protected Ticket(TicketType<T> tickettype, int i, T t0, long j) {
@@ -24,7 +24,7 @@
} else {
int j = Integer.compare(System.identityHashCode(this.a), System.identityHashCode(ticket.a));
- return j != 0 ? j : this.a.a().compare(this.c, ticket.c);
+ return j != 0 ? j : this.a.a().compare(this.c, (T) ticket.c); // CraftBukkit - decompile error
}
}

View File

@@ -9,15 +9,16 @@
public static final TicketType<Unit> START = a("start", (unit, unit1) -> {
return 0;
});
@@ -19,6 +19,7 @@
@@ -19,6 +19,8 @@
public static final TicketType<BlockPosition2D> PORTAL = a("portal", Comparator.comparingLong(BlockPosition2D::b));
public static final TicketType<Integer> POST_TELEPORT = a("post_teleport", Integer::compareTo, 5);
public static final TicketType<ChunkCoordIntPair> UNKNOWN = a("unknown", Comparator.comparingLong(ChunkCoordIntPair::pair), 1);
+ public static final TicketType<Unit> PLUGIN = a("plugin", (a, b) -> 0); // CraftBukkit
+ public static final TicketType<org.bukkit.plugin.Plugin> PLUGIN_TICKET = a("plugin_ticket", (plugin1, plugin2) -> plugin1.getClass().getName().compareTo(plugin2.getClass().getName())); // Craftbukkit
public static <T> TicketType<T> a(String s, Comparator<T> comparator) {
return new TicketType<>(s, comparator, 0L);
@@ -45,4 +46,10 @@
@@ -45,4 +47,10 @@
public long b() {
return this.k;
}