summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft
diff options
context:
space:
mode:
authorDinnerbone <dinnerbone@dinnerbone.com>2011-02-08 14:26:55 +0000
committerDinnerbone <dinnerbone@dinnerbone.com>2011-02-08 14:26:55 +0000
commit3526a66fbe4877e6267fb937257c69cd0daa7abc (patch)
treec99a320bada61321d905beded26b3116b62db526 /src/main/java/net/minecraft
parent6b9b59db4e5b4e6012d66f13bcb951264c8260d0 (diff)
downloadcraftbukkit-3526a66fbe4877e6267fb937257c69cd0daa7abc.tar
craftbukkit-3526a66fbe4877e6267fb937257c69cd0daa7abc.tar.gz
craftbukkit-3526a66fbe4877e6267fb937257c69cd0daa7abc.tar.lz
craftbukkit-3526a66fbe4877e6267fb937257c69cd0daa7abc.tar.xz
craftbukkit-3526a66fbe4877e6267fb937257c69cd0daa7abc.zip
Added loadChunk, unloadChunk and unloadChunkRequest.
Diffstat (limited to 'src/main/java/net/minecraft')
-rw-r--r--src/main/java/net/minecraft/server/ChunkProviderServer.java90
1 files changed, 89 insertions, 1 deletions
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index 7e530d38..c2e47ba9 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -9,8 +9,10 @@ import java.util.Map;
import java.util.Set;
// CraftBukkit start
+import org.bukkit.Location;
import org.bukkit.craftbukkit.CraftChunk;
import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.world.ChunkLoadEvent;
// CraftBukkit end
@@ -47,8 +49,94 @@ public class ChunkProviderServer implements IChunkProvider {
public boolean a(int i, int j) {
return this.e.containsKey(i, j);
}
- // CraftBukkit end
+ public void saveChunk(int x, int z) {
+ Chunk chunk = this.b(x, z);
+ chunk.e();
+ this.b(chunk);
+ this.a(chunk);
+ }
+
+ public boolean unloadChunk(int x, int z, boolean save, boolean safe) {
+ if (safe && isChunkInUse(x, z))
+ return false;
+
+ Chunk chunk = this.b(x, z);
+
+ if (save)
+ saveChunk(x, z);
+
+ this.a.remove(x, z);
+ this.e.remove(x, z);
+ this.f.remove(chunk);
+ return true;
+ }
+
+ public boolean unloadChunkRequest(int x, int z, boolean safe) {
+ if (safe && isChunkInUse(x, z))
+ return false;
+ c(x, z);
+ return true;
+ }
+
+ public boolean isChunkInUse(int x, int z) {
+ CraftServer server = g.getServer();
+ Player[] players = server.getOnlinePlayers();
+ for (Player player : players) {
+ Location loc = player.getLocation();
+ if (loc.getWorld() != g.getWorld()) {
+ continue;
+ }
+ // If the chunk is within 256 blocks of a player, refuse to accept the unload request
+ // This is larger than the distance of loaded chunks that actually surround a player
+ // The player is the center of a 21x21 chunk grid, so the edge is 10 chunks (160 blocks) away from the player
+ if (Math.abs(loc.getBlockX() - (x << 4)) <= 256 && Math.abs(loc.getBlockZ() - (z << 4)) <= 256) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public Chunk loadChunk(int x, int z, boolean generate) {
+ if (generate) {
+ // Use the default variant of loadChunk when generate == true.
+ return d(x, z);
+ }
+
+ this.a.remove(x, z);
+ Chunk chunk = (Chunk) this.e.get(x, z);
+
+ if (chunk == null) {
+ chunk = this.e(x, z);
+
+ if (chunk != null) {
+ this.e.put(x, z, chunk);
+ this.f.add(chunk);
+
+ chunk.c();
+ chunk.d();
+
+ if (!chunk.n && this.a(x + 1, z + 1) && this.a(x, z + 1) && this.a(x + 1, z)) {
+ this.a(this, x, z);
+ }
+
+ if (this.a(x - 1, z) && !this.b(x - 1, z).n && this.a(x - 1, z + 1) && this.a(x, z + 1) && this.a(x - 1, z)) {
+ this.a(this, x - 1, z);
+ }
+
+ if (this.a(x, z - 1) && !this.b(x, z - 1).n && this.a(x + 1, z - 1) && this.a(x, z - 1) && this.a(x + 1, z)) {
+ this.a(this, x, z - 1);
+ }
+
+ if (this.a(x - 1, z - 1) && !this.b(x - 1, z - 1).n && this.a(x - 1, z - 1) && this.a(x, z - 1) && this.a(x - 1, z)) {
+ this.a(this, x - 1, z - 1);
+ }
+ }
+ }
+ return chunk;
+ }
+ // CraftBukkit end
+
public void c(int i, int j) {
int k = i * 16 + 8 - this.g.spawnX;
int l = j * 16 + 8 - this.g.spawnZ;