From e54914bd221197c6871365832ab9f9615bd4539a Mon Sep 17 00:00:00 2001 From: Tobias Ottenweller Date: Sat, 23 Feb 2013 19:52:41 +0100 Subject: [PATCH] Fix a null pointer exception if a certain world has no gates. --- .../gates/listeners/PluginPortalListener.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/de/craftinc/gates/listeners/PluginPortalListener.java b/src/de/craftinc/gates/listeners/PluginPortalListener.java index 11d5daa..c34e753 100644 --- a/src/de/craftinc/gates/listeners/PluginPortalListener.java +++ b/src/de/craftinc/gates/listeners/PluginPortalListener.java @@ -68,21 +68,23 @@ public class PluginPortalListener implements Listener Location eventLocation = event.getLocation(); Gate closestGate = GateUtil.closestGate(eventLocation); - // Make sure gate and event locations are on the same height (y-value). - // Otherwise the distance will be messed up when players are flying. - // FIX ME: this could potentially let a nearby nether portal fail! - eventLocation.setY(closestGate.getLocation().getY()); - - double distToClosestGate = closestGate.getLocation().distance(eventLocation); - - Plugin.log("closest gate: " + closestGate.getId()); - Plugin.log("distance: " + distToClosestGate); - - if (distToClosestGate < 2.0) { - this.currentGateAtEvent.put(player, closestGate); - return; + if (closestGate != null) + { + // Make sure gate and event locations are on the same height (y-value). + // Otherwise the distance will be messed up when players are flying. + // FIX ME: this could potentially let a nearby nether portal fail! + eventLocation.setY(closestGate.getLocation().getY()); + + double distToClosestGate = closestGate.getLocation().distance(eventLocation); + + Plugin.log("closest gate: " + closestGate.getId()); + Plugin.log("distance: " + distToClosestGate); + + if (distToClosestGate < 2.0) { + this.currentGateAtEvent.put(player, closestGate); + return; + } } - } this.currentGateAtEvent.put(player, null);