From 422b30d54e045661a8d871c91303f3867fa1435d Mon Sep 17 00:00:00 2001 From: Steven Scott Date: Sat, 1 Dec 2012 11:54:02 -0800 Subject: [PATCH] [Version 0.7.9.1] - Optimize gate lookup in onPlayerMove - Resolve issue where Stargates would teleport players to the nether --- README | 3 +++ src/net/TheDgtl/Stargate/Gate.java | 12 ++++++++---- src/net/TheDgtl/Stargate/Portal.java | 2 +- src/net/TheDgtl/Stargate/Stargate.java | 11 +++++++++-- src/plugin.yml | 2 +- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/README b/README index 7b5796e..e9eb956 100644 --- a/README +++ b/README @@ -213,6 +213,9 @@ Unable to reproduce: Stargates teleport a user into the ground/under the ground ============= Changes ============= +[Version 0.7.9.1] + - Optimize gate lookup in onPlayerMove + - Resolve issue where Stargates would teleport players to the nether [Version 0.7.9.0] - Added BungeeCord multi-server support (Requires Stargate-Bungee for BungeeCord) - Updated Spanish language file diff --git a/src/net/TheDgtl/Stargate/Gate.java b/src/net/TheDgtl/Stargate/Gate.java index 4b37f55..93d1a54 100644 --- a/src/net/TheDgtl/Stargate/Gate.java +++ b/src/net/TheDgtl/Stargate/Gate.java @@ -316,6 +316,7 @@ public class Gate { HashMap types = new HashMap(); HashMap metadata = new HashMap(); HashMap config = new HashMap(); + HashSet frameTypes = new HashSet(); int cols = 0; // Init types map @@ -365,7 +366,7 @@ public class Gate { Integer id = Integer.parseInt(value); types.put(symbol, id); - frameBlocks.add(id); + frameTypes.add(id); } else { config.put(key, value); } @@ -408,10 +409,13 @@ public class Gate { if (gate.getControls().length != 2) { Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gates must have exactly 2 control points."); return null; - } else { - gate.save(file.getParent() + "/"); // Updates format for version changes - return gate; } + + // Merge frame types, add open mat to list + frameBlocks.addAll(frameTypes); + + gate.save(file.getParent() + "/"); // Updates format for version changes + return gate; } private static int readConfig(HashMap config, Gate gate, File file, String key, int def) { diff --git a/src/net/TheDgtl/Stargate/Portal.java b/src/net/TheDgtl/Stargate/Portal.java index cf1d611..74cfb16 100644 --- a/src/net/TheDgtl/Stargate/Portal.java +++ b/src/net/TheDgtl/Stargate/Portal.java @@ -1188,7 +1188,7 @@ public class Portal { } public static Portal getByEntrance(Location location) { - return getByEntrance(new Blox(location).getBlock()); + return lookupEntrances.get(new Blox(location)); } public static Portal getByEntrance(Block block) { diff --git a/src/net/TheDgtl/Stargate/Stargate.java b/src/net/TheDgtl/Stargate/Stargate.java index ae932f2..e172b19 100644 --- a/src/net/TheDgtl/Stargate/Stargate.java +++ b/src/net/TheDgtl/Stargate/Stargate.java @@ -723,6 +723,7 @@ public class Stargate extends JavaPlugin { } private class pListener implements Listener { + @EventHandler public void onPlayerPortal(PlayerPortalEvent event) { if (event.isCancelled()) return; @@ -741,7 +742,8 @@ public class Stargate extends JavaPlugin { for (int k = -2; k < 2; k++) { Block b = world.getBlockAt(cX + i, cY + j, cZ + k); // We only need to worry about portal mat - if (b.getType() != Material.PORTAL) continue; + // Commented out for now, due to new Minecraft insta-nether + //if (b.getType() != Material.PORTAL) continue; Portal portal = Portal.getByEntrance(b); if (portal != null) { event.setCancelled(true); @@ -755,9 +757,14 @@ public class Stargate extends JavaPlugin { @EventHandler public void onPlayerMove(PlayerMoveEvent event) { if (event.isCancelled()) return; + + // Check to see if the player actually moved + if (event.getFrom().getBlockX() == event.getTo().getBlockX() && event.getFrom().getBlockY() == event.getTo().getBlockY() && event.getFrom().getBlockZ() == event.getTo().getBlockZ()) { + return; + } + Player player = event.getPlayer(); Portal portal = Portal.getByEntrance(event.getTo()); - // No portal or not open if (portal == null || !portal.isOpen()) return; diff --git a/src/plugin.yml b/src/plugin.yml index 943dc4b..982709b 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: Stargate main: net.TheDgtl.Stargate.Stargate -version: 0.7.9.0 +version: 0.7.9.1 description: Stargate mod for Bukkit author: Drakia website: http://www.thedgtl.net