Saber-Factions/src/com/massivecraft/factions/cmd/CmdHome.java

149 lines
4.3 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
2011-03-23 17:39:56 +01:00
import java.util.ArrayList;
import java.util.List;
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.FPlayers;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.integration.EssentialsFeatures;
import com.massivecraft.factions.struct.Permission;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.util.SmokeUtil;
2011-03-23 17:39:56 +01:00
2011-10-09 20:10:19 +02:00
public class CmdHome extends FCommand
{
2011-03-23 17:39:56 +01:00
2011-10-09 20:10:19 +02:00
public CmdHome()
{
super();
this.aliases.add("home");
2011-03-23 17:39:56 +01:00
//this.requiredArgs.add("");
//this.optionalArgs.put("", "");
2011-10-09 21:57:43 +02:00
this.permission = Permission.HOME.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
2011-03-23 17:39:56 +01:00
}
@Override
public void perform()
{
// TODO: Hide this command on help also.
if ( ! Conf.homesEnabled)
{
2011-10-10 13:40:24 +02:00
fme.msg("<b>Sorry, Faction homes are disabled on this server.");
2011-03-23 17:39:56 +01:00
return;
}
if ( ! Conf.homesTeleportCommandEnabled)
{
2011-10-10 13:40:24 +02:00
fme.msg("<b>Sorry, the ability to teleport to Faction homes is disabled on this server.");
return;
}
2011-03-23 17:39:56 +01:00
if ( ! myFaction.hasHome())
{
fme.msg("<b>Your faction does not have a home. " + (fme.getRole().value < Role.MODERATOR.value ? "<i> Ask your leader to:" : "<i>You should:"));
2011-10-10 01:21:05 +02:00
fme.sendMessage(p.cmdBase.cmdSethome.getUseageTemplate());
2011-03-23 17:39:56 +01:00
return;
}
if ( ! Conf.homesTeleportAllowedFromEnemyTerritory && fme.isInEnemyTerritory())
{
2011-10-10 13:40:24 +02:00
fme.msg("<b>You cannot teleport to your faction home while in the territory of an enemy faction.");
return;
}
if ( ! Conf.homesTeleportAllowedFromDifferentWorld && me.getWorld().getUID() != myFaction.getHome().getWorld().getUID())
{
2011-10-10 13:40:24 +02:00
fme.msg("<b>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()
&&
(
! fme.isInOwnTerritory()
||
(
fme.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())
{
if (p == null || !p.isOnline() || p.isDead() || p == fme || p.getWorld() != w)
continue;
FPlayer fp = FPlayers.i.get(p);
2011-10-12 17:25:01 +02:00
if (fme.getRelationTo(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;
2011-10-10 13:40:24 +02:00
fme.msg("<b>You cannot teleport to your faction home while an enemy is within " + Conf.homesTeleportAllowedEnemyDistance + " blocks of you.");
return;
}
}
// if Essentials teleport handling is enabled and available, pass the teleport off to it (for delay and cooldown)
if (EssentialsFeatures.handleTeleport(me, myFaction.getHome())) 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, "to teleport to your faction home", "for teleporting to your faction home")) return;
// Create a smoke effect
if (Conf.homesTeleportCommandSmokeEffectEnabled)
{
List<Location> smokeLocations = new ArrayList<Location>();
smokeLocations.add(me.getLocation());
smokeLocations.add(me.getLocation().clone().add(0, 1, 0));
smokeLocations.add(myFaction.getHome());
smokeLocations.add(myFaction.getHome().clone().add(0, 1, 0));
SmokeUtil.spawnCloudRandom(smokeLocations, Conf.homesTeleportCommandSmokeEffectThickness);
}
2011-10-08 23:22:02 +02:00
me.teleport(myFaction.getHome());
2011-03-23 17:39:56 +01:00
}
}