2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
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;
|
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;
|
2011-10-09 14:53:38 +02:00
|
|
|
import com.massivecraft.factions.FPlayers;
|
2011-07-18 22:06:02 +02:00
|
|
|
import com.massivecraft.factions.Faction;
|
2011-10-09 14:53:38 +02:00
|
|
|
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;
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2011-10-09 20:10:19 +02:00
|
|
|
public class CmdHome extends FCommand
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2011-10-09 20:10:19 +02:00
|
|
|
public CmdHome()
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.aliases.add("home");
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2011-10-09 14:53:38 +02:00
|
|
|
//this.requiredArgs.add("");
|
|
|
|
//this.optionalArgs.put("", "");
|
|
|
|
|
2011-10-09 21:57:43 +02:00
|
|
|
this.permission = Permission.HOME.node;
|
|
|
|
this.disableOnLock = false;
|
2011-10-09 14:53:38 +02:00
|
|
|
|
|
|
|
senderMustBePlayer = true;
|
|
|
|
senderMustBeMember = true;
|
|
|
|
senderMustBeModerator = false;
|
|
|
|
senderMustBeAdmin = false;
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
|
|
|
|
2011-06-21 07:38:31 +02:00
|
|
|
@Override
|
2011-10-09 14:53:38 +02:00
|
|
|
public void perform()
|
|
|
|
{
|
|
|
|
// TODO: Hide this command on help also.
|
|
|
|
if ( ! Conf.homesEnabled)
|
|
|
|
{
|
|
|
|
fme.sendMessage("Sorry, Faction homes are disabled on this server.");
|
2011-03-23 17:39:56 +01:00
|
|
|
return;
|
|
|
|
}
|
2011-06-29 01:29:14 +02:00
|
|
|
|
2011-10-09 14:53:38 +02:00
|
|
|
if ( ! Conf.homesTeleportCommandEnabled)
|
|
|
|
{
|
|
|
|
fme.sendMessage("Sorry, the ability to teleport to Faction homes is disabled on this server.");
|
2011-06-29 01:29:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2011-10-09 14:53:38 +02:00
|
|
|
if ( ! myFaction.hasHome())
|
|
|
|
{
|
|
|
|
fme.sendMessage("You faction does not have a home. " + (fme.getRole().value < Role.MODERATOR.value ? " Ask your leader to:" : "You should:"));
|
2011-10-09 20:10:19 +02:00
|
|
|
fme.sendMessage(new CmdSethome().getUseageTemplate());
|
2011-03-23 17:39:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-09 14:53:38 +02:00
|
|
|
if ( ! Conf.homesTeleportAllowedFromEnemyTerritory && fme.isInEnemyTerritory())
|
|
|
|
{
|
|
|
|
fme.sendMessage("You cannot teleport to your faction home while in the territory of an enemy faction.");
|
2011-06-19 10:56:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-09 14:53:38 +02:00
|
|
|
if ( ! Conf.homesTeleportAllowedFromDifferentWorld && me.getWorld().getUID() != myFaction.getHome().getWorld().getUID())
|
|
|
|
{
|
|
|
|
fme.sendMessage("You cannot teleport to your faction home while in a different world.");
|
2011-07-09 14:21:47 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-08 23:22:02 +02:00
|
|
|
Faction faction = Board.getFactionAt(new FLocation(me.getLocation()));
|
2011-07-09 14:21:47 +02:00
|
|
|
|
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
|
2011-10-09 14:53:38 +02:00
|
|
|
if
|
|
|
|
(
|
|
|
|
Conf.homesTeleportAllowedEnemyDistance > 0
|
|
|
|
&&
|
|
|
|
! faction.isSafeZone()
|
|
|
|
&&
|
|
|
|
(
|
|
|
|
! fme.isInOwnTerritory()
|
|
|
|
||
|
|
|
|
(
|
|
|
|
fme.isInOwnTerritory()
|
|
|
|
&&
|
|
|
|
! Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
2011-10-08 23:22:02 +02:00
|
|
|
Location loc = me.getLocation();
|
2011-05-29 23:28:29 +02:00
|
|
|
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
|
|
|
|
2011-10-08 23:22:02 +02:00
|
|
|
for (Player p : me.getServer().getOnlinePlayers())
|
2011-05-29 23:28:29 +02:00
|
|
|
{
|
2011-10-09 14:53:38 +02:00
|
|
|
if (p == null || !p.isOnline() || p.isDead() || p == fme || p.getWorld() != w)
|
2011-05-29 23:28:29 +02:00
|
|
|
continue;
|
2011-06-09 03:33:12 +02:00
|
|
|
|
2011-10-09 14:53:38 +02:00
|
|
|
FPlayer fp = FPlayers.i.get(p);
|
|
|
|
if (fme.getRelation(fp) != Relation.ENEMY)
|
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
|
|
|
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-10-09 14:53:38 +02:00
|
|
|
fme.sendMessage("You cannot teleport to your faction home while an enemy is within " + Conf.homesTeleportAllowedEnemyDistance + " blocks of you.");
|
2011-05-29 23:28:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
|
|
|
|
|
|
|
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
2011-10-09 14:53:38 +02:00
|
|
|
if ( ! payForCommand(Conf.econCostHome))
|
|
|
|
{
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-08 23:22:02 +02:00
|
|
|
me.teleport(myFaction.getHome());
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|