Only teleport players once if they got pending teleport requests.

This commit is contained in:
Tobias Ottenweller 2013-06-01 12:43:39 +02:00
parent faabb2f9db
commit 2ed611d995
2 changed files with 17 additions and 16 deletions

View File

@ -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<SimpleChunk, List<TeleportRequest>> pendingRequests = new HashMap<SimpleChunk, List<TeleportRequest>>();
private HashSet<Player> playersWithTeleportRequest = new HashSet<Player>();
@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<TeleportRequest> requests = pendingRequests.get(c);
@ -63,5 +69,6 @@ public class ChunkLoadListener implements Listener
}
requests.add(r);
this.playersWithTeleportRequest.add(r.getPlayer());
}
}

View File

@ -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();
// }
}
}