diff --git a/src/main/java/de/craftinc/borderprotection/Plugin.java b/src/main/java/de/craftinc/borderprotection/Plugin.java index b0df6ef..e898d0f 100644 --- a/src/main/java/de/craftinc/borderprotection/Plugin.java +++ b/src/main/java/de/craftinc/borderprotection/Plugin.java @@ -49,7 +49,6 @@ public class Plugin extends JavaPlugin PlayerMoveListener playerMoveListener = new PlayerMoveListener(); PlayerTeleportListener playerTeleportListener = new PlayerTeleportListener(); PlayerLoginListener playerLoginListener = new PlayerLoginListener(); - ChunkLoadingListener chunkLoadingListener = new ChunkLoadingListener(); PlayerQuitListener playerQuitListener = new PlayerQuitListener(); // commands @@ -61,7 +60,6 @@ public class Plugin extends JavaPlugin pm.registerEvents(playerMoveListener, this); pm.registerEvents(playerTeleportListener, this); pm.registerEvents(playerLoginListener, this); - pm.registerEvents(chunkLoadingListener, this); pm.registerEvents(playerQuitListener, this); } } diff --git a/src/main/java/de/craftinc/borderprotection/events/ChunkLoadingListener.java b/src/main/java/de/craftinc/borderprotection/events/ChunkLoadingListener.java deleted file mode 100644 index 37c061e..0000000 --- a/src/main/java/de/craftinc/borderprotection/events/ChunkLoadingListener.java +++ /dev/null @@ -1,46 +0,0 @@ -/* Craft Inc. BorderProtection - Copyright (C) 2013 Paul Schulze, Tobias Ottenweller - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -package de.craftinc.borderprotection.events; - -import de.craftinc.borderprotection.Plugin; -import de.craftinc.borderprotection.util.ChunkGenerator; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.world.ChunkLoadEvent; -import org.bukkit.event.world.ChunkPopulateEvent; - -public class ChunkLoadingListener implements Listener -{ -// @SuppressWarnings("unused") -// @EventHandler(priority = EventPriority.NORMAL) -// public void onChunkPopulate( ChunkPopulateEvent e ) -// { -// System.out.println("populate: " + e.getChunk()); -// -// ChunkGenerator.handleChunkLoad(e.getChunk(), true); -// } - - - @SuppressWarnings("unused") - @EventHandler(priority = EventPriority.NORMAL) - public void onChunkLoad( ChunkLoadEvent e ) - { - boolean populated = !e.isNewChunk(); - ChunkGenerator.handleChunkLoad(e.getChunk(), populated); - } -} diff --git a/src/main/java/de/craftinc/borderprotection/util/ChunkGenerator.java b/src/main/java/de/craftinc/borderprotection/util/ChunkGenerator.java index c1ea126..2f66615 100644 --- a/src/main/java/de/craftinc/borderprotection/util/ChunkGenerator.java +++ b/src/main/java/de/craftinc/borderprotection/util/ChunkGenerator.java @@ -16,25 +16,21 @@ */ package de.craftinc.borderprotection.util; -import de.craftinc.borderprotection.Messages; import de.craftinc.borderprotection.Plugin; 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.Location; 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.HashMap; -import java.util.Map; public class ChunkGenerator { - protected static Map chunkGenerationStatus = new HashMap(); + protected static HashMap chunkGenerationStatus = new HashMap(); protected static boolean isPaused = true; - protected static ArrayList loadedChunks = new ArrayList(); + + public static long waitTicks = 5; // TODO: make adjustable via config file public static void pause() { @@ -49,7 +45,7 @@ public class ChunkGenerator for (World w : chunkGenerationStatus.keySet()) { - loadNextChunk(w); + slowLoadNextChunk(w); } } } @@ -107,74 +103,28 @@ public class ChunkGenerator return true; } - public static void handleChunkLoad(Chunk c, boolean isPopulated) + protected static void slowLoadNextChunk(World w) { - if (c == null) + if (w == null) { - throw new IllegalArgumentException("Chunk 'c' must not be null!"); + throw new IllegalArgumentException("World 'w' must not be null!"); } - if (isPaused) - { - return; - } - - World w = c.getWorld(); - Integer[] currentGenerationChunk = chunkGenerationStatus.get(w); - - if ((currentGenerationChunk != null) && c.getX() == currentGenerationChunk[0] && c.getZ() == currentGenerationChunk[1]) - { - if (!isPopulated) - { -// Plugin.instance.getLogger().info("Trying to get the chunk to get populated"); - - ChunkProviderServer cps = ((CraftWorld) w).getHandle().chunkProviderServer; - cps.chunkProvider.getOrCreateChunk(c.getX(), c.getZ()); - - - } - - DelayedCall delayedCall = new DelayedCall(); - delayedCall.w = w; - Bukkit.getScheduler().scheduleSyncDelayedTask(Plugin.instance, delayedCall, 10L); - - -// loadNextChunk(w); - } + DelayedCall delayedCall = new DelayedCall(); + delayedCall.w = w; + Bukkit.getScheduler().scheduleSyncDelayedTask(Plugin.instance, delayedCall, waitTicks); } -// protected static void loadSurroundingChunks(int x, int z, World w) -// { -// int radius = 2; -// -// for (int i=-radius; i> 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++; while (!chunkIsInsideBorder(chunkX, chunkZ, w, border) - && chunkZ <= maxChunkZ - /*&& !w.isChunkLoaded(chunkX, chunkZ)*/) + && chunkZ <= maxChunkZ) { chunkX++; @@ -220,7 +165,11 @@ public class ChunkGenerator { chunkGenerationStatus.put(w, new Integer[]{chunkX, chunkZ}); Plugin.instance.getLogger().info("Loading/Generating Chunk ( x=" + chunkX + " z=" + chunkZ + " world=" + w.getName() + " )"); - w.loadChunk(chunkX, chunkZ, true); + + Chunk chunk = w.getChunkAt(chunkX, chunkZ); + chunk.load(true); + + slowLoadNextChunk(w); } else {