Further alleviating the time it takes to load chunks.

This commit is contained in:
Glitchfinder 2013-01-20 15:46:53 -08:00
parent b7354779d4
commit 57d1cd5f63
2 changed files with 43 additions and 24 deletions

View File

@ -2,11 +2,16 @@ package com.gmail.nossr50.listeners;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Chunk;
import org.bukkit.TreeType;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -76,8 +81,17 @@ public class WorldListener implements Listener {
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
Chunk chunk = event.getChunk();
if (chunk.getEntities().length > 0) {
List<Entity> chunkMobs = new ArrayList(Arrays.asList(chunk.getEntities()));
if (chunkMobs.isEmpty())
return;
for(Entity entity : chunkMobs) {
if(!(entity instanceof LivingEntity) && !(entity instanceof FallingBlock))
continue;
mcMMO.placeStore.loadChunk(chunk.getX(), chunk.getZ(), event.getWorld());
return;
}
}
}

View File

@ -8,6 +8,7 @@ import java.io.ObjectOutputStream;
import java.lang.Boolean;
import java.lang.Integer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -161,12 +162,13 @@ public class HashChunkManager implements ChunkManager {
UUID key = world.getUID();
boolean oldDataHasKey = oldData.containsKey(key);
boolean converted = false;
if (!oldDataHasKey) {
oldData.put(key, (new File(world.getWorldFolder(), "mcmmo_data")).exists());
}
else if (oldData.get(key)) {
convertChunk(new File(world.getWorldFolder(), "mcmmo_data"), cx, cz, world, true);
converted = convertChunk(new File(world.getWorldFolder(), "mcmmo_data"), cx, cz, world, true);
}
try {
@ -174,7 +176,9 @@ public class HashChunkManager implements ChunkManager {
}
catch(Exception e) {}
if (in != null) {
if (in == null || converted)
return;
store.put(world.getName() + "," + cx + "," + cz, in);
List<UUID> mobs = in.getSpawnedMobs();
@ -184,12 +188,12 @@ public class HashChunkManager implements ChunkManager {
iteratingMobs = true;
for (LivingEntity entity : world.getLivingEntities()) {
if (mobs.contains(entity.getUniqueId()))
addSpawnedMob(entity);
}
List<Entity> chunkMobs = new ArrayList(Arrays.asList(world.getChunkAt(cx, cz).getEntities()));
for (Entity entity : chunkMobs) {
if(!(entity instanceof LivingEntity) && !(entity instanceof FallingBlock))
continue;
for(FallingBlock entity: world.getEntitiesByClass(FallingBlock.class)) {
if (mobs.contains(entity.getUniqueId()))
addSpawnedMob(entity);
}
@ -199,7 +203,6 @@ public class HashChunkManager implements ChunkManager {
in.clearSpawnedMobs();
}
}
@Override
public synchronized void unloadChunk(int cx, int cz, World world) {
@ -546,14 +549,14 @@ public class HashChunkManager implements ChunkManager {
convertChunk(dataDir, cx, cz, world, false);
}
public synchronized void convertChunk(File dataDir, int cx, int cz, World world, boolean actually) {
public synchronized boolean convertChunk(File dataDir, int cx, int cz, World world, boolean actually) {
if (!actually)
return;
if (!dataDir.exists()) return;
return false;
if (!dataDir.exists()) return false;
File cxDir = new File(dataDir, "" + cx);
if (!cxDir.exists()) return;
if (!cxDir.exists()) return false;
File czDir = new File(cxDir, "" + cz);
if (!czDir.exists()) return;
if (!czDir.exists()) return false;
boolean conversionSet = false;
@ -574,6 +577,8 @@ public class HashChunkManager implements ChunkManager {
converter.start(world, cxDir, czDir);
converters.add(converter);
}
return true;
}
public boolean isSpawnedMob(Entity entity) {