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 java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
import de.craftinc.gates.listeners.ChunkLoadListener;
|
|
||||||
import de.craftinc.gates.listeners.PlayerMoveListener;
|
import de.craftinc.gates.listeners.PlayerMoveListener;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
|
||||||
@ -30,7 +29,6 @@ public class Plugin extends JavaPlugin
|
|||||||
|
|
||||||
private String baseCommand;
|
private String baseCommand;
|
||||||
private PlayerMoveListener playerListener = new PlayerMoveListener();
|
private PlayerMoveListener playerListener = new PlayerMoveListener();
|
||||||
private ChunkLoadListener chunkLoadListener = new ChunkLoadListener();
|
|
||||||
private List<BaseCommand> commands = new ArrayList<BaseCommand>();
|
private List<BaseCommand> commands = new ArrayList<BaseCommand>();
|
||||||
private GatesManager gatesManager = new GatesManager();
|
private GatesManager gatesManager = new GatesManager();
|
||||||
|
|
||||||
@ -114,7 +112,6 @@ public class Plugin extends JavaPlugin
|
|||||||
// Register events
|
// Register events
|
||||||
PluginManager pm = this.getServer().getPluginManager();
|
PluginManager pm = this.getServer().getPluginManager();
|
||||||
pm.registerEvents(this.playerListener, this);
|
pm.registerEvents(this.playerListener, this);
|
||||||
pm.registerEvents(this.chunkLoadListener, this);
|
|
||||||
|
|
||||||
// Load gates
|
// Load gates
|
||||||
gatesManager.loadGatesFromDisk();
|
gatesManager.loadGatesFromDisk();
|
||||||
@ -123,12 +120,6 @@ public class Plugin extends JavaPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ChunkLoadListener getChunkLoadListener()
|
|
||||||
{
|
|
||||||
return chunkLoadListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// Commands
|
// 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
|
* Teleports a player.
|
||||||
* is loaded before executing the teleportion event.
|
|
||||||
* @param p The player to teleport.
|
* @param p The player to teleport.
|
||||||
* @param g The gate to which exit the player will be teleported.
|
* @param g The gate to which exit the player will be teleported.
|
||||||
*/
|
*/
|
||||||
@ -79,7 +78,7 @@ public class PlayerMoveListener implements Listener
|
|||||||
|
|
||||||
Float newYaw = g.getExit().getYaw() - g.getLocation().getYaw() + playerLocation.getYaw();
|
Float newYaw = g.getExit().getYaw() - g.getLocation().getYaw() + playerLocation.getYaw();
|
||||||
|
|
||||||
Location teleportToLocation = new Location( g.getExit().getWorld(),
|
Location destLocation = new Location( g.getExit().getWorld(),
|
||||||
g.getExit().getX(),
|
g.getExit().getX(),
|
||||||
g.getExit().getY(),
|
g.getExit().getY(),
|
||||||
g.getExit().getZ(),
|
g.getExit().getZ(),
|
||||||
@ -87,25 +86,14 @@ public class PlayerMoveListener implements Listener
|
|||||||
playerLocation.getPitch()
|
playerLocation.getPitch()
|
||||||
);
|
);
|
||||||
|
|
||||||
Chunk teleportToChunk = teleportToLocation.getChunk();
|
p.teleport(destLocation);
|
||||||
|
|
||||||
if (teleportToChunk.isLoaded()) {
|
|
||||||
p.teleport(teleportToLocation);
|
|
||||||
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.");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
TeleportRequest request = new TeleportRequest(p, teleportToLocation);
|
|
||||||
Plugin.getPlugin().getChunkLoadListener().addTeleportRequest(request);
|
|
||||||
|
|
||||||
teleportToChunk.load();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected boolean hasPermission(Player player, Gate gate)
|
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);
|
return player.hasPermission(Plugin.permissionUse);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package de.craftinc.gates.util;
|
package de.craftinc.gates.util;
|
||||||
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
public class SimpleChunk
|
public class SimpleChunk
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user