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

147 lines
5.4 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
2014-04-04 20:55:21 +02:00
import com.massivecraft.factions.*;
2014-05-19 18:45:45 +02:00
import com.massivecraft.factions.integration.Essentials;
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;
2015-05-25 06:42:31 +02:00
import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.util.SmokeUtil;
import com.massivecraft.factions.zcore.util.TL;
2014-04-04 20:55:21 +02:00
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class CmdHome extends FCommand {
public CmdHome() {
2014-07-01 22:10:18 +02:00
super();
this.aliases.add("home");
2014-04-04 20:55:21 +02:00
//this.requiredArgs.add("");
//this.optionalArgs.put("", "");
2014-07-01 22:10:18 +02:00
this.permission = Permission.HOME.node;
this.disableOnLock = false;
2014-04-04 20:55:21 +02:00
2014-07-01 22:10:18 +02:00
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
2018-03-26 23:43:15 +02:00
senderMustBeColeader = false;
2014-07-01 22:10:18 +02:00
senderMustBeAdmin = false;
2014-04-04 20:55:21 +02:00
}
@Override
public void perform() {
// TODO: Hide this command on help also.
if (!Conf.homesEnabled) {
fme.msg(TL.COMMAND_HOME_DISABLED);
2014-07-01 22:10:18 +02:00
return;
2014-04-04 20:55:21 +02:00
}
if (!Conf.homesTeleportCommandEnabled) {
fme.msg(TL.COMMAND_HOME_TELEPORTDISABLED);
2014-07-01 22:10:18 +02:00
return;
2014-04-04 20:55:21 +02:00
}
if (!fme.isAdminBypassing()) {
Access access = myFaction.getAccess(fme, PermissableAction.HOME);
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "teleport home");
return;
}
}
2014-04-04 20:55:21 +02:00
if (!myFaction.hasHome()) {
fme.msg(TL.COMMAND_HOME_NOHOME.toString() + (fme.getRole().value < Role.MODERATOR.value ? TL.GENERIC_ASKYOURLEADER.toString() : TL.GENERIC_YOUSHOULD.toString()));
2014-07-01 22:10:18 +02:00
fme.sendMessage(p.cmdBase.cmdSethome.getUseageTemplate());
return;
2014-04-04 20:55:21 +02:00
}
if (!Conf.homesTeleportAllowedFromEnemyTerritory && fme.isInEnemyTerritory()) {
fme.msg(TL.COMMAND_HOME_INENEMY);
2014-07-01 22:10:18 +02:00
return;
2014-04-04 20:55:21 +02:00
}
if (!Conf.homesTeleportAllowedFromDifferentWorld && me.getWorld().getUID() != myFaction.getHome().getWorld().getUID()) {
fme.msg(TL.COMMAND_HOME_WRONGWORLD);
2014-07-01 22:10:18 +02:00
return;
2014-04-04 20:55:21 +02:00
}
Faction faction = Board.getInstance().getFactionAt(new FLocation(me.getLocation()));
2015-01-20 00:59:15 +01:00
final Location loc = me.getLocation().clone();
2014-04-04 20:55:21 +02:00
// if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby
2014-07-01 21:52:40 +02:00
if (Conf.homesTeleportAllowedEnemyDistance > 0 &&
!faction.isSafeZone() &&
(!fme.isInOwnTerritory() || (fme.isInOwnTerritory() && !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory))) {
2014-07-01 22:10:18 +02:00
World w = loc.getWorld();
double x = loc.getX();
double y = loc.getY();
double z = loc.getZ();
2014-04-04 20:55:21 +02:00
for (Player p : me.getServer().getOnlinePlayers()) {
2014-07-01 22:10:18 +02:00
if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w) {
continue;
}
2014-04-04 20:55:21 +02:00
FPlayer fp = FPlayers.getInstance().getByPlayer(p);
if (fme.getRelationTo(fp) != Relation.ENEMY || fp.isVanished()) {
2014-07-01 22:10:18 +02:00
continue;
}
2014-04-04 20:55:21 +02:00
2014-07-01 22:10:18 +02:00
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;
2014-04-04 20:55:21 +02:00
// box-shaped distance check
2014-07-01 22:10:18 +02:00
if (dx > max || dy > max || dz > max) {
continue;
}
2014-04-04 20:55:21 +02:00
2014-12-11 17:05:04 +01:00
fme.msg(TL.COMMAND_HOME_ENEMYNEAR, String.valueOf(Conf.homesTeleportAllowedEnemyDistance));
2014-04-04 20:55:21 +02:00
return;
}
}
2014-05-19 18:45:45 +02:00
// 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, TL.COMMAND_HOME_TOTELEPORT.toString(), TL.COMMAND_HOME_FORTELEPORT.toString())) {
2014-07-01 22:10:18 +02:00
return;
}
2014-05-19 18:45:45 +02:00
// if Essentials teleport handling is enabled and available, pass the teleport off to it (for delay and cooldown)
if (Essentials.handleTeleport(me, myFaction.getHome())) {
2014-04-04 20:55:21 +02:00
return;
2014-07-01 21:49:42 +02:00
}
2014-04-04 20:55:21 +02:00
2015-05-25 06:42:31 +02:00
this.doWarmUp(WarmUpUtil.Warmup.HOME, TL.WARMUPS_NOTIFY_TELEPORT, "Home", new Runnable() {
2015-01-20 00:59:15 +01:00
@Override
public void run() {
// Create a smoke effect
if (Conf.homesTeleportCommandSmokeEffectEnabled) {
2017-12-19 11:18:13 +01:00
List<Location> smokeLocations = new ArrayList<>();
2015-01-20 00:59:15 +01:00
smokeLocations.add(loc);
smokeLocations.add(loc.add(0, 1, 0));
smokeLocations.add(CmdHome.this.myFaction.getHome());
smokeLocations.add(CmdHome.this.myFaction.getHome().clone().add(0, 1, 0));
SmokeUtil.spawnCloudRandom(smokeLocations, Conf.homesTeleportCommandSmokeEffectThickness);
}
2011-03-23 17:39:56 +01:00
2015-01-20 00:59:15 +01:00
CmdHome.this.me.teleport(CmdHome.this.myFaction.getHome());
}
}, this.p.getConfig().getLong("warmups.f-home", 0));
2014-04-04 20:55:21 +02:00
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_HOME_DESCRIPTION;
}
2011-03-23 17:39:56 +01:00
}