2011-04-08 15:51:07 +02:00
|
|
|
package org.mcteam.factions.commands;
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2011-05-29 23:28:29 +02:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.mcteam.factions.Board;
|
2011-04-08 15:51:07 +02:00
|
|
|
import org.mcteam.factions.Conf;
|
|
|
|
import org.mcteam.factions.Faction;
|
2011-05-29 23:28:29 +02:00
|
|
|
import org.mcteam.factions.FLocation;
|
|
|
|
import org.mcteam.factions.FPlayer;
|
|
|
|
import org.mcteam.factions.struct.Relation;
|
2011-04-08 15:51:07 +02:00
|
|
|
import org.mcteam.factions.struct.Role;
|
2011-03-23 17:39:56 +01:00
|
|
|
|
|
|
|
public class FCommandHome extends FBaseCommand {
|
|
|
|
|
|
|
|
public FCommandHome() {
|
|
|
|
aliases.add("home");
|
|
|
|
|
|
|
|
helpDescription = "Teleport to the faction home";
|
|
|
|
}
|
|
|
|
|
2011-06-21 07:38:31 +02:00
|
|
|
@Override
|
2011-03-23 17:39:56 +01:00
|
|
|
public void perform() {
|
|
|
|
if ( ! assertHasFaction()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! Conf.homesEnabled) {
|
|
|
|
me.sendMessage("Sorry, Faction homes are disabled on this server.");
|
|
|
|
return;
|
|
|
|
}
|
2011-06-29 01:29:14 +02:00
|
|
|
|
|
|
|
if ( ! Conf.homesTeleportCommandEnabled) {
|
|
|
|
me.sendMessage("Sorry, the ability to teleport to Faction homes is disabled on this server.");
|
|
|
|
return;
|
|
|
|
}
|
2011-03-23 17:39:56 +01:00
|
|
|
|
|
|
|
Faction myFaction = me.getFaction();
|
|
|
|
|
|
|
|
if ( ! myFaction.hasHome()) {
|
|
|
|
me.sendMessage("You faction does not have a home. " + (me.getRole().value < Role.MODERATOR.value ? " Ask your leader to:" : "You should:"));
|
2011-04-08 16:03:04 +02:00
|
|
|
me.sendMessage(new FCommandSethome().getUseageTemplate());
|
2011-03-23 17:39:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-29 23:28:29 +02:00
|
|
|
Faction faction = Board.getFactionAt(new FLocation(player.getLocation()));
|
|
|
|
|
2011-06-19 10:56:21 +02:00
|
|
|
if (!Conf.homesTeleportAllowedFromEnemyTerritory && me.isInEnemyTerritory()) {
|
|
|
|
me.sendMessage("You cannot teleport to your faction home while in the territory of an enemy faction.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-29 23:28:29 +02:00
|
|
|
// if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby
|
|
|
|
if (Conf.homesTeleportAllowedEnemyDistance > 0 && ! faction.isSafeZone() && ! me.isInOwnTerritory()) {
|
|
|
|
Location loc = player.getLocation();
|
|
|
|
World w = loc.getWorld();
|
2011-06-09 03:33:12 +02:00
|
|
|
double x = loc.getX();
|
|
|
|
double y = loc.getY();
|
|
|
|
double z = loc.getZ();
|
2011-05-29 23:28:29 +02:00
|
|
|
|
|
|
|
for (Player p : player.getServer().getOnlinePlayers())
|
|
|
|
{
|
|
|
|
if (p == null || !p.isOnline() || p.isDead() || p == player || p.getWorld() != w)
|
|
|
|
continue;
|
2011-06-09 03:33:12 +02:00
|
|
|
|
2011-05-29 23:28:29 +02:00
|
|
|
FPlayer fp = FPlayer.get(p);
|
|
|
|
if (me.getRelation(fp) != Relation.ENEMY)
|
|
|
|
continue;
|
2011-06-09 03:33:12 +02:00
|
|
|
|
2011-05-29 23:28:29 +02:00
|
|
|
Location l = p.getLocation();
|
2011-06-09 03:33:12 +02:00
|
|
|
double dx = Math.abs(x - l.getX());
|
|
|
|
double dy = Math.abs(y - l.getY());
|
|
|
|
double dz = Math.abs(z - l.getZ());
|
|
|
|
double max = Conf.homesTeleportAllowedEnemyDistance;
|
|
|
|
|
|
|
|
// box-shaped distance check
|
|
|
|
if (dx > max || dy > max || dz > max)
|
2011-05-29 23:28:29 +02:00
|
|
|
continue;
|
2011-06-09 03:33:12 +02:00
|
|
|
|
2011-05-29 23:28:29 +02:00
|
|
|
me.sendMessage("You cannot teleport to your faction home while an enemy is within " + Conf.homesTeleportAllowedEnemyDistance + " blocks of you.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 15:13:02 +02:00
|
|
|
player.teleport(myFaction.getHome());
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|