From 2ed611d9950966e78624d3ac2806403c78c21649 Mon Sep 17 00:00:00 2001 From: Tobias Ottenweller Date: Sat, 1 Jun 2013 12:43:39 +0200 Subject: [PATCH] Only teleport players once if they got pending teleport requests. --- .../gates/listeners/ChunkLoadListener.java | 15 +++++++++++---- .../gates/listeners/PlayerMoveListener.java | 18 ++++++------------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/de/craftinc/gates/listeners/ChunkLoadListener.java b/src/de/craftinc/gates/listeners/ChunkLoadListener.java index ae991c4..862bed8 100644 --- a/src/de/craftinc/gates/listeners/ChunkLoadListener.java +++ b/src/de/craftinc/gates/listeners/ChunkLoadListener.java @@ -13,12 +13,14 @@ import org.bukkit.event.world.ChunkLoadEvent; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; public class ChunkLoadListener implements Listener { private HashMap> pendingRequests = new HashMap>(); + private HashSet playersWithTeleportRequest = new HashSet(); @EventHandler(priority = EventPriority.NORMAL) public void onChunkLoad(ChunkLoadEvent event) @@ -36,12 +38,10 @@ public class ChunkLoadListener implements Listener for (TeleportRequest r : requests) { Player p = r.getPlayer(); - - - p.sendMessage(ChatColor.DARK_AQUA + "Chunk got loaded."); - + this.playersWithTeleportRequest.remove(p); p.teleport(r.getDestination()); + p.sendMessage(ChatColor.DARK_AQUA + "Chunk got loaded."); p.sendMessage(ChatColor.DARK_AQUA + "Thank you for traveling with Craft Inc. Gates."); } } @@ -50,10 +50,16 @@ public class ChunkLoadListener implements Listener public void addTeleportRequest(final TeleportRequest r) { + System.out.println("Got teleport request: " + r.getDestination().getChunk()); + if (r == null) { throw new IllegalArgumentException("The request must not be null!"); } + if (this.playersWithTeleportRequest.contains(r.getPlayer())) { + return; + } + SimpleChunk c = new SimpleChunk(r.getDestination().getChunk()); List requests = pendingRequests.get(c); @@ -63,5 +69,6 @@ public class ChunkLoadListener implements Listener } requests.add(r); + this.playersWithTeleportRequest.add(r.getPlayer()); } } diff --git a/src/de/craftinc/gates/listeners/PlayerMoveListener.java b/src/de/craftinc/gates/listeners/PlayerMoveListener.java index 9c92265..430f8b7 100644 --- a/src/de/craftinc/gates/listeners/PlayerMoveListener.java +++ b/src/de/craftinc/gates/listeners/PlayerMoveListener.java @@ -89,22 +89,16 @@ public class PlayerMoveListener implements Listener Chunk teleportToChunk = teleportToLocation.getChunk(); -// System.out.println(teleportToChunk.getWorld() + "\n" + -// teleportToChunk.getX() + "," + teleportToChunk.getZ() + "\n" + -// teleportToChunk + "\n" + -// teleportToChunk.getChunkSnapshot() + "\n" + -// teleportToChunk.getTileEntities()); -// -// if (teleportToChunk.isLoaded()) { -// p.teleport(teleportToLocation); -// p.sendMessage(ChatColor.DARK_AQUA + "Thank you for traveling with Craft Inc. Gates."); -// } -// else { + if (teleportToChunk.isLoaded()) { + p.teleport(teleportToLocation); + p.sendMessage(ChatColor.DARK_AQUA + "Thank you for traveling with Craft Inc. Gates."); + } + else { TeleportRequest request = new TeleportRequest(p, teleportToLocation); Plugin.getPlugin().getChunkLoadListener().addTeleportRequest(request); teleportToChunk.load(); -// } + } }