From 52a9278dfcfe93043fd5d7a6f4d89629521b7687 Mon Sep 17 00:00:00 2001 From: Tobias Ottenweller Date: Mon, 12 Mar 2012 22:50:29 +0100 Subject: [PATCH] fixing problem with gates saved in older version (hopefully); check if gate is really open in isOpen() method --- src/org/mcteam/ancientgates/Gate.java | 40 ++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/org/mcteam/ancientgates/Gate.java b/src/org/mcteam/ancientgates/Gate.java index f03d15e..b27bd94 100644 --- a/src/org/mcteam/ancientgates/Gate.java +++ b/src/org/mcteam/ancientgates/Gate.java @@ -81,7 +81,7 @@ public class Gate public Integer[][] getGateBlocks() { - return gateBlocks; + return gateBlocks; } @@ -200,6 +200,22 @@ public class Gate public boolean isOpen() { + // check if gate is really open + if (getGateBlocks() == null) + { + isOpen = false; + } + else if (!isHidden()) + { + Integer[] gateBlock = getGateBlocks()[0]; + Block b = new Location(from.getWorld(), gateBlock[0], gateBlock[1], gateBlock[2]).getBlock(); + + if (b.getType() != Material.PORTAL) + { + isOpen = false; + } + } + return this.isOpen; } @@ -294,6 +310,28 @@ public class Gate fillIds(); + // old releases did not save gate blocks - this fixes the problem + for (Gate g : getAll()) + { + if (g.getGateBlocks() == null && g.getFrom() != null) + { + Plugin.log("Fixing problems with old gate: " + g.getId()); + + Set gateBlocks = FloodUtil.getGateFrameBlocks(g.getFrom().getBlock()); + + if (gateBlocks == null) + continue; + + g.setGateBlocks(gateBlocks); + + if (((Block) gateBlocks.toArray()[0]).getType() == Material.PORTAL ) + g.setOpen(true); + } + + } + save(); + // end of fix + return true; }