diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index 8db49821d..3bda9ba8f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -598,9 +598,16 @@ public class PlotMain extends JavaPlugin implements Listener { final World world = player.getWorld(); final int x = loc.getBlockX(); final int z = loc.getBlockZ(); + final String name = player.getName(); + TaskManager.TELEPORT_QUEUE.add(name); TaskManager.runTaskLater(new Runnable() { @Override public void run() { + if (!TaskManager.TELEPORT_QUEUE.contains(name)) { + PlayerFunctions.sendMessage(player, C.TELEPORT_FAILED); + return; + } + TaskManager.TELEPORT_QUEUE.remove(name); if (!player.isOnline()) { return; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index 8f0b5fe7c..08099f3de 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -261,7 +261,7 @@ public enum C { TELEPORTED_TO_PLOT("&6You have been teleported"), TELEPORTED_TO_ROAD("&cYou got teleported to the road"), TELEPORT_IN_SECONDS("&6Teleporting in %s seconds. Do not move..."), - TELEPORT_FAILED("&cTeleportation cancelled due to movement"), + TELEPORT_FAILED("&cTeleportation cancelled due to movement or damage"), /* * Set Block */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index fcbfc6c7c..fc69ebf97 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -99,6 +99,7 @@ import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; +import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandler; /** @@ -161,6 +162,12 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi final Location q = new Location(t.getWorld(), t.getBlockX(), 0, t.getZ()); if ((f.getBlockX() != q.getBlockX()) || (f.getBlockZ() != q.getBlockZ())) { + if (Settings.TELEPORT_DELAY != 0 && TaskManager.TELEPORT_QUEUE.size() > 0) { + String name = player.getName(); + if (TaskManager.TELEPORT_QUEUE.contains(name)) { + TaskManager.TELEPORT_QUEUE.remove(name); + } + } if (!isPlotWorld(player.getWorld())) { return; } @@ -916,6 +923,15 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi final Location l = e.getEntity().getLocation(); final Entity d = e.getDamager(); final Entity a = e.getEntity(); + + if (Settings.TELEPORT_DELAY != 0 && TaskManager.TELEPORT_QUEUE.size() > 0 && a instanceof Player) { + Player player = (Player) a; + String name = player.getName(); + if (TaskManager.TELEPORT_QUEUE.contains(name)) { + TaskManager.TELEPORT_QUEUE.remove(name); + } + } + if (isPlotWorld(l)) { if (d instanceof Player) { final Player p = (Player) d; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java index daa40b6eb..6cfa25031 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java @@ -1,8 +1,13 @@ package com.intellectualcrafters.plot.util; +import java.util.HashSet; + import com.intellectualcrafters.plot.PlotMain; public class TaskManager { + + public static HashSet TELEPORT_QUEUE = new HashSet<>(); + public static void runTask(final Runnable r) { PlotMain.getMain().getServer().getScheduler().runTaskAsynchronously(PlotMain.getMain(), r); }