mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-25 10:27:55 +01:00
Just cleaning some commits. Don't mind me.
This commit is contained in:
parent
3526a66fbe
commit
1a983aceb3
@ -19,13 +19,13 @@ import org.bukkit.event.world.ChunkLoadEvent;
|
||||
|
||||
public class ChunkProviderServer implements IChunkProvider {
|
||||
|
||||
private LongHashset a = new LongHashset(); // CraftBukkit
|
||||
public LongHashset a = new LongHashset(); // CraftBukkit
|
||||
private Chunk b;
|
||||
private IChunkProvider c;
|
||||
private IChunkLoader d;
|
||||
private LongHashtable<Chunk> e = new LongHashtable<Chunk>(); // CraftBukkit
|
||||
private List f = new ArrayList();
|
||||
private WorldServer g;
|
||||
public LongHashtable<Chunk> e = new LongHashtable<Chunk>(); // CraftBukkit
|
||||
public List f = new ArrayList(); // Craftbukkit
|
||||
public WorldServer g; // Craftbukkit
|
||||
|
||||
public ChunkProviderServer(WorldServer worldserver, IChunkLoader ichunkloader, IChunkProvider ichunkprovider) {
|
||||
this.b = new EmptyChunk(worldserver, new byte['\u8000'], 0, 0);
|
||||
@ -35,106 +35,9 @@ public class ChunkProviderServer implements IChunkProvider {
|
||||
}
|
||||
|
||||
// CraftBukkit start
|
||||
public org.bukkit.Chunk[] getLoadedChunks() {
|
||||
Object[] chunks = e.values().toArray();
|
||||
org.bukkit.Chunk[] craftChunks = new CraftChunk[chunks.length];
|
||||
|
||||
for(int cnt =0;cnt<chunks.length;cnt++) {
|
||||
craftChunks[cnt] = ((Chunk)chunks[cnt]).bukkitChunk;
|
||||
}
|
||||
|
||||
return craftChunks;
|
||||
}
|
||||
|
||||
public boolean a(int i, int j) {
|
||||
return this.e.containsKey(i, j);
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -208,7 +111,7 @@ public class ChunkProviderServer implements IChunkProvider {
|
||||
return chunk == null ? (this.g.x ? this.d(i, j) : this.b) : chunk;
|
||||
}
|
||||
|
||||
private Chunk e(int i, int j) {
|
||||
public Chunk e(int i, int j) { // Craftbukkit - public
|
||||
if (this.d == null) {
|
||||
return null;
|
||||
} else {
|
||||
@ -227,7 +130,7 @@ public class ChunkProviderServer implements IChunkProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private void a(Chunk chunk) {
|
||||
public void a(Chunk chunk) { // Craftbukkit - public
|
||||
if (this.d != null) {
|
||||
try {
|
||||
this.d.b(this.g, chunk);
|
||||
@ -237,7 +140,7 @@ public class ChunkProviderServer implements IChunkProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private void b(Chunk chunk) {
|
||||
public void b(Chunk chunk) { // Craftbukkit - public
|
||||
if (this.d != null) {
|
||||
try {
|
||||
chunk.r = this.g.e;
|
||||
|
@ -26,12 +26,14 @@ public class CraftWorld implements World {
|
||||
private final WorldServer world;
|
||||
private final Environment environment;
|
||||
private final CraftServer server;
|
||||
private final ChunkProviderServer provider;
|
||||
|
||||
private static final Random rand = new Random();
|
||||
|
||||
public CraftWorld(WorldServer world) {
|
||||
this.world = world;
|
||||
this.server = world.getServer();
|
||||
this.provider = world.A;
|
||||
|
||||
if (world.q instanceof WorldProviderHell) {
|
||||
environment = Environment.NETHER;
|
||||
@ -59,7 +61,7 @@ public class CraftWorld implements World {
|
||||
}
|
||||
|
||||
public Chunk getChunkAt(int x, int z) {
|
||||
return this.world.A.d(x,z).bukkitChunk;
|
||||
return this.provider.d(x,z).bukkitChunk;
|
||||
}
|
||||
|
||||
public Chunk getChunkAt(Block block) {
|
||||
@ -67,21 +69,24 @@ public class CraftWorld implements World {
|
||||
}
|
||||
|
||||
public boolean isChunkLoaded(int x, int z) {
|
||||
return world.A.a( x, z );
|
||||
return provider.a( x, z );
|
||||
}
|
||||
|
||||
public Chunk[] getLoadedChunks() {
|
||||
return world.A.getLoadedChunks();
|
||||
net.minecraft.server.Chunk[] chunks = (net.minecraft.server.Chunk[])provider.e.values().toArray();
|
||||
org.bukkit.Chunk[] craftChunks = new CraftChunk[chunks.length];
|
||||
|
||||
for (int i = 0; i < chunks.length; i++) {
|
||||
craftChunks[i] = chunks[i].bukkitChunk;
|
||||
}
|
||||
|
||||
return craftChunks;
|
||||
}
|
||||
|
||||
public void loadChunk(int x, int z) {
|
||||
loadChunk(x, z, true);
|
||||
}
|
||||
|
||||
public boolean loadChunk(int x, int z, boolean generate) {
|
||||
return world.A.loadChunk(x, z, generate) != null;
|
||||
}
|
||||
|
||||
public boolean unloadChunk(int x, int z) {
|
||||
return unloadChunk(x, z, true);
|
||||
}
|
||||
@ -89,17 +94,97 @@ public class CraftWorld implements World {
|
||||
public boolean unloadChunk(int x, int z, boolean save) {
|
||||
return unloadChunk(x, z, save, false);
|
||||
}
|
||||
|
||||
public boolean unloadChunk(int x, int z, boolean save, boolean safe) {
|
||||
return world.A.unloadChunk(x, z, save, safe);
|
||||
}
|
||||
|
||||
public boolean unloadChunkRequest(int x, int z) {
|
||||
return unloadChunkRequest(x, z, true);
|
||||
}
|
||||
|
||||
public boolean unloadChunkRequest(int x, int z, boolean safe) {
|
||||
return world.A.unloadChunkRequest(x, z, safe);
|
||||
if (safe && isChunkInUse(x, z)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
provider.c(x, z);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean unloadChunk(int x, int z, boolean save, boolean safe) {
|
||||
if (safe && isChunkInUse(x, z)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
net.minecraft.server.Chunk chunk = provider.b(x, z);
|
||||
|
||||
if (save) {
|
||||
chunk.e();
|
||||
provider.b(chunk);
|
||||
provider.a(chunk);
|
||||
}
|
||||
|
||||
provider.a.remove(x, z);
|
||||
provider.e.remove(x, z);
|
||||
provider.f.remove(chunk);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isChunkInUse(int x, int z) {
|
||||
Player[] players = server.getOnlinePlayers();
|
||||
|
||||
for (Player player : players) {
|
||||
Location loc = player.getLocation();
|
||||
if (loc.getWorld() != provider.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 boolean loadChunk(int x, int z, boolean generate) {
|
||||
if (generate) {
|
||||
// Use the default variant of loadChunk when generate == true.
|
||||
return provider.d(x, z) != null;
|
||||
}
|
||||
|
||||
provider.a.remove(x, z);
|
||||
net.minecraft.server.Chunk chunk = (net.minecraft.server.Chunk) provider.e.get(x, z);
|
||||
|
||||
if (chunk == null) {
|
||||
chunk = provider.e(x, z);
|
||||
|
||||
if (chunk != null) {
|
||||
provider.e.put(x, z, chunk);
|
||||
provider.f.add(chunk);
|
||||
|
||||
chunk.c();
|
||||
chunk.d();
|
||||
|
||||
if (!chunk.n && provider.a(x + 1, z + 1) && provider.a(x, z + 1) && provider.a(x + 1, z)) {
|
||||
provider.a(provider, x, z);
|
||||
}
|
||||
|
||||
if (provider.a(x - 1, z) && !provider.b(x - 1, z).n && provider.a(x - 1, z + 1) && provider.a(x, z + 1) && provider.a(x - 1, z)) {
|
||||
provider.a(provider, x - 1, z);
|
||||
}
|
||||
|
||||
if (provider.a(x, z - 1) && !provider.b(x, z - 1).n && provider.a(x + 1, z - 1) && provider.a(x, z - 1) && provider.a(x + 1, z)) {
|
||||
provider.a(provider, x, z - 1);
|
||||
}
|
||||
|
||||
if (provider.a(x - 1, z - 1) && !provider.b(x - 1, z - 1).n && provider.a(x - 1, z - 1) && provider.a(x, z - 1) && provider.a(x - 1, z)) {
|
||||
provider.a(provider, x - 1, z - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return chunk != null;
|
||||
}
|
||||
|
||||
public boolean isChunkLoaded(Chunk chunk) {
|
||||
|
Loading…
Reference in New Issue
Block a user