diff --git a/src/de/craftinc/gates/Plugin.java b/src/de/craftinc/gates/Plugin.java index 7efdf3c..9271e1f 100644 --- a/src/de/craftinc/gates/Plugin.java +++ b/src/de/craftinc/gates/Plugin.java @@ -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 commands = new ArrayList(); 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 diff --git a/src/de/craftinc/gates/listeners/ChunkLoadListener.java b/src/de/craftinc/gates/listeners/ChunkLoadListener.java deleted file mode 100644 index 862bed8..0000000 --- a/src/de/craftinc/gates/listeners/ChunkLoadListener.java +++ /dev/null @@ -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> pendingRequests = new HashMap>(); - private HashSet playersWithTeleportRequest = new HashSet(); - - @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 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 requests = pendingRequests.get(c); - - if (requests == null) { - requests = new ArrayList(); - this.pendingRequests.put(c, requests); - } - - 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 430f8b7..d01e12a 100644 --- a/src/de/craftinc/gates/listeners/PlayerMoveListener.java +++ b/src/de/craftinc/gates/listeners/PlayerMoveListener.java @@ -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 { diff --git a/src/de/craftinc/gates/util/SimpleChunk.java b/src/de/craftinc/gates/util/SimpleChunk.java index 45bd513..b20fb13 100644 --- a/src/de/craftinc/gates/util/SimpleChunk.java +++ b/src/de/craftinc/gates/util/SimpleChunk.java @@ -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)