From 6ab3a029b229a827658853f2f65b703265949b07 Mon Sep 17 00:00:00 2001 From: manuelgu Date: Mon, 4 Apr 2016 11:31:15 +0200 Subject: [PATCH] Add teleport on death feature --- .../plotsquared/bukkit/listeners/PlayerEvents.java | 8 ++++++++ .../java/com/intellectualcrafters/plot/PS.java | 3 ++- .../intellectualcrafters/plot/config/Settings.java | 12 ++++++++---- .../intellectualcrafters/plot/util/EventUtil.java | 14 +++++++++++++- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 07f5d629c..96abea7f1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -96,6 +96,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.vehicle.VehicleCreateEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent; @@ -461,6 +462,13 @@ public class PlayerEvents extends PlotListener implements Listener { }, 20); } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void playerRespawn(PlayerRespawnEvent event) { + final Player player = event.getPlayer(); + final PlotPlayer pp = BukkitUtil.getPlayer(player); + EventUtil.manager.doDeathTask(pp); + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void playerMove(PlayerMoveEvent event) { org.bukkit.Location from = event.getFrom(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index 634247e9e..dccd9cf7d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -53,7 +53,6 @@ import com.intellectualcrafters.plot.util.WorldUtil; import com.intellectualcrafters.plot.util.area.QuadMap; import com.plotsquared.listener.WESubscriber; import com.sk89q.worldedit.WorldEdit; - import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -2030,6 +2029,7 @@ public class PS { // Teleportation options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN); + options.put("teleport.on_death", Settings.TELEPORT_ON_DEATH); options.put("teleport.delay", Settings.TELEPORT_DELAY); // WorldEdit @@ -2140,6 +2140,7 @@ public class PS { // Teleportation Settings.TELEPORT_DELAY = this.config.getInt("teleport.delay"); Settings.TELEPORT_ON_LOGIN = this.config.getBoolean("teleport.on_login"); + Settings.TELEPORT_ON_DEATH = this.config.getBoolean("teleport.on_death"); // WorldEdit Settings.QUEUE_COMMANDS = this.config.getBoolean("worldedit.queue-commands"); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java index ef028ed88..d911f5748 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -11,10 +11,10 @@ import java.util.List; */ public class Settings { public static boolean USE_SQLUUIDHANDLER = false; - + public static boolean AUTO_PURGE = false; /** - * + * */ public static boolean UPDATE_NOTIFICATIONS = true; @@ -26,7 +26,7 @@ public class Settings { public static boolean PERMISSION_CACHING = true; public static boolean CACHE_RATINGS = true; public static boolean UUID_FROM_DISK = false; - + /** * Web */ @@ -82,6 +82,10 @@ public class Settings { * Teleport to path on login */ public static boolean TELEPORT_ON_LOGIN = false; + /** + * Teleport to path on death + */ + public static boolean TELEPORT_ON_DEATH = false; /** * Display titles */ @@ -156,7 +160,7 @@ public class Settings { * Use global plot limit? */ public static boolean GLOBAL_LIMIT = false; - + /** * Database settings * diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java index 76d4c213c..c7adcbfb5 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java @@ -15,7 +15,6 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.Rating; import com.plotsquared.listener.PlayerBlockEventType; - import java.util.ArrayList; import java.util.HashSet; import java.util.UUID; @@ -78,6 +77,19 @@ public abstract class EventUtil { } } + public void doDeathTask(final PlotPlayer pp) { + final Plot plot = pp.getCurrentPlot(); + if (Settings.TELEPORT_ON_DEATH && plot != null) { + TaskManager.runTask(new Runnable() { + @Override + public void run() { + plot.teleportPlayer(pp); + } + }); + MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD); + } + } + public boolean checkPlayerBlockEvent(PlotPlayer pp, PlayerBlockEventType type, Location loc, LazyBlock block, boolean notifyPerms) { PlotArea area = PS.get().getPlotAreaAbs(loc); Plot plot;