From 9473ca8f6f5575d18652a0212f5d6e859e4053c6 Mon Sep 17 00:00:00 2001 From: Drakia Date: Mon, 14 Mar 2011 19:26:04 -0700 Subject: [PATCH] Fixed an issue with removing stargates during load --- README | 2 ++ src/net/TheDgtl/Stargate/Portal.java | 22 ++++++++++++++++++---- src/net/TheDgtl/Stargate/Stargate.java | 4 ++-- src/plugin.yml | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/README b/README index af44b66..0a190ac 100644 --- a/README +++ b/README @@ -86,6 +86,8 @@ destroyexplosion - Whether to destroy a stargate with explosions, or stop an exp ============= Changes ============= +[Version 0.28] + - Fixed an issue with removing stargates during load [Version 0.27] - Fixed portal count on load [Version 0.26] diff --git a/src/net/TheDgtl/Stargate/Portal.java b/src/net/TheDgtl/Stargate/Portal.java index 299c2e9..cac240a 100644 --- a/src/net/TheDgtl/Stargate/Portal.java +++ b/src/net/TheDgtl/Stargate/Portal.java @@ -5,6 +5,7 @@ import java.io.File; import java.io.FileWriter; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.Scanner; import java.util.logging.Level; @@ -297,6 +298,14 @@ public class Portal { public String getDestinationName() { return destination; } + + public boolean isChunkLoaded() { + return topLeft.getWorld().isChunkLoaded(topLeft.getBlock().getChunk()); + } + + public void loadChunk() { + topLeft.getWorld().loadChunk(topLeft.getBlock().getChunk()); + } public boolean isVerified() { for (RelativeBlockVector control : gate.getControls()) @@ -454,7 +463,7 @@ public class Portal { return frame; } - public void unregister() { + public void unregister(boolean removeAll) { Stargate.log.info("[Stargate] Unregistering gate " + getName()); close(true); lookupNamesNet.get(getNetwork().toLowerCase()).remove(getName().toLowerCase()); @@ -472,7 +481,9 @@ public class Portal { lookupEntrances.remove(entrance); } - allPortals.remove(this); + if (removeAll) + allPortals.remove(this); + allPortalsNet.get(getNetwork().toLowerCase()).remove(getName().toLowerCase()); if (id.getBlock().getType() == Material.WALL_SIGN) { @@ -776,13 +787,16 @@ public class Portal { // Open any always-on gates. Do this here as it should be more efficient than in the loop. int OpenCount = 0; - for (Portal portal : allPortals) { + //for (Portal portal : allPortals) { + for (Iterator iter = allPortals.iterator(); iter.hasNext(); ) { + Portal portal = iter.next(); if (portal == null) continue; // Verify portal integrity/register portal if (!portal.wasVerified()) { if (!portal.isVerified() || !portal.checkIntegrity()) { - portal.unregister(); + portal.unregister(false); + iter.remove(); Stargate.log.info("[Stargate] Destroying stargate at " + portal.toString()); continue; } else { diff --git a/src/net/TheDgtl/Stargate/Stargate.java b/src/net/TheDgtl/Stargate/Stargate.java index 032e089..9241ecd 100644 --- a/src/net/TheDgtl/Stargate/Stargate.java +++ b/src/net/TheDgtl/Stargate/Stargate.java @@ -423,7 +423,7 @@ public class Stargate extends JavaPlugin { if (hasPerm(player, "stargate.destroy", player.isOp()) || hasPerm(player, "stargate.destroy.all", player.isOp()) || ( portal.getOwner().equalsIgnoreCase(player.getName()) && hasPerm(player, "stargate.destroy.owner", false) )) { - portal.unregister(); + portal.unregister(true); if (!dmgMsg.isEmpty()) { player.sendMessage(ChatColor.RED + dmgMsg); } @@ -471,7 +471,7 @@ public class Stargate extends JavaPlugin { Portal portal = Portal.getByBlock(b); if (portal == null) continue; if (destroyExplosion) { - portal.unregister(); + portal.unregister(true); } else { b.setType(b.getType()); event.setCancelled(true); diff --git a/src/plugin.yml b/src/plugin.yml index 62dca74..6dd4147 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: Stargate main: net.TheDgtl.Stargate.Stargate -version: 0.27 +version: 0.28 description: Stargate mod for Bukkit author: Drakia website: http://www.thedgtl.net \ No newline at end of file