Only teleport players once if they got pending teleport requests.
This commit is contained in:
parent
faabb2f9db
commit
2ed611d995
@ -13,12 +13,14 @@ import org.bukkit.event.world.ChunkLoadEvent;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class ChunkLoadListener implements Listener
|
public class ChunkLoadListener implements Listener
|
||||||
{
|
{
|
||||||
private HashMap<SimpleChunk, List<TeleportRequest>> pendingRequests = new HashMap<SimpleChunk, List<TeleportRequest>>();
|
private HashMap<SimpleChunk, List<TeleportRequest>> pendingRequests = new HashMap<SimpleChunk, List<TeleportRequest>>();
|
||||||
|
private HashSet<Player> playersWithTeleportRequest = new HashSet<Player>();
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onChunkLoad(ChunkLoadEvent event)
|
public void onChunkLoad(ChunkLoadEvent event)
|
||||||
@ -36,12 +38,10 @@ public class ChunkLoadListener implements Listener
|
|||||||
for (TeleportRequest r : requests) {
|
for (TeleportRequest r : requests) {
|
||||||
|
|
||||||
Player p = r.getPlayer();
|
Player p = r.getPlayer();
|
||||||
|
this.playersWithTeleportRequest.remove(p);
|
||||||
|
|
||||||
p.sendMessage(ChatColor.DARK_AQUA + "Chunk got loaded.");
|
|
||||||
|
|
||||||
|
|
||||||
p.teleport(r.getDestination());
|
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.");
|
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)
|
public void addTeleportRequest(final TeleportRequest r)
|
||||||
{
|
{
|
||||||
|
System.out.println("Got teleport request: " + r.getDestination().getChunk());
|
||||||
|
|
||||||
if (r == null) {
|
if (r == null) {
|
||||||
throw new IllegalArgumentException("The request must not be null!");
|
throw new IllegalArgumentException("The request must not be null!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.playersWithTeleportRequest.contains(r.getPlayer())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SimpleChunk c = new SimpleChunk(r.getDestination().getChunk());
|
SimpleChunk c = new SimpleChunk(r.getDestination().getChunk());
|
||||||
List<TeleportRequest> requests = pendingRequests.get(c);
|
List<TeleportRequest> requests = pendingRequests.get(c);
|
||||||
|
|
||||||
@ -63,5 +69,6 @@ public class ChunkLoadListener implements Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
requests.add(r);
|
requests.add(r);
|
||||||
|
this.playersWithTeleportRequest.add(r.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,22 +89,16 @@ public class PlayerMoveListener implements Listener
|
|||||||
|
|
||||||
Chunk teleportToChunk = teleportToLocation.getChunk();
|
Chunk teleportToChunk = teleportToLocation.getChunk();
|
||||||
|
|
||||||
// System.out.println(teleportToChunk.getWorld() + "\n" +
|
if (teleportToChunk.isLoaded()) {
|
||||||
// teleportToChunk.getX() + "," + teleportToChunk.getZ() + "\n" +
|
p.teleport(teleportToLocation);
|
||||||
// teleportToChunk + "\n" +
|
p.sendMessage(ChatColor.DARK_AQUA + "Thank you for traveling with Craft Inc. Gates.");
|
||||||
// teleportToChunk.getChunkSnapshot() + "\n" +
|
}
|
||||||
// teleportToChunk.getTileEntities());
|
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);
|
TeleportRequest request = new TeleportRequest(p, teleportToLocation);
|
||||||
Plugin.getPlugin().getChunkLoadListener().addTeleportRequest(request);
|
Plugin.getPlugin().getChunkLoadListener().addTeleportRequest(request);
|
||||||
|
|
||||||
teleportToChunk.load();
|
teleportToChunk.load();
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user