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
|
|
|
|
2013-04-09 13:24:55 +02:00
|
|
|
import com.massivecraft.factions.FFlag;
|
2013-04-16 11:27:03 +02:00
|
|
|
import com.massivecraft.factions.Factions;
|
2013-04-09 12:56:29 +02:00
|
|
|
import com.massivecraft.factions.Perm;
|
2013-04-09 13:24:55 +02:00
|
|
|
import com.massivecraft.factions.Rel;
|
2013-04-25 13:25:15 +02:00
|
|
|
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
2013-04-25 13:53:22 +02:00
|
|
|
import com.massivecraft.factions.cmd.req.ReqHasFaction;
|
2013-04-22 12:26:13 +02:00
|
|
|
import com.massivecraft.factions.entity.BoardColls;
|
2013-04-23 18:07:17 +02:00
|
|
|
import com.massivecraft.factions.entity.UConf;
|
2013-04-22 17:59:51 +02:00
|
|
|
import com.massivecraft.factions.entity.UPlayer;
|
2013-04-22 09:37:53 +02:00
|
|
|
import com.massivecraft.factions.entity.Faction;
|
2013-04-19 12:44:28 +02:00
|
|
|
import com.massivecraft.factions.event.FactionsEventHomeTeleport;
|
2013-04-16 10:11:59 +02:00
|
|
|
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
2013-04-16 09:48:57 +02:00
|
|
|
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
|
2013-04-17 11:47:48 +02:00
|
|
|
import com.massivecraft.mcore.mixin.Mixin;
|
|
|
|
import com.massivecraft.mcore.mixin.TeleporterException;
|
2013-04-11 11:11:31 +02:00
|
|
|
import com.massivecraft.mcore.ps.PS;
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2012-02-22 20:35:26 +01:00
|
|
|
|
2013-04-10 13:12:22 +02:00
|
|
|
public class CmdFactionsHome extends FCommand
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-11-11 09:31:04 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// CONSTRUCT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-04-10 13:12:22 +02:00
|
|
|
public CmdFactionsHome()
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-11-11 09:31:04 +01:00
|
|
|
// Aliases
|
2013-04-16 10:11:59 +02:00
|
|
|
this.addAliases("home");
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// Requirements
|
2013-04-25 13:25:15 +02:00
|
|
|
this.addRequirements(ReqFactionsEnabled.get());
|
2013-04-25 13:53:22 +02:00
|
|
|
this.addRequirements(ReqHasPerm.get(Perm.HOME.node));
|
|
|
|
this.addRequirements(ReqHasFaction.get());
|
2013-04-16 09:48:57 +02:00
|
|
|
this.addRequirements(ReqIsPlayer.get());
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE
|
|
|
|
// -------------------------------------------- //
|
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()
|
|
|
|
{
|
2013-04-23 18:07:17 +02:00
|
|
|
UConf uconf = UConf.get(sender);
|
|
|
|
|
2011-10-09 14:53:38 +02:00
|
|
|
// TODO: Hide this command on help also.
|
2013-04-23 18:07:17 +02:00
|
|
|
if ( ! uconf.homesEnabled)
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-04-25 07:29:19 +02:00
|
|
|
usender.msg("<b>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
|
|
|
|
2013-04-23 18:07:17 +02:00
|
|
|
if ( ! uconf.homesTeleportCommandEnabled)
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-04-25 07:29:19 +02:00
|
|
|
usender.msg("<b>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
|
|
|
|
2013-04-25 07:29:19 +02:00
|
|
|
if ( ! usenderFaction.hasHome())
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-04-25 07:29:19 +02:00
|
|
|
usender.msg("<b>Your faction does not have a home. " + (usender.getRole().isLessThan(Rel.OFFICER) ? "<i> Ask your leader to:" : "<i>You should:"));
|
|
|
|
usender.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsSethome.getUseageTemplate());
|
2011-03-23 17:39:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-25 07:29:19 +02:00
|
|
|
if ( ! uconf.homesTeleportAllowedFromEnemyTerritory && usender.isInEnemyTerritory())
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-04-25 07:29:19 +02:00
|
|
|
usender.msg("<b>You cannot teleport to your faction home while in the territory of an enemy faction.");
|
2011-06-19 10:56:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-25 07:29:19 +02:00
|
|
|
if (!uconf.homesTeleportAllowedFromDifferentWorld && !me.getWorld().getName().equalsIgnoreCase(usenderFaction.getHome().getWorld()))
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-04-25 07:29:19 +02:00
|
|
|
usender.msg("<b>You cannot teleport to your faction home while in a different world.");
|
2011-07-09 14:21:47 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-11 11:11:31 +02:00
|
|
|
|
2013-04-22 12:26:13 +02:00
|
|
|
Faction faction = BoardColls.get().getFactionAt(PS.valueOf(me));
|
2012-03-19 07:28:06 +01:00
|
|
|
Location loc = me.getLocation().clone();
|
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
|
|
|
|
(
|
2013-04-23 18:07:17 +02:00
|
|
|
uconf.homesTeleportAllowedEnemyDistance > 0
|
2011-10-09 14:53:38 +02:00
|
|
|
&&
|
2011-10-24 02:33:30 +02:00
|
|
|
faction.getFlag(FFlag.PVP)
|
2011-10-09 14:53:38 +02:00
|
|
|
&&
|
|
|
|
(
|
2013-04-25 07:29:19 +02:00
|
|
|
! usender.isInOwnTerritory()
|
2011-10-09 14:53:38 +02:00
|
|
|
||
|
|
|
|
(
|
2013-04-25 07:29:19 +02:00
|
|
|
usender.isInOwnTerritory()
|
2011-10-09 14:53:38 +02:00
|
|
|
&&
|
2013-04-23 18:07:17 +02:00
|
|
|
! uconf.homesTeleportIgnoreEnemiesIfInOwnTerritory
|
2011-10-09 14:53:38 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
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
|
|
|
{
|
2012-08-08 04:58:41 +02:00
|
|
|
if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w)
|
2011-05-29 23:28:29 +02:00
|
|
|
continue;
|
2011-06-09 03:33:12 +02:00
|
|
|
|
2013-04-22 17:59:51 +02:00
|
|
|
UPlayer fp = UPlayer.get(p);
|
2013-04-25 07:29:19 +02:00
|
|
|
if (usender.getRelationTo(fp) != Rel.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());
|
2013-04-23 18:07:17 +02:00
|
|
|
double max = uconf.homesTeleportAllowedEnemyDistance;
|
2011-06-09 03:33:12 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2013-04-25 07:29:19 +02:00
|
|
|
usender.msg("<b>You cannot teleport to your faction home while an enemy is within " + uconf.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
|
|
|
|
2013-04-19 12:44:28 +02:00
|
|
|
// Event
|
|
|
|
FactionsEventHomeTeleport event = new FactionsEventHomeTeleport(sender);
|
|
|
|
event.run();
|
|
|
|
if (event.isCancelled()) return;
|
|
|
|
|
|
|
|
// Apply
|
2013-04-17 11:47:48 +02:00
|
|
|
try
|
2012-01-27 22:22:32 +01:00
|
|
|
{
|
2013-04-25 07:29:19 +02:00
|
|
|
Mixin.teleport(me, usenderFaction.getHome(), "your faction home", sender);
|
2013-04-17 11:47:48 +02:00
|
|
|
}
|
|
|
|
catch (TeleporterException e)
|
|
|
|
{
|
|
|
|
me.sendMessage(e.getMessage());
|
2012-01-27 22:22:32 +01:00
|
|
|
}
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|