mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-18 00:05:17 +01:00
Untested re-added teleport to faction home on death feature.
This commit is contained in:
parent
6f1777cc83
commit
ea5c5ce81e
@ -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<UConf>
|
||||
public double homesTeleportAllowedEnemyDistance = 32.0;
|
||||
public boolean homesTeleportIgnoreEnemiesIfInOwnTerritory = true;
|
||||
|
||||
public boolean homesTeleportToOnDeathActive = false;
|
||||
public EventPriority homesTeleportToOnDeathPriority = EventPriority.NORMAL;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ASSORTED
|
||||
// -------------------------------------------- //
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user