// If in Monster Derby Track
if(player.isInsideZone(L2Character.ZONE_MONSTERTRACK))
return new Location(12661, 181687, -3560);
Castle castle = null;
Fort fort = null;
ClanHall clanhall = null;
if(player.getClan() != null)
{
// If teleport to clan hall
if(teleportWhere == TeleportWhereType.ClanHall)
{
clanhall = ClanHallManager.getInstance().getClanHallByOwner(player.getClan());
if(clanhall != null)
{
L2ClanHallZone zone = clanhall.getZone();
if(zone != null)
return zone.getSpawn();
}
}
// If teleport to castle
if(teleportWhere == TeleportWhereType.Castle)
{
castle = CastleManager.getInstance().getCastleByOwner(player.getClan());
}
// If teleport to fort
if(teleportWhere == TeleportWhereType.Fortress)
{
fort = FortManager.getInstance().getFortByOwner(player.getClan());
}
// Check if player is on castle&fortress ground
if(castle == null)
{
castle = CastleManager.getInstance().getCastle(player);
}
if(fort == null)
{
fort = FortManager.getInstance().getFort(player);
}
if(castle != null && castle.getCastleId() > 0)
{
// If Teleporting to castle or
// If is on caslte with siege and player's clan is defender
if(teleportWhere == TeleportWhereType.Castle || teleportWhere == TeleportWhereType.Castle && castle.getSiege().getIsInProgress() && castle.getSiege().getDefenderClan(player.getClan()) != null)
{
coord = castle.getZone().getSpawn();
return new Location(coord[0], coord[1], coord[2]);
}
if(teleportWhere == TeleportWhereType.SiegeFlag && castle.getSiege().getIsInProgress())
{
// Check if player's clan is attacker
List<L2NpcInstance> flags = castle.getSiege().getFlag(player.getClan());
if(flags != null && !flags.isEmpty())
{
// Spawn to flag - Need more work to get player to the nearest flag
L2NpcInstance flag = flags.get(0);
return new Location(flag.getX(), flag.getY(), flag.getZ());
}
flags = null;
}
}
else if(fort != null && fort.getFortId() > 0)
{
// teleporting to castle or fortress
// is on caslte with siege and player's clan is defender
if(teleportWhere == TeleportWhereType.Fortress || teleportWhere == TeleportWhereType.Fortress && fort.getSiege().getIsInProgress() && fort.getSiege().getDefenderClan(player.getClan()) != null)
{
coord = fort.getZone().getSpawn();
return new Location(coord[0], coord[1], coord[2]);
}
if(teleportWhere == TeleportWhereType.SiegeFlag && fort.getSiege().getIsInProgress())
{
// check if player's clan is attacker
List<L2NpcInstance> flags = fort.getSiege().getFlag(player.getClan());
if(flags != null && !flags.isEmpty())
{
// spawn to flag
L2NpcInstance flag = flags.get(0);