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

112 lines
3.9 KiB
Java
Raw Normal View History

2015-05-13 05:16:47 +02:00
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.*;
import com.massivecraft.factions.integration.Essentials;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.SpiralTask;
import com.massivecraft.factions.zcore.util.TL;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class CmdStuck extends FCommand {
public CmdStuck() {
super();
this.aliases.add("stuck");
this.aliases.add("halp!"); // halp!c:
this.permission = Permission.STUCK.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
final Player player = fme.getPlayer();
final Location sentAt = player.getLocation();
final FLocation chunk = fme.getLastStoodAt();
2019-08-02 23:01:33 +02:00
final long delay = P.p.getConfig().getLong("hcf.stuck.delay", 30);
final int radius = P.p.getConfig().getInt("hcf.stuck.radius", 10);
2019-08-02 23:01:33 +02:00
if (P.p.getStuckMap().containsKey(player.getUniqueId())) {
long wait = P.p.getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
String time = DurationFormatUtils.formatDuration(wait, TL.COMMAND_STUCK_TIMEFORMAT.toString(), true);
msg(TL.COMMAND_STUCK_EXISTS, time);
} else {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostStuck, TL.COMMAND_STUCK_TOSTUCK.format(fme.getName()), TL.COMMAND_STUCK_FORSTUCK.format(fme.getName()))) {
return;
}
2019-08-02 23:01:33 +02:00
final int id = Bukkit.getScheduler().runTaskLater(P.p, new BukkitRunnable() {
@Override
public void run() {
2019-08-02 23:01:33 +02:00
if (!P.p.getStuckMap().containsKey(player.getUniqueId())) {
return;
}
// check for world difference or radius exceeding
final World world = chunk.getWorld();
if (world.getUID() != player.getWorld().getUID() || sentAt.distance(player.getLocation()) > radius) {
msg(TL.COMMAND_STUCK_OUTSIDE.format(radius));
2019-08-02 23:01:33 +02:00
P.p.getTimers().remove(player.getUniqueId());
P.p.getStuckMap().remove(player.getUniqueId());
return;
}
final Board board = Board.getInstance();
// spiral task to find nearest wilderness chunk
new SpiralTask(new FLocation(me), radius * 2) {
@Override
public boolean work() {
FLocation chunk = currentFLocation();
Faction faction = board.getFactionAt(chunk);
2019-08-02 23:01:33 +02:00
int buffer = P.p.getConfig().getInt("world-border.buffer", 0);
if (faction.isWilderness() && !chunk.isOutsideWorldBorder(buffer)) {
int cx = FLocation.chunkToBlock((int) chunk.getX());
int cz = FLocation.chunkToBlock((int) chunk.getZ());
int y = world.getHighestBlockYAt(cx, cz);
Location tp = new Location(world, cx, y, cz);
msg(TL.COMMAND_STUCK_TELEPORT, tp.getBlockX(), tp.getBlockY(), tp.getBlockZ());
2019-08-02 23:01:33 +02:00
P.p.getTimers().remove(player.getUniqueId());
P.p.getStuckMap().remove(player.getUniqueId());
if (!Essentials.handleTeleport(player, tp)) {
player.teleport(tp);
2019-08-02 23:01:33 +02:00
P.p.debug("/f stuck used regular teleport, not essentials!");
}
this.stop();
return false;
}
return true;
}
};
}
}, delay * 20).getTaskId();
2019-08-02 23:01:33 +02:00
P.p.getTimers().put(player.getUniqueId(), System.currentTimeMillis() + (delay * 1000));
long wait = P.p.getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
String time = DurationFormatUtils.formatDuration(wait, TL.COMMAND_STUCK_TIMEFORMAT.toString(), true);
msg(TL.COMMAND_STUCK_START, time);
2019-08-02 23:01:33 +02:00
P.p.getStuckMap().put(player.getUniqueId(), id);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_STUCK_DESCRIPTION;
}
2015-05-13 05:16:47 +02:00
}