mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-02 08:39:49 +01:00
Merge pull request #543 from Glitchfinder/master
Slightly reducing the processing required to load and unload chunks.
This commit is contained in:
commit
f7aba26be2
@ -7,6 +7,9 @@ import org.bukkit.Chunk;
|
|||||||
import org.bukkit.TreeType;
|
import org.bukkit.TreeType;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.BlockState;
|
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.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -76,8 +79,17 @@ public class WorldListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChunkLoad(ChunkLoadEvent event) {
|
public void onChunkLoad(ChunkLoadEvent event) {
|
||||||
Chunk chunk = event.getChunk();
|
Chunk chunk = event.getChunk();
|
||||||
if (chunk.getEntities().length > 0) {
|
Entity[] chunkMobs = chunk.getEntities();
|
||||||
|
|
||||||
|
if (chunkMobs.length <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(Entity entity : chunkMobs) {
|
||||||
|
if(!(entity instanceof LivingEntity) && !(entity instanceof FallingBlock))
|
||||||
|
continue;
|
||||||
|
|
||||||
mcMMO.placeStore.loadChunk(chunk.getX(), chunk.getZ(), event.getWorld());
|
mcMMO.placeStore.loadChunk(chunk.getX(), chunk.getZ(), event.getWorld());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -161,12 +162,13 @@ public class HashChunkManager implements ChunkManager {
|
|||||||
|
|
||||||
UUID key = world.getUID();
|
UUID key = world.getUID();
|
||||||
boolean oldDataHasKey = oldData.containsKey(key);
|
boolean oldDataHasKey = oldData.containsKey(key);
|
||||||
|
boolean converted = false;
|
||||||
|
|
||||||
if (!oldDataHasKey) {
|
if (!oldDataHasKey) {
|
||||||
oldData.put(key, (new File(world.getWorldFolder(), "mcmmo_data")).exists());
|
oldData.put(key, (new File(world.getWorldFolder(), "mcmmo_data")).exists());
|
||||||
}
|
}
|
||||||
else if (oldData.get(key)) {
|
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 {
|
try {
|
||||||
@ -174,7 +176,9 @@ public class HashChunkManager implements ChunkManager {
|
|||||||
}
|
}
|
||||||
catch(Exception e) {}
|
catch(Exception e) {}
|
||||||
|
|
||||||
if (in != null) {
|
if (in == null || converted)
|
||||||
|
return;
|
||||||
|
|
||||||
store.put(world.getName() + "," + cx + "," + cz, in);
|
store.put(world.getName() + "," + cx + "," + cz, in);
|
||||||
|
|
||||||
List<UUID> mobs = in.getSpawnedMobs();
|
List<UUID> mobs = in.getSpawnedMobs();
|
||||||
@ -184,12 +188,12 @@ public class HashChunkManager implements ChunkManager {
|
|||||||
|
|
||||||
iteratingMobs = true;
|
iteratingMobs = true;
|
||||||
|
|
||||||
for (LivingEntity entity : world.getLivingEntities()) {
|
Entity[] chunkMobs = world.getChunkAt(cx, cz).getEntities();
|
||||||
if (mobs.contains(entity.getUniqueId()))
|
|
||||||
addSpawnedMob(entity);
|
for (Entity entity : chunkMobs) {
|
||||||
}
|
if(!(entity instanceof LivingEntity) && !(entity instanceof FallingBlock))
|
||||||
|
continue;
|
||||||
|
|
||||||
for(FallingBlock entity: world.getEntitiesByClass(FallingBlock.class)) {
|
|
||||||
if (mobs.contains(entity.getUniqueId()))
|
if (mobs.contains(entity.getUniqueId()))
|
||||||
addSpawnedMob(entity);
|
addSpawnedMob(entity);
|
||||||
}
|
}
|
||||||
@ -199,7 +203,6 @@ public class HashChunkManager implements ChunkManager {
|
|||||||
|
|
||||||
in.clearSpawnedMobs();
|
in.clearSpawnedMobs();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void unloadChunk(int cx, int cz, World world) {
|
public synchronized void unloadChunk(int cx, int cz, World world) {
|
||||||
@ -286,10 +289,12 @@ public class HashChunkManager implements ChunkManager {
|
|||||||
if (entity == null || world == null)
|
if (entity == null || world == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (entity.getLocation().getChunk().getX() != cx)
|
Chunk chunk = entity.getLocation().getChunk();
|
||||||
|
|
||||||
|
if (chunk.getX() != cx)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (entity.getLocation().getChunk().getZ() != cz)
|
if (chunk.getZ() != cz)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (entity.getWorld() != world)
|
if (entity.getWorld() != world)
|
||||||
@ -546,14 +551,14 @@ public class HashChunkManager implements ChunkManager {
|
|||||||
convertChunk(dataDir, cx, cz, world, false);
|
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)
|
if (!actually)
|
||||||
return;
|
return false;
|
||||||
if (!dataDir.exists()) return;
|
if (!dataDir.exists()) return false;
|
||||||
File cxDir = new File(dataDir, "" + cx);
|
File cxDir = new File(dataDir, "" + cx);
|
||||||
if (!cxDir.exists()) return;
|
if (!cxDir.exists()) return false;
|
||||||
File czDir = new File(cxDir, "" + cz);
|
File czDir = new File(cxDir, "" + cz);
|
||||||
if (!czDir.exists()) return;
|
if (!czDir.exists()) return false;
|
||||||
|
|
||||||
boolean conversionSet = false;
|
boolean conversionSet = false;
|
||||||
|
|
||||||
@ -574,6 +579,8 @@ public class HashChunkManager implements ChunkManager {
|
|||||||
converter.start(world, cxDir, czDir);
|
converter.start(world, cxDir, czDir);
|
||||||
converters.add(converter);
|
converters.add(converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSpawnedMob(Entity entity) {
|
public boolean isSpawnedMob(Entity entity) {
|
||||||
|
Loading…
Reference in New Issue
Block a user