From e94a9bf68f790319b06b413fba9926a2f551e2c2 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 4 Dec 2010 18:21:05 -0800 Subject: [PATCH] Added exact respawning and teleporting to home on death. --- src/WorldGuardListener.java | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/WorldGuardListener.java b/src/WorldGuardListener.java index cf041641..08d5562b 100644 --- a/src/WorldGuardListener.java +++ b/src/WorldGuardListener.java @@ -96,6 +96,8 @@ public class WorldGuardListener extends PluginListener { private boolean disableWaterDamage; private int loginProtection; private int spawnProtection; + private boolean teleportToHome; + private boolean exactRespawn; private boolean kickOnDeath; private Blacklist blacklist; @@ -199,6 +201,8 @@ public void loadConfiguration() { loginProtection = properties.getInt("login-protection", 3); spawnProtection = properties.getInt("spawn-protection", 0); kickOnDeath = properties.getBoolean("kick-on-death", false); + teleportToHome = properties.getBoolean("teleport-to-home-on-death", false); + exactRespawn = properties.getBoolean("exact-respawn", false); // Console log configuration boolean logConsole = properties.getBoolean("log-console", true); @@ -311,7 +315,8 @@ public void onLogin(Player player) { player.sendMessage(Colors.Yellow + "Fire spread is currently globally disabled."); } - if (loginProtection > 0 || spawnProtection > 0 || kickOnDeath) { + if (loginProtection > 0 || spawnProtection > 0 + || kickOnDeath || teleportToHome || exactRespawn) { recentLogins.put(player.getName(), System.currentTimeMillis()); } @@ -959,7 +964,8 @@ public boolean onHealthChange(Player player, int oldValue, int newValue) { return oldValue > newValue; } - if (loginProtection > 0 || spawnProtection > 0 || kickOnDeath) { + if (loginProtection > 0 || spawnProtection > 0 + || kickOnDeath || teleportToHome || exactRespawn) { long now = System.currentTimeMillis(); boolean recentLogin = false; @@ -979,13 +985,29 @@ public boolean onHealthChange(Player player, int oldValue, int newValue) { } } - if (kickOnDeath && oldValue == -1 && newValue == 20 && !recentLogin) { + boolean alreadyMoved = false; + + if (teleportToHome && oldValue <= 0 && newValue == 20 && !recentLogin) { + Warp warp = etc.getDataSource().getHome(player.getName()); + if (warp != null) { + player.teleportTo(warp.Location); + alreadyMoved = true; + } else if (player.canUseCommand("/sethome")) { + player.sendMessage(Colors.Yellow + "Use /sethome to set your spawn location."); + } + } + + if (exactRespawn && !alreadyMoved && oldValue <= 0 && newValue == 20 && !recentLogin) { + player.teleportTo(etc.getServer().getSpawnLocation()); + } + + if (kickOnDeath && oldValue <= 0 && newValue == 20 && !recentLogin) { player.kick("You died! Rejoin please."); return false; } if (spawnProtection > 0) { - if (oldValue == -1 && newValue == 20 && !recentLogin) { // Player was just respawned + if (oldValue <= 0 && newValue == 20 && !recentLogin) { // Player was just respawned lastSpawn.put(player.getName(), now); } else if (lastSpawn.containsKey(playerName)) { long time = lastSpawn.get(playerName);