Made chunk generator generate chunks. (Code needs cleanup.)
This commit is contained in:
parent
5b75b83c5b
commit
8592f4ada1
@ -26,12 +26,14 @@ import org.bukkit.event.world.ChunkPopulateEvent;
|
|||||||
|
|
||||||
public class ChunkLoadingListener implements Listener
|
public class ChunkLoadingListener implements Listener
|
||||||
{
|
{
|
||||||
@SuppressWarnings("unused")
|
// @SuppressWarnings("unused")
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
// @EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onChunkPopulate( ChunkPopulateEvent e )
|
// public void onChunkPopulate( ChunkPopulateEvent e )
|
||||||
{
|
// {
|
||||||
ChunkGenerator.handleChunkLoad(e.getChunk(), true);
|
// System.out.println("populate: " + e.getChunk());
|
||||||
}
|
//
|
||||||
|
// ChunkGenerator.handleChunkLoad(e.getChunk(), true);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
@ -16,11 +16,15 @@
|
|||||||
*/
|
*/
|
||||||
package de.craftinc.borderprotection.util;
|
package de.craftinc.borderprotection.util;
|
||||||
|
|
||||||
|
import de.craftinc.borderprotection.Messages;
|
||||||
import de.craftinc.borderprotection.Plugin;
|
import de.craftinc.borderprotection.Plugin;
|
||||||
import de.craftinc.borderprotection.borders.Border;
|
import de.craftinc.borderprotection.borders.Border;
|
||||||
|
import net.minecraft.server.v1_5_R3.ChunkProviderServer; // NOTE: this will break with any new Bukkit/Minecraft version!
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.craftbukkit.v1_5_R3.CraftWorld; // NOTE: this will break with any new Bukkit/Minecraft version!
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -122,43 +126,48 @@ public class ChunkGenerator
|
|||||||
{
|
{
|
||||||
if (!isPopulated)
|
if (!isPopulated)
|
||||||
{
|
{
|
||||||
Plugin.instance.getLogger().info("Trying to get the chunk to get populated");
|
// Plugin.instance.getLogger().info("Trying to get the chunk to get populated");
|
||||||
// loadSurroundingChunks(c.getX(), c.getZ(), w);
|
|
||||||
|
ChunkProviderServer cps = ((CraftWorld) w).getHandle().chunkProviderServer;
|
||||||
|
cps.chunkProvider.getOrCreateChunk(c.getX(), c.getZ());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
DelayedCall delayedCall = new DelayedCall();
|
||||||
unloadLoadedChunks();
|
delayedCall.w = w;
|
||||||
loadNextChunk(c.getWorld());
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Plugin.instance, delayedCall, 10L);
|
||||||
}
|
|
||||||
|
|
||||||
|
// loadNextChunk(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void loadSurroundingChunks(int x, int z, World w)
|
// protected static void loadSurroundingChunks(int x, int z, World w)
|
||||||
{
|
// {
|
||||||
int radius = 2;
|
// int radius = 2;
|
||||||
|
//
|
||||||
for (int i=-radius; i<radius; i++)
|
// for (int i=-radius; i<radius; i++)
|
||||||
{
|
// {
|
||||||
for (int j=-radius; j<radius; j++)
|
// for (int j=-radius; j<radius; j++)
|
||||||
{
|
// {
|
||||||
if (j == 0 && i == 0)
|
// if (j == 0 && i == 0)
|
||||||
{
|
// {
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
w.loadChunk(i+x, j+z, false);
|
// w.loadChunk(i+x, j+z, false);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
protected static void unloadLoadedChunks()
|
// protected static void unloadLoadedChunks()
|
||||||
{
|
// {
|
||||||
for (Chunk c : loadedChunks)
|
// for (Chunk c : loadedChunks)
|
||||||
{
|
// {
|
||||||
c.getWorld().unloadChunk(c);
|
// c.getWorld().unloadChunk(c);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -188,6 +197,10 @@ public class ChunkGenerator
|
|||||||
int maxChunkX = Math.max(borderRect[0].getBlockX(), borderRect[1].getBlockX()) >> 4;
|
int maxChunkX = Math.max(borderRect[0].getBlockX(), borderRect[1].getBlockX()) >> 4;
|
||||||
int maxChunkZ = Math.max(borderRect[0].getBlockZ(), borderRect[1].getBlockZ()) >> 4;
|
int maxChunkZ = Math.max(borderRect[0].getBlockZ(), borderRect[1].getBlockZ()) >> 4;
|
||||||
|
|
||||||
|
// System.out.println("minChunkX: " + minChunkX);
|
||||||
|
// System.out.println("maxChunkX: " + maxChunkX);
|
||||||
|
// System.out.println("maxChunkZ: " + maxChunkZ);
|
||||||
|
|
||||||
chunkX++;
|
chunkX++;
|
||||||
|
|
||||||
while (!chunkIsInsideBorder(chunkX, chunkZ, w, border)
|
while (!chunkIsInsideBorder(chunkX, chunkZ, w, border)
|
||||||
@ -207,7 +220,6 @@ public class ChunkGenerator
|
|||||||
{
|
{
|
||||||
chunkGenerationStatus.put(w, new Integer[]{chunkX, chunkZ});
|
chunkGenerationStatus.put(w, new Integer[]{chunkX, chunkZ});
|
||||||
Plugin.instance.getLogger().info("Loading/Generating Chunk ( x=" + chunkX + " z=" + chunkZ + " world=" + w.getName() + " )");
|
Plugin.instance.getLogger().info("Loading/Generating Chunk ( x=" + chunkX + " z=" + chunkZ + " world=" + w.getName() + " )");
|
||||||
// loadSurroundingChunks(chunkX, chunkZ, w);
|
|
||||||
w.loadChunk(chunkX, chunkZ, true);
|
w.loadChunk(chunkX, chunkZ, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -219,8 +231,18 @@ public class ChunkGenerator
|
|||||||
|
|
||||||
protected static boolean chunkIsInsideBorder(int x, int z, World w, Border b)
|
protected static boolean chunkIsInsideBorder(int x, int z, World w, Border b)
|
||||||
{
|
{
|
||||||
// Location chunkLocation = new Location(w, (double)(x << 4), (double)100, (double)(z << 4));
|
Location chunkLocation = new Location(w, (double)(x << 4), (double)100, (double)(z << 4));
|
||||||
// return b.checkBorder(chunkLocation) == null;
|
return b.checkBorder(chunkLocation) == null;
|
||||||
return true;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class DelayedCall implements Runnable
|
||||||
|
{
|
||||||
|
public World w;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ChunkGenerator.loadNextChunk(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user