Testing code for not working chunk load listener.
This commit is contained in:
parent
e6e6273147
commit
faabb2f9db
@ -1,6 +1,7 @@
|
|||||||
package de.craftinc.gates.listeners;
|
package de.craftinc.gates.listeners;
|
||||||
|
|
||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
|
import de.craftinc.gates.util.SimpleChunk;
|
||||||
import de.craftinc.gates.util.TeleportRequest;
|
import de.craftinc.gates.util.TeleportRequest;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
@ -17,12 +18,15 @@ import java.util.List;
|
|||||||
|
|
||||||
public class ChunkLoadListener implements Listener
|
public class ChunkLoadListener implements Listener
|
||||||
{
|
{
|
||||||
private HashMap<Chunk, List<TeleportRequest>> pendingRequests = new HashMap<Chunk, List<TeleportRequest>>();
|
private HashMap<SimpleChunk, List<TeleportRequest>> pendingRequests = new HashMap<SimpleChunk, List<TeleportRequest>>();
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onChunkLoad(ChunkLoadEvent event)
|
public void onChunkLoad(ChunkLoadEvent event)
|
||||||
{
|
{
|
||||||
Chunk c = event.getChunk();
|
System.out.println("loaded chunk: " + event.getChunk() + "world: " + event.getChunk().getWorld());
|
||||||
|
System.out.println("pending: " + pendingRequests.keySet());
|
||||||
|
|
||||||
|
SimpleChunk c = new SimpleChunk(event.getChunk());
|
||||||
List<TeleportRequest> requests = pendingRequests.get(c);
|
List<TeleportRequest> requests = pendingRequests.get(c);
|
||||||
|
|
||||||
if (requests != null) {
|
if (requests != null) {
|
||||||
@ -50,7 +54,7 @@ public class ChunkLoadListener implements Listener
|
|||||||
throw new IllegalArgumentException("The request must not be null!");
|
throw new IllegalArgumentException("The request must not be null!");
|
||||||
}
|
}
|
||||||
|
|
||||||
Chunk c = r.getDestination().getChunk();
|
SimpleChunk c = new SimpleChunk(r.getDestination().getChunk());
|
||||||
List<TeleportRequest> requests = pendingRequests.get(c);
|
List<TeleportRequest> requests = pendingRequests.get(c);
|
||||||
|
|
||||||
if (requests == null) {
|
if (requests == null) {
|
||||||
|
@ -87,19 +87,24 @@ public class PlayerMoveListener implements Listener
|
|||||||
playerLocation.getPitch()
|
playerLocation.getPitch()
|
||||||
);
|
);
|
||||||
|
|
||||||
Chunk c = exit.getChunk();
|
Chunk teleportToChunk = teleportToLocation.getChunk();
|
||||||
World w = exit.getWorld();
|
|
||||||
|
|
||||||
if (w.isChunkLoaded(c)) {
|
// System.out.println(teleportToChunk.getWorld() + "\n" +
|
||||||
p.teleport(teleportToLocation);
|
// teleportToChunk.getX() + "," + teleportToChunk.getZ() + "\n" +
|
||||||
p.sendMessage(ChatColor.DARK_AQUA + "Thank you for traveling with Craft Inc. Gates.");
|
// teleportToChunk + "\n" +
|
||||||
}
|
// teleportToChunk.getChunkSnapshot() + "\n" +
|
||||||
else {
|
// teleportToChunk.getTileEntities());
|
||||||
TeleportRequest request = new TeleportRequest(p, exit);
|
//
|
||||||
|
// 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);
|
Plugin.getPlugin().getChunkLoadListener().addTeleportRequest(request);
|
||||||
|
|
||||||
w.loadChunk(c);
|
teleportToChunk.load();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,4 +44,11 @@ public class SimpleChunk
|
|||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return this.getClass().toString() + " (x=" + this.x + " z=" + this.z + " world='" + this.world + "')";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ public class SimpleLocation
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(final Object o)
|
||||||
{
|
{
|
||||||
if (o instanceof SimpleLocation) {
|
if (o instanceof SimpleLocation) {
|
||||||
SimpleLocation otherLocation = (SimpleLocation)o;
|
SimpleLocation otherLocation = (SimpleLocation)o;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user