SPIGOT-2014: Respect the spectatorsGenerateChunks gamerule

By: Thinkofname <thinkofdeath@spigotmc.org>
This commit is contained in:
CraftBukkit/Spigot
2016-04-20 11:00:35 +01:00
parent 8fe634523c
commit 77b2d0456e
2 changed files with 35 additions and 39 deletions

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/PlayerChunk.java
+++ b/net/minecraft/server/PlayerChunk.java
@@ -4,35 +4,48 @@
@@ -4,35 +4,50 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import java.util.ArrayList;
@@ -27,9 +27,10 @@
private boolean done;
+ // CraftBukkit start - add fields
+ private final HashMap<EntityPlayer, Runnable> players = new HashMap<EntityPlayer, Runnable>();
+ private boolean loadInProgress = false;
+ private Runnable loadedRunnable = new Runnable() {
+ public void run() {
+ loadInProgress = false;
+ PlayerChunk.this.chunk = PlayerChunk.this.playerChunkMap.getWorld().getChunkProviderServer().getOrLoadChunkAt(location.x, location.z);
+ }
+ };
@@ -40,7 +41,8 @@
this.location = new ChunkCoordIntPair(i, j);
- this.chunk = playerchunkmap.getWorld().getChunkProviderServer().getOrLoadChunkAt(i, j);
+ // CraftBukkit start
+ this.chunk = playerchunkmap.getWorld().getChunkProviderServer().getChunkAt(i, j, loadedRunnable);
+ loadInProgress = true;
+ this.chunk = playerchunkmap.getWorld().getChunkProviderServer().getChunkAt(i, j, loadedRunnable, false);
+ // CraftBukkit end
}
@@ -53,31 +55,20 @@
if (this.c.contains(entityplayer)) {
PlayerChunk.a.debug("Failed to add player. {} already is in chunk {}, {}", new Object[] { entityplayer, Integer.valueOf(this.location.x), Integer.valueOf(this.location.z)});
} else {
@@ -41,19 +54,50 @@
@@ -41,15 +56,32 @@
}
this.c.add(entityplayer);
+ // CraftBukkit start - use async chunk io
+ // if (this.j) {
+ // if (this.done) {
+ // this.sendChunk(entityplayer);
+ // }
+ Runnable playerRunnable;
if (this.done) {
- this.sendChunk(entityplayer);
+ playerRunnable = null;
+ sendChunk(entityplayer);
+ } else {
+ playerRunnable = new Runnable() {
+ public void run() {
+ sendChunk(entityplayer);
+ }
+ };
+ playerChunkMap.getWorld().getChunkProviderServer().getChunkAt(this.location.x, this.location.z, playerRunnable);
}
+ this.players.put(entityplayer, playerRunnable);
+ // CraftBukkit end
+
}
}
@@ -85,9 +76,7 @@
if (this.c.contains(entityplayer)) {
+ // CraftBukkit start - If we haven't loaded yet don't load the chunk just so we can clean it up
+ if (!this.done) {
+ ChunkIOExecutor.dropQueuedChunkLoad(this.playerChunkMap.getWorld(), this.location.x, this.location.z, this.players.get(entityplayer));
+ this.c.remove(entityplayer);
+ this.players.remove(entityplayer);
+
+ if (this.c.isEmpty()) {
+ ChunkIOExecutor.dropQueuedChunkLoad(this.playerChunkMap.getWorld(), this.location.x, this.location.z, this.loadedRunnable);
@@ -100,19 +89,22 @@
if (this.done) {
entityplayer.playerConnection.sendPacket(new PacketPlayOutUnloadChunk(this.location.x, this.location.z));
}
+ this.players.remove(entityplayer); // CraftBukkit
this.c.remove(entityplayer);
if (this.c.isEmpty()) {
this.playerChunkMap.b(this);
@@ -63,8 +107,8 @@
}
public boolean a(boolean flag) {
- if (this.chunk != null) {
- return true;
+ if (this.chunk != null || true) { // CraftBukkit
+ return done; // CraftBukkit
@@ -66,11 +98,18 @@
if (this.chunk != null) {
return true;
} else {
+ /* CraftBukkit start
if (flag) {
this.chunk = this.playerChunkMap.getWorld().getChunkProviderServer().getChunkAt(this.location.x, this.location.z);
} else {
this.chunk = this.playerChunkMap.getWorld().getChunkProviderServer().getOrLoadChunkAt(this.location.x, this.location.z);
}
+ */
+ if (!loadInProgress) {
+ loadInProgress = true;
+ this.chunk = playerChunkMap.getWorld().getChunkProviderServer().getChunkAt(this.location.x, this.location.z, loadedRunnable, flag);
+ }
+ // CraftBukkit end
return this.chunk != null;
}