From 85b58b7623c753c5d3b53c12212aaaca773abd44 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 10 Feb 2015 23:23:12 +1100 Subject: [PATCH] Resolves #116 --- .../intellectualcrafters/plot/PlotMain.java | 35 +++++++++++++++++-- .../intellectualcrafters/plot/config/C.java | 8 ++++- .../plot/config/Settings.java | 6 +++- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index bf8035792..4346d9e3f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -113,6 +113,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.SendChunk; import com.intellectualcrafters.plot.util.SetBlockFast; +import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; @@ -587,8 +588,36 @@ public class PlotMain extends JavaPlugin implements Listener { event.setCancelled(true); return false; } - player.teleport(location); - PlayerFunctions.sendMessage(player, C.TELEPORTED_TO_PLOT); + if (Settings.TELEPORT_DELAY == 0 || hasPermission(player, "plots.teleport.delay.bypass")) { + PlayerFunctions.sendMessage(player, C.TELEPORTED_TO_PLOT); + player.teleport(location); + return true; + } + PlayerFunctions.sendMessage(player, C.TELEPORT_IN_SECONDS, Settings.TELEPORT_DELAY + ""); + Location loc = player.getLocation(); + final World world = player.getWorld(); + final int x = loc.getBlockX(); + final int z = loc.getBlockZ(); + TaskManager.runTaskLater(new Runnable() { + @Override + public void run() { + if (!player.isOnline()) { + return; + } + Location loc = player.getLocation(); + if (!loc.getWorld().equals(world)) { + PlayerFunctions.sendMessage(player, C.TELEPORT_FAILED); + return; + } + if (loc.getBlockX() != x || loc.getBlockZ() != z) { + PlayerFunctions.sendMessage(player, C.TELEPORT_FAILED); + return; + } + PlayerFunctions.sendMessage(player, C.TELEPORTED_TO_PLOT); + player.teleport(location); + } + }, Settings.TELEPORT_DELAY * 20); + return true; } return !event.isCancelled(); } @@ -796,6 +825,7 @@ public class PlotMain extends JavaPlugin implements Listener { final int config_ver = 1; config.set("version", config_ver); final Map options = new HashMap<>(); + options.put("teleport.delay", 0); options.put("auto_update", false); options.put("clusters.enabled", Settings.ENABLE_CLUSTERS); options.put("plotme-alias", Settings.USE_PLOTME_ALIAS); @@ -834,6 +864,7 @@ public class PlotMain extends JavaPlugin implements Listener { if (Settings.DEBUG) { sendConsoleSenderMessage(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off."); } + Settings.TELEPORT_DELAY = config.getInt("teleport.delay"); Settings.CONSOLE_COLOR = config.getBoolean("console.color"); Settings.TELEPORT_ON_LOGIN = config.getBoolean("teleport.on_login"); Settings.USE_PLOTME_ALIAS = config.getBoolean("plotme-alias"); 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 990c73a57..9119a58ae 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -260,6 +260,8 @@ 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"), /* * Set Block */ @@ -504,7 +506,11 @@ public enum C { } public static void saveTranslations() { - manager.saveAll(defaultFile).saveFile(defaultFile); + try { + manager.saveAll(defaultFile).saveFile(defaultFile); + } catch (Exception e) { + e.printStackTrace(); + } } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 58fc1154b..e9cd1f485 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -113,7 +113,11 @@ public class Settings { * Have colored console messages? */ public static boolean CONSOLE_COLOR = true; - + + /** + * The delay (in seconds) before teleportation commences + */ + public static int TELEPORT_DELAY; /** * Auto clear enabled */