Removed the ChunkLoadListener.
This commit is contained in:
parent
2ed611d995
commit
fec999541e
@ -5,7 +5,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
import de.craftinc.gates.listeners.ChunkLoadListener;
|
||||
import de.craftinc.gates.listeners.PlayerMoveListener;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
@ -30,7 +29,6 @@ public class Plugin extends JavaPlugin
|
||||
|
||||
private String baseCommand;
|
||||
private PlayerMoveListener playerListener = new PlayerMoveListener();
|
||||
private ChunkLoadListener chunkLoadListener = new ChunkLoadListener();
|
||||
private List<BaseCommand> commands = new ArrayList<BaseCommand>();
|
||||
private GatesManager gatesManager = new GatesManager();
|
||||
|
||||
@ -114,7 +112,6 @@ public class Plugin extends JavaPlugin
|
||||
// Register events
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
pm.registerEvents(this.playerListener, this);
|
||||
pm.registerEvents(this.chunkLoadListener, this);
|
||||
|
||||
// Load gates
|
||||
gatesManager.loadGatesFromDisk();
|
||||
@ -122,12 +119,6 @@ public class Plugin extends JavaPlugin
|
||||
log("Enabled");
|
||||
}
|
||||
|
||||
|
||||
public ChunkLoadListener getChunkLoadListener()
|
||||
{
|
||||
return chunkLoadListener;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Commands
|
||||
|
@ -1,74 +0,0 @@
|
||||
package de.craftinc.gates.listeners;
|
||||
|
||||
import de.craftinc.gates.Plugin;
|
||||
import de.craftinc.gates.util.SimpleChunk;
|
||||
import de.craftinc.gates.util.TeleportRequest;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
if (requests != null) {
|
||||
|
||||
pendingRequests.remove(c);
|
||||
|
||||
for (TeleportRequest r : requests) {
|
||||
|
||||
Player p = r.getPlayer();
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
if (requests == null) {
|
||||
requests = new ArrayList<TeleportRequest>();
|
||||
this.pendingRequests.put(c, requests);
|
||||
}
|
||||
|
||||
requests.add(r);
|
||||
this.playersWithTeleportRequest.add(r.getPlayer());
|
||||
}
|
||||
}
|
@ -67,8 +67,7 @@ public class PlayerMoveListener implements Listener
|
||||
|
||||
|
||||
/**
|
||||
* Teleports a player. This method will check if the destination chunk is loaded and will wait until the chunk
|
||||
* is loaded before executing the teleportion event.
|
||||
* Teleports a player.
|
||||
* @param p The player to teleport.
|
||||
* @param g The gate to which exit the player will be teleported.
|
||||
*/
|
||||
@ -79,33 +78,22 @@ public class PlayerMoveListener implements Listener
|
||||
|
||||
Float newYaw = g.getExit().getYaw() - g.getLocation().getYaw() + playerLocation.getYaw();
|
||||
|
||||
Location teleportToLocation = new Location( g.getExit().getWorld(),
|
||||
g.getExit().getX(),
|
||||
g.getExit().getY(),
|
||||
g.getExit().getZ(),
|
||||
newYaw,
|
||||
playerLocation.getPitch()
|
||||
);
|
||||
Location destLocation = new Location( g.getExit().getWorld(),
|
||||
g.getExit().getX(),
|
||||
g.getExit().getY(),
|
||||
g.getExit().getZ(),
|
||||
newYaw,
|
||||
playerLocation.getPitch()
|
||||
);
|
||||
|
||||
Chunk teleportToChunk = teleportToLocation.getChunk();
|
||||
|
||||
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();
|
||||
}
|
||||
p.teleport(destLocation);
|
||||
p.sendMessage(ChatColor.DARK_AQUA + "Thank you for traveling with Craft Inc. Gates.");
|
||||
}
|
||||
|
||||
|
||||
protected boolean hasPermission(Player player, Gate gate)
|
||||
{
|
||||
if (Plugin.getPermission() == null) // fallback: use the standard bukkit permission system
|
||||
{
|
||||
if (Plugin.getPermission() == null) { // fallback: use the standard bukkit permission system
|
||||
return player.hasPermission(Plugin.permissionUse);
|
||||
}
|
||||
else {
|
||||
|
@ -1,6 +1,8 @@
|
||||
package de.craftinc.gates.util;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class SimpleChunk
|
||||
{
|
||||
@ -14,7 +16,7 @@ public class SimpleChunk
|
||||
this.z = c.getZ();
|
||||
this.world = c.getWorld().getName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
|
Loading…
x
Reference in New Issue
Block a user