2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2013-04-09 13:24:55 +02:00
|
|
|
import com.massivecraft.factions.Rel;
|
2015-10-21 19:35:41 +02:00
|
|
|
import com.massivecraft.factions.cmd.type.TypeFaction;
|
2019-01-26 15:04:47 +01:00
|
|
|
import com.massivecraft.factions.cmd.type.TypeWarp;
|
2014-09-17 13:17:33 +02:00
|
|
|
import com.massivecraft.factions.entity.BoardColl;
|
2017-02-10 16:38:36 +01:00
|
|
|
import com.massivecraft.factions.entity.Faction;
|
2014-09-17 13:17:33 +02:00
|
|
|
import com.massivecraft.factions.entity.MConf;
|
2014-10-02 11:45:06 +02:00
|
|
|
import com.massivecraft.factions.entity.MFlag;
|
2014-10-02 14:02:07 +02:00
|
|
|
import com.massivecraft.factions.entity.MPerm;
|
2014-09-17 13:17:33 +02:00
|
|
|
import com.massivecraft.factions.entity.MPlayer;
|
2019-01-26 15:04:47 +01:00
|
|
|
import com.massivecraft.factions.entity.Warp;
|
|
|
|
import com.massivecraft.factions.event.EventFactionsWarpTeleport;
|
2015-02-12 12:00:55 +01:00
|
|
|
import com.massivecraft.massivecore.MassiveException;
|
2015-11-06 02:10:29 +01:00
|
|
|
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
|
2017-07-02 17:20:51 +02:00
|
|
|
import com.massivecraft.massivecore.mixin.MixinMessage;
|
2016-05-13 12:32:05 +02:00
|
|
|
import com.massivecraft.massivecore.mixin.MixinTeleport;
|
2014-06-04 14:02:23 +02:00
|
|
|
import com.massivecraft.massivecore.mixin.TeleporterException;
|
|
|
|
import com.massivecraft.massivecore.ps.PS;
|
2015-04-09 11:55:44 +02:00
|
|
|
import com.massivecraft.massivecore.teleport.Destination;
|
|
|
|
import com.massivecraft.massivecore.teleport.DestinationSimple;
|
2015-05-16 12:19:36 +02:00
|
|
|
import com.massivecraft.massivecore.util.MUtil;
|
2019-01-26 15:04:47 +01:00
|
|
|
import com.massivecraft.massivecore.util.Txt;
|
2017-03-24 13:05:58 +01:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.Player;
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2019-01-26 15:04:47 +01:00
|
|
|
public class CmdFactionsWarpGo extends FactionsCommandWarp
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-11-11 09:31:04 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// CONSTRUCT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2019-01-26 15:04:47 +01:00
|
|
|
public CmdFactionsWarpGo()
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2015-10-21 19:35:41 +02:00
|
|
|
// Parameters
|
2019-01-26 15:04:47 +01:00
|
|
|
this.addParameter(TypeWarp.get(), "warp");
|
2015-10-21 19:35:41 +02:00
|
|
|
this.addParameter(TypeFaction.get(), "faction", "you");
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// Requirements
|
2015-11-06 02:10:29 +01:00
|
|
|
this.addRequirements(RequirementIsPlayer.get());
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
2014-09-18 13:41:20 +02: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
|
2015-02-12 12:00:55 +01:00
|
|
|
public void perform() throws MassiveException
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2014-09-18 13:41:20 +02:00
|
|
|
// Args
|
2019-01-26 15:04:47 +01:00
|
|
|
Faction faction = this.readArgAt(1, msenderFaction);
|
|
|
|
Warp warp = TypeWarp.get(faction).read(this.argAt(0), sender);
|
|
|
|
String warpDesc = Txt.parse("<h>%s <i>in <reset>%s<i>.", warp.getName(), faction.describeTo(msender, false));
|
2019-08-11 16:21:56 +02:00
|
|
|
|
|
|
|
// Must be valid
|
|
|
|
if (!warp.verifyIsValid()) return;
|
|
|
|
|
2014-10-03 09:01:36 +02:00
|
|
|
// Any and MPerm
|
2019-01-27 17:29:28 +01:00
|
|
|
if ( ! MPerm.getPermWarp().has(msender, faction, true)) return;
|
2014-09-18 13:41:20 +02:00
|
|
|
|
2019-01-26 15:04:47 +01:00
|
|
|
if ( ! MConf.get().warpsTeleportAllowedFromEnemyTerritory && msender.isInEnemyTerritory())
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2019-01-26 15:04:47 +01:00
|
|
|
throw new MassiveException().addMsg("<b>You cannot teleport to %s <b>while in the territory of an enemy faction.", warp);
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
|
|
|
|
2019-01-26 15:04:47 +01:00
|
|
|
if ( ! MConf.get().warpsTeleportAllowedFromDifferentWorld && !me.getWorld().getName().equalsIgnoreCase(warp.getWorld()))
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2019-01-26 15:04:47 +01:00
|
|
|
throw new MassiveException().addMsg("<b>You cannot teleport to %s <b>while in a different world.", warpDesc);
|
2011-06-19 10:56:21 +02:00
|
|
|
}
|
2019-01-26 15:04:47 +01:00
|
|
|
|
2014-11-18 10:00:15 +01:00
|
|
|
Faction factionHere = BoardColl.get().getFactionAt(PS.valueOf(me.getLocation()));
|
2014-09-18 13:41:20 +02:00
|
|
|
Location locationHere = 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
|
|
|
|
(
|
2019-01-26 15:04:47 +01:00
|
|
|
MConf.get().warpsTeleportAllowedEnemyDistance > 0
|
2011-10-09 14:53:38 +02:00
|
|
|
&&
|
2014-10-07 12:30:44 +02:00
|
|
|
factionHere.getFlag(MFlag.getFlagPvp())
|
2011-10-09 14:53:38 +02:00
|
|
|
&&
|
|
|
|
(
|
2014-09-18 13:41:20 +02:00
|
|
|
! msender.isInOwnTerritory()
|
2011-10-09 14:53:38 +02:00
|
|
|
||
|
|
|
|
(
|
2014-09-18 13:41:20 +02:00
|
|
|
msender.isInOwnTerritory()
|
2011-10-09 14:53:38 +02:00
|
|
|
&&
|
2019-01-26 15:04:47 +01:00
|
|
|
! MConf.get().warpsTeleportIgnoreEnemiesIfInOwnTerritory
|
2011-10-09 14:53:38 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
2014-09-18 13:41:20 +02:00
|
|
|
World w = locationHere.getWorld();
|
|
|
|
double x = locationHere.getX();
|
|
|
|
double y = locationHere.getY();
|
|
|
|
double z = locationHere.getZ();
|
2011-05-29 23:28:29 +02:00
|
|
|
|
2019-01-26 15:04:47 +01:00
|
|
|
for (Player p : w.getPlayers())
|
2011-05-29 23:28:29 +02:00
|
|
|
{
|
2015-05-16 14:30:49 +02:00
|
|
|
if (MUtil.isntPlayer(p)) continue;
|
2015-05-16 12:19:36 +02:00
|
|
|
|
2019-03-03 10:16:41 +01:00
|
|
|
if (!p.isOnline() || p.isDead() || p == me || p.getWorld() != w) continue;
|
2011-06-09 03:33:12 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
MPlayer fp = MPlayer.get(p);
|
2019-01-26 15:04:47 +01:00
|
|
|
if (msender.getRelationTo(fp) != Rel.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());
|
2019-01-26 15:04:47 +01:00
|
|
|
double max = MConf.get().warpsTeleportAllowedEnemyDistance;
|
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
|
|
|
|
2019-01-26 15:04:47 +01:00
|
|
|
throw new MassiveException().addMsg("<b>You cannot teleport to %s <b>while an enemy is within %f blocks of you.", warpDesc, max);
|
2011-05-29 23:28:29 +02:00
|
|
|
}
|
|
|
|
}
|
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
|
2019-01-26 15:04:47 +01:00
|
|
|
EventFactionsWarpTeleport event = new EventFactionsWarpTeleport(sender, warp);
|
2013-04-19 12:44:28 +02:00
|
|
|
event.run();
|
|
|
|
if (event.isCancelled()) return;
|
|
|
|
|
|
|
|
// Apply
|
2013-04-17 11:47:48 +02:00
|
|
|
try
|
2012-01-27 22:22:32 +01:00
|
|
|
{
|
2019-01-26 15:04:47 +01:00
|
|
|
Destination destination = new DestinationSimple(warp.getLocation(), warpDesc);
|
2016-05-13 12:32:05 +02:00
|
|
|
MixinTeleport.get().teleport(me, destination, sender);
|
2013-04-17 11:47:48 +02:00
|
|
|
}
|
|
|
|
catch (TeleporterException e)
|
|
|
|
{
|
2017-07-02 17:20:51 +02:00
|
|
|
String message = e.getMessage();
|
|
|
|
MixinMessage.get().messageOne(me, message);
|
2012-01-27 22:22:32 +01:00
|
|
|
}
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|