diff --git a/plugin/src/lightling/gibsoniacraft/GibsoniaCraft.java b/plugin/src/lightling/gibsoniacraft/GibsoniaCraft.java index 372746e..fb44293 100644 --- a/plugin/src/lightling/gibsoniacraft/GibsoniaCraft.java +++ b/plugin/src/lightling/gibsoniacraft/GibsoniaCraft.java @@ -62,8 +62,20 @@ public final class GibsoniaCraft extends JavaPlugin { if (!this.loadedChunks.contains(chunk)) { chunk.setForceLoaded(true); + this.loadedChunks.add(chunk); } - - this.loadedChunks.add(chunk); + } + + /** + * Removes a chunk from the list of force-loaded chunks + * @param chunk The chunk to remove as force-loaded + */ + public void ForceChunkInactive(final Chunk chunk) + { + if (this.loadedChunks.contains(chunk)) + { + chunk.setForceLoaded(false); + this.loadedChunks.remove(chunk); + } } } diff --git a/plugin/src/lightling/gibsoniacraft/listener/BlockListener.java b/plugin/src/lightling/gibsoniacraft/listener/BlockListener.java index f68aafc..9b2f0f7 100644 --- a/plugin/src/lightling/gibsoniacraft/listener/BlockListener.java +++ b/plugin/src/lightling/gibsoniacraft/listener/BlockListener.java @@ -27,6 +27,7 @@ import lightling.gibsoniacraft.util.ToolUtil; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.ItemMeta; + import org.bukkit.enchantments.Enchantment; /** @@ -306,10 +307,31 @@ public class BlockListener implements Listener item.setItemMeta(meta); } + /** + * Handle the placing of chunk loaders + * @param bpEvent The event that triggered this method + */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void LoaderPlace(BlockPlaceEvent bpEvent) { - Chunk chunk = bpEvent.getBlock().getLocation().getChunk(); - this.gcPlugin.ForceChunkActive(chunk); + if (bpEvent.getBlock().hasMetadata("Keeps chunks loaded")) + { + Chunk chunk = bpEvent.getBlock().getLocation().getChunk(); + this.gcPlugin.ForceChunkActive(chunk); + } + } + + /** + * Handle the breaking of chunk loaders + * @param bbEvent The event that triggered this method + */ + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void LoaderDestroy(BlockBreakEvent bbEvent) + { + if (bbEvent.getBlock().hasMetadata("Keeps chunks loaded")) + { + Chunk chunk = bbEvent.getBlock().getLocation().getChunk(); + this.gcPlugin.ForceChunkInactive(chunk); + } } }