From 2d830b2f9f4911a55e1f4eb66a1111227ea0c5f5 Mon Sep 17 00:00:00 2001 From: Tobias Ottenweller Date: Sat, 6 Jul 2013 17:13:28 +0200 Subject: [PATCH] Fixed a bug where players got teleported at the old location of a gate when a new location has been set. --- src/de/craftinc/gates/Gate.java | 29 ++++++++++++----- .../gates/commands/CommandLocation.java | 32 +++++++------------ .../craftinc/gates/commands/CommandOpen.java | 1 + .../gates/util/GateBlockChangeSender.java | 10 ++++-- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/de/craftinc/gates/Gate.java b/src/de/craftinc/gates/Gate.java index c3c9474..cb20d44 100644 --- a/src/de/craftinc/gates/Gate.java +++ b/src/de/craftinc/gates/Gate.java @@ -77,12 +77,13 @@ public class Gate implements ConfigurationSerializable this.location = location; if (isOpen) { - if (this.gateBlockLocations == null || this.gateBlockLocations.size() == 0 ) { - findPortalBlocks(); - } - + findPortalBlocks(); validate(); } + else { + this.gateBlockLocations = new HashSet(); + this.gateFrameBlocks = new HashSet(); + } } @@ -211,17 +212,26 @@ public class Gate implements ConfigurationSerializable } if (location == null) { - setOpen(false); + isOpen = false; + this.gateBlockLocations = new HashSet(); + this.gateFrameBlocks = new HashSet(); + throw new Exception("Gate got closed. It has no location."); } if (exit == null) { - setOpen(false); + isOpen = false; + this.gateBlockLocations = new HashSet(); + this.gateFrameBlocks = new HashSet(); + throw new Exception("Gate got closed. It has no exit."); } if (gateBlockLocations.size() == 0) { - setOpen(false); + isOpen = false; + this.gateBlockLocations = new HashSet(); + this.gateFrameBlocks = new HashSet(); + throw new Exception("Gate got closed. The frame is missing or broken. (no gate blocks)"); } @@ -230,7 +240,10 @@ public class Gate implements ConfigurationSerializable for (Block b : gateFrameBlocks) { if (b.getType() == Material.AIR) { - setOpen(false); + isOpen = false; + this.gateBlockLocations = new HashSet(); + this.gateFrameBlocks = new HashSet(); + throw new Exception("Gate got closed. The frame is missing or broken. (missing frame block(s))"); } } diff --git a/src/de/craftinc/gates/commands/CommandLocation.java b/src/de/craftinc/gates/commands/CommandLocation.java index cfbaa76..0ff15b4 100644 --- a/src/de/craftinc/gates/commands/CommandLocation.java +++ b/src/de/craftinc/gates/commands/CommandLocation.java @@ -56,38 +56,30 @@ public class CommandLocation extends BaseLocationCommand sendMessage("There is not enough room for a gate to open here"); return; } + + Location oldLocation = gate.getLocation(); + Set oldGateBlockLocations = gate.getGateBlockLocations(); + Set oldFrameBlocks = gate.getGateFrameBlocks(); try { - boolean gateOpen = gate.isOpen(); - - if (gateOpen) { - gate.setOpen(false); - GateBlockChangeSender.updateGateBlocks(gate); + if (gate.isOpen()) { + GateBlockChangeSender.updateGateBlocks(gate, true); } - Location oldLocation = gate.getLocation(); - Set oldGateBlockLocations = gate.getGateBlockLocations(); - Set oldFrameBlocks = gate.getGateFrameBlocks(); - gate.setLocation(playerLocation); - if (gateOpen) { - gate.setOpen(true); - } - - Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, oldLocation, oldGateBlockLocations, oldFrameBlocks); - GateBlockChangeSender.updateGateBlocks(gate); - sendMessage(ChatColor.GREEN + "The location of '" + gate.getId() + "' is now at your current location."); } catch (Exception e) { - GateBlockChangeSender.updateGateBlocks(gate); - - sendMessage(ChatColor.RED + "There seems to be no frame at your new location! The gate got closed!" + ChatColor.AQUA + " You should build a frame now and execute:"); + sendMessage(ChatColor.RED + "There seems to be no frame at your new location! The gate got closed!" + ChatColor.AQUA + " You should build a frame now and execute:"); sendMessage(new CommandOpen().getUsageTemplate(true, true)); } - } + finally { + Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, oldLocation, oldGateBlockLocations, oldFrameBlocks); + GateBlockChangeSender.updateGateBlocks(gate); + } + } } diff --git a/src/de/craftinc/gates/commands/CommandOpen.java b/src/de/craftinc/gates/commands/CommandOpen.java index 1876701..7dde5cf 100644 --- a/src/de/craftinc/gates/commands/CommandOpen.java +++ b/src/de/craftinc/gates/commands/CommandOpen.java @@ -53,6 +53,7 @@ public class CommandOpen extends BaseCommand } gate.setOpen(true); + GateBlockChangeSender.updateGateBlocks(gate); if (needsGateManagerUpdate) { diff --git a/src/de/craftinc/gates/util/GateBlockChangeSender.java b/src/de/craftinc/gates/util/GateBlockChangeSender.java index ba6b146..f092e78 100644 --- a/src/de/craftinc/gates/util/GateBlockChangeSender.java +++ b/src/de/craftinc/gates/util/GateBlockChangeSender.java @@ -110,14 +110,20 @@ public class GateBlockChangeSender /** * Sends block changes to players near a given gate. * @param gate Must not be 'null'! + * @param remove Set to true if all visible gate blocks shall be removed. */ - public static void updateGateBlocks(final Gate gate, boolean deleted) + public static void updateGateBlocks(final Gate gate, boolean remove) { if (gate == null) { throw new IllegalArgumentException("'gate must not be 'null'!"); } Location gateLocation = gate.getLocation(); + + if (gate.getGateBlockLocations().isEmpty()) { + return; + } + ArrayList playersNearby = new ArrayList(); int searchRadius = Plugin.getPlugin().getConfig().getInt(Plugin.confPlayerGateBlockUpdateRadiusKey); @@ -131,7 +137,7 @@ public class GateBlockChangeSender Material material; - if (gate.isOpen() && !gate.isHidden() && !deleted) { + if (gate.isOpen() && !gate.isHidden() && !remove) { material = Material.PORTAL; } else {