From ea5c5ce81e024b07eb7368ec52d3615ecd2033a5 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 24 Jul 2013 18:29:55 +0200 Subject: [PATCH] Untested re-added teleport to faction home on death feature. --- .../massivecraft/factions/entity/UConf.java | 4 + .../listeners/FactionsListenerMain.java | 77 +++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/src/com/massivecraft/factions/entity/UConf.java b/src/com/massivecraft/factions/entity/UConf.java index 8a347d2a..16adf5e1 100644 --- a/src/com/massivecraft/factions/entity/UConf.java +++ b/src/com/massivecraft/factions/entity/UConf.java @@ -7,6 +7,7 @@ import java.util.Set; import java.util.UUID; import org.bukkit.command.CommandSender; +import org.bukkit.event.EventPriority; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPerm; @@ -126,6 +127,9 @@ public class UConf extends Entity public double homesTeleportAllowedEnemyDistance = 32.0; public boolean homesTeleportIgnoreEnemiesIfInOwnTerritory = true; + public boolean homesTeleportToOnDeathActive = false; + public EventPriority homesTeleportToOnDeathPriority = EventPriority.NORMAL; + // -------------------------------------------- // // ASSORTED // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index a1fbd963..cc7d7a2c 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -49,6 +49,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerRespawnEvent; import com.massivecraft.factions.Const; import com.massivecraft.factions.FFlag; @@ -904,4 +905,80 @@ public class FactionsListenerMain implements Listener event.setCancelled(true); } + // -------------------------------------------- // + // TELEPORT TO HOME ON DEATH + // -------------------------------------------- // + + public void teleportToHomeOnDeath(PlayerRespawnEvent event, EventPriority priority) + { + // If a player is respawning ... + final Player player = event.getPlayer(); + final UPlayer uplayer = UPlayer.get(player); + final UConf uconf = UConf.get(player); + + // ... homes are enabled, active and at this priority ... + if (!uconf.homesEnabled) return; + if (!uconf.homesTeleportToOnDeathActive) return; + if (uconf.homesTeleportToOnDeathPriority != priority) return; + + // ... and the player has a faction ... + final Faction faction = uplayer.getFaction(); + if (faction.isNone()) return; + + // ... and the faction has a home ... + PS home = faction.getHome(); + if (home == null) return; + + // ... and the home is translatable ... + Location respawnLocation = null; + try + { + respawnLocation = home.asBukkitLocation(true); + } + catch (Exception e) + { + // The home location map may have been deleted + return; + } + + // ... then use it for the respawn location. + event.setRespawnLocation(respawnLocation); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void teleportToHomeOnDeathLowest(PlayerRespawnEvent event) + { + this.teleportToHomeOnDeath(event, EventPriority.LOWEST); + } + + @EventHandler(priority = EventPriority.LOW) + public void teleportToHomeOnDeathLow(PlayerRespawnEvent event) + { + this.teleportToHomeOnDeath(event, EventPriority.LOW); + } + + @EventHandler(priority = EventPriority.NORMAL) + public void teleportToHomeOnDeathNormal(PlayerRespawnEvent event) + { + this.teleportToHomeOnDeath(event, EventPriority.NORMAL); + } + + @EventHandler(priority = EventPriority.HIGH) + public void teleportToHomeOnDeathHigh(PlayerRespawnEvent event) + { + this.teleportToHomeOnDeath(event, EventPriority.HIGH); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void teleportToHomeOnDeathHighest(PlayerRespawnEvent event) + { + this.teleportToHomeOnDeath(event, EventPriority.HIGHEST); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void teleportToHomeOnDeathMonitor(PlayerRespawnEvent event) + { + this.teleportToHomeOnDeath(event, EventPriority.MONITOR); + } + }