Saber-Factions/src/com/massivecraft/factions/commands/FCommandHome.java

104 lines
3.1 KiB
Java
Raw Normal View History

2011-07-18 22:06:02 +02:00
package com.massivecraft.factions.commands;
2011-03-23 17:39:56 +01:00
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
2011-03-23 17:39:56 +01:00
2011-10-08 23:22:02 +02:00
public class FCommandHome extends FCommand {
2011-03-23 17:39:56 +01:00
public FCommandHome() {
aliases.add("home");
helpDescription = "Teleport to the faction home";
}
@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;
}
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:"));
me.sendMessage(new FCommandSethome().getUseageTemplate());
2011-03-23 17:39:56 +01:00
return;
}
if (!Conf.homesTeleportAllowedFromEnemyTerritory && me.isInEnemyTerritory()) {
me.sendMessage("You cannot teleport to your faction home while in the territory of an enemy faction.");
return;
}
2011-10-08 23:22:02 +02:00
if (!Conf.homesTeleportAllowedFromDifferentWorld && me.getWorld().getUID() != myFaction.getHome().getWorld().getUID()) {
me.sendMessage("You cannot teleport to your faction home while in a different world.");
return;
}
2011-10-08 23:22:02 +02:00
Faction faction = Board.getFactionAt(new FLocation(me.getLocation()));
// 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() || (me.isInOwnTerritory() && !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory))
) {
2011-10-08 23:22:02 +02:00
Location loc = me.getLocation();
World w = loc.getWorld();
double x = loc.getX();
double y = loc.getY();
double z = loc.getZ();
2011-10-08 23:22:02 +02:00
for (Player p : me.getServer().getOnlinePlayers())
{
2011-10-08 23:22:02 +02:00
if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w)
continue;
FPlayer fp = FPlayer.get(p);
if (me.getRelation(fp) != Relation.ENEMY)
continue;
Location l = p.getLocation();
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)
continue;
me.sendMessage("You cannot teleport to your faction home while an enemy is within " + Conf.homesTeleportAllowedEnemyDistance + " blocks of you.");
return;
}
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostHome)) {
return;
}
2011-10-08 23:22:02 +02:00
me.teleport(myFaction.getHome());
2011-03-23 17:39:56 +01:00
}
}