2011-01-04 16:54:41 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.*;
|
2011-01-11 09:25:13 +01:00
|
|
|
|
|
|
|
// CraftBukkit start
|
2011-01-04 16:54:41 +01:00
|
|
|
import org.bukkit.craftbukkit.CraftChunk;
|
|
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.CraftWorld;
|
|
|
|
import org.bukkit.event.Event.Type;
|
|
|
|
import org.bukkit.event.world.ChunkLoadedEvent;
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit end
|
2011-01-04 16:54:41 +01:00
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
public class ChunkProviderServer implements IChunkProvider {
|
2011-01-04 16:54:41 +01:00
|
|
|
|
|
|
|
private Set a;
|
|
|
|
private Chunk b;
|
|
|
|
private IChunkProvider c;
|
|
|
|
private IChunkLoader d;
|
|
|
|
private Map e;
|
|
|
|
private List f;
|
|
|
|
private WorldServer g;
|
|
|
|
|
|
|
|
public ChunkProviderServer(WorldServer worldserver, IChunkLoader ichunkloader, IChunkProvider ichunkprovider) {
|
2011-01-11 09:25:13 +01:00
|
|
|
a = ((Set) (new HashSet()));
|
|
|
|
e = ((Map) (new HashMap()));
|
|
|
|
f = ((List) (new ArrayList()));
|
2011-01-14 14:31:10 +01:00
|
|
|
b = ((Chunk) (new EmptyChunk(((World) (worldserver)), new byte[32768], 0, 0)));
|
2011-01-04 16:54:41 +01:00
|
|
|
g = worldserver;
|
|
|
|
d = ichunkloader;
|
|
|
|
c = ichunkprovider;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a(int i, int j) {
|
|
|
|
ChunkCoordinates chunkcoordinates = new ChunkCoordinates(i, j);
|
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
return e.containsKey(((chunkcoordinates)));
|
2011-01-04 16:54:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void c(int i, int j) {
|
|
|
|
int k = (i * 16 + 8) - g.m;
|
|
|
|
int l = (j * 16 + 8) - g.o;
|
|
|
|
char c1 = '\200';
|
|
|
|
|
|
|
|
if (k < -c1 || k > c1 || l < -c1 || l > c1) {
|
2011-01-11 09:25:13 +01:00
|
|
|
a.add(((new ChunkCoordinates(i, j))));
|
2011-01-04 16:54:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Chunk d(int i, int j) {
|
|
|
|
ChunkCoordinates chunkcoordinates = new ChunkCoordinates(i, j);
|
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
a.remove(((new ChunkCoordinates(i, j))));
|
|
|
|
Chunk chunk = (Chunk) e.get(((chunkcoordinates)));
|
2011-01-04 16:54:41 +01:00
|
|
|
|
|
|
|
if (chunk == null) {
|
|
|
|
chunk = e(i, j);
|
|
|
|
if (chunk == null) {
|
|
|
|
if (c == null) {
|
|
|
|
chunk = b;
|
|
|
|
} else {
|
|
|
|
chunk = c.b(i, j);
|
|
|
|
}
|
|
|
|
}
|
2011-01-11 09:25:13 +01:00
|
|
|
e.put(((chunkcoordinates)), ((chunk)));
|
|
|
|
f.add(((chunk)));
|
2011-01-04 16:54:41 +01:00
|
|
|
if (chunk != null) {
|
2011-01-14 14:31:10 +01:00
|
|
|
chunk.c();
|
2011-01-04 16:54:41 +01:00
|
|
|
chunk.d();
|
|
|
|
}
|
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit start
|
2011-01-04 16:54:41 +01:00
|
|
|
CraftServer server = g.getServer();
|
|
|
|
if (server != null) {
|
|
|
|
/*
|
|
|
|
* If it's a new world, the first few chunks are generated inside
|
|
|
|
* the World constructor. We can't reliably alter that, so we have
|
|
|
|
* no way of creating a CraftWorld/CraftServer at that point.
|
|
|
|
*/
|
|
|
|
CraftWorld world = g.getWorld();
|
|
|
|
CraftChunk cchunk = world.updateChunk(i, j);
|
|
|
|
server.getPluginManager().callEvent(new ChunkLoadedEvent(Type.CHUNK_LOADED, cchunk));
|
|
|
|
}
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit end
|
2011-01-04 16:54:41 +01:00
|
|
|
|
|
|
|
if (!chunk.n && a(i + 1, j + 1) && a(i, j + 1) && a(i + 1, j)) {
|
2011-01-11 09:25:13 +01:00
|
|
|
a(((IChunkProvider) (this)), i, j);
|
2011-01-04 16:54:41 +01:00
|
|
|
}
|
|
|
|
if (a(i - 1, j) && !b(i - 1, j).n && a(i - 1, j + 1) && a(i, j + 1) && a(i - 1, j)) {
|
2011-01-11 09:25:13 +01:00
|
|
|
a(((IChunkProvider) (this)), i - 1, j);
|
2011-01-04 16:54:41 +01:00
|
|
|
}
|
|
|
|
if (a(i, j - 1) && !b(i, j - 1).n && a(i + 1, j - 1) && a(i, j - 1) && a(i + 1, j)) {
|
2011-01-11 09:25:13 +01:00
|
|
|
a(((IChunkProvider) (this)), i, j - 1);
|
2011-01-04 16:54:41 +01:00
|
|
|
}
|
|
|
|
if (a(i - 1, j - 1) && !b(i - 1, j - 1).n && a(i - 1, j - 1) && a(i, j - 1) && a(i - 1, j)) {
|
2011-01-11 09:25:13 +01:00
|
|
|
a(((IChunkProvider) (this)), i - 1, j - 1);
|
2011-01-04 16:54:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return chunk;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Chunk b(int i, int j) {
|
|
|
|
ChunkCoordinates chunkcoordinates = new ChunkCoordinates(i, j);
|
2011-01-11 09:25:13 +01:00
|
|
|
Chunk chunk = (Chunk) e.get(((chunkcoordinates)));
|
2011-01-04 16:54:41 +01:00
|
|
|
|
|
|
|
if (chunk == null) {
|
|
|
|
if (g.x) {
|
|
|
|
return d(i, j);
|
|
|
|
} else {
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return chunk;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Chunk e(int i, int j) {
|
|
|
|
if (d == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
try {
|
2011-01-11 09:25:13 +01:00
|
|
|
Chunk chunk = d.a(((World) (g)), i, j);
|
2011-01-04 16:54:41 +01:00
|
|
|
|
|
|
|
if (chunk != null) {
|
2011-01-14 14:31:10 +01:00
|
|
|
chunk.r = g.e;
|
2011-01-04 16:54:41 +01:00
|
|
|
}
|
|
|
|
return chunk;
|
|
|
|
} catch (Exception exception) {
|
|
|
|
exception.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void a(Chunk chunk) {
|
|
|
|
if (d == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
2011-01-11 09:25:13 +01:00
|
|
|
d.b(((World) (g)), chunk);
|
2011-01-04 16:54:41 +01:00
|
|
|
} catch (Exception exception) {
|
|
|
|
exception.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void b(Chunk chunk) {
|
|
|
|
if (d == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
2011-01-14 14:31:10 +01:00
|
|
|
chunk.r = g.e;
|
2011-01-11 09:25:13 +01:00
|
|
|
d.a(((World) (g)), chunk);
|
|
|
|
} catch (Throwable ioexception) { // CraftBukkit -- downcast to work
|
2011-01-04 16:54:41 +01:00
|
|
|
ioexception.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(IChunkProvider ichunkprovider, int i, int j) {
|
|
|
|
Chunk chunk = b(i, j);
|
|
|
|
|
|
|
|
if (!chunk.n) {
|
|
|
|
chunk.n = true;
|
|
|
|
if (c != null) {
|
|
|
|
c.a(ichunkprovider, i, j);
|
|
|
|
chunk.f();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a(boolean flag, IProgressUpdate iprogressupdate) {
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (int j = 0; j < f.size(); j++) {
|
|
|
|
Chunk chunk = (Chunk) f.get(j);
|
|
|
|
|
|
|
|
if (flag && !chunk.p) {
|
|
|
|
a(chunk);
|
|
|
|
}
|
|
|
|
if (!chunk.a(flag)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
b(chunk);
|
|
|
|
chunk.o = false;
|
|
|
|
if (++i == 24 && !flag) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
if (d == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
d.b();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a() {
|
|
|
|
if (!g.C) {
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
if (!a.isEmpty()) {
|
|
|
|
ChunkCoordinates chunkcoordinates = (ChunkCoordinates) a.iterator().next();
|
|
|
|
Chunk chunk = b(chunkcoordinates.a, chunkcoordinates.b);
|
|
|
|
|
|
|
|
chunk.e();
|
|
|
|
b(chunk);
|
|
|
|
a(chunk);
|
2011-01-11 09:25:13 +01:00
|
|
|
a.remove(((chunkcoordinates)));
|
|
|
|
e.remove(((chunkcoordinates)));
|
|
|
|
f.remove(((chunk)));
|
2011-01-04 16:54:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d != null) {
|
|
|
|
d.a();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c.a();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean b() {
|
|
|
|
return !g.C;
|
|
|
|
}
|
|
|
|
}
|