Introduced Brigadier Command System. More Formatting Coming in next commit.
This commit is contained in:
@@ -10,87 +10,75 @@ 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;
|
||||
|
||||
this.requirements = new CommandRequirements.Builder(Permission.STUCK)
|
||||
.playerOnly()
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
final Player player = fme.getPlayer();
|
||||
public void perform(CommandContext context) {
|
||||
final Player player = context.player;
|
||||
final Location sentAt = player.getLocation();
|
||||
final FLocation chunk = fme.getLastStoodAt();
|
||||
final long delay = P.p.getConfig().getLong("hcf.stuck.delay", 30);
|
||||
final int radius = P.p.getConfig().getInt("hcf.stuck.radius", 10);
|
||||
final FLocation chunk = context.fPlayer.getLastStoodAt();
|
||||
final long delay = FactionsPlugin.getInstance().getConfig().getLong("hcf.stuck.delay", 30);
|
||||
final int radius = FactionsPlugin.getInstance().getConfig().getInt("hcf.stuck.radius", 10);
|
||||
|
||||
if (P.p.getStuckMap().containsKey(player.getUniqueId())) {
|
||||
long wait = P.p.getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
|
||||
if (FactionsPlugin.getInstance().getStuckMap().containsKey(player.getUniqueId())) {
|
||||
long wait = FactionsPlugin.getInstance().getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
|
||||
String time = DurationFormatUtils.formatDuration(wait, TL.COMMAND_STUCK_TIMEFORMAT.toString(), true);
|
||||
msg(TL.COMMAND_STUCK_EXISTS, time);
|
||||
context.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()))) {
|
||||
if (!context.payForCommand(Conf.econCostStuck, TL.COMMAND_STUCK_TOSTUCK.format(context.fPlayer.getName()), TL.COMMAND_STUCK_FORSTUCK.format(context.fPlayer.getName()))) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int id = Bukkit.getScheduler().runTaskLater(P.p, new BukkitRunnable() {
|
||||
final int id = Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!P.p.getStuckMap().containsKey(player.getUniqueId())) {
|
||||
if (!FactionsPlugin.getInstance().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));
|
||||
P.p.getTimers().remove(player.getUniqueId());
|
||||
P.p.getStuckMap().remove(player.getUniqueId());
|
||||
context.msg(TL.COMMAND_STUCK_OUTSIDE.format(radius));
|
||||
FactionsPlugin.getInstance().getTimers().remove(player.getUniqueId());
|
||||
FactionsPlugin.getInstance().getStuckMap().remove(player.getUniqueId());
|
||||
return;
|
||||
}
|
||||
|
||||
final Board board = Board.getInstance();
|
||||
// spiral task to find nearest wilderness chunk
|
||||
new SpiralTask(new FLocation(me), radius * 2) {
|
||||
|
||||
final int buffer = P.p.getConfig().getInt("world-border.buffer", 0);
|
||||
|
||||
new SpiralTask(new FLocation(context.player), radius * 2) {
|
||||
@Override
|
||||
public boolean work() {
|
||||
FLocation chunk = currentFLocation();
|
||||
if (chunk.isOutsideWorldBorder(buffer)) {
|
||||
return true;
|
||||
}
|
||||
Faction faction = board.getFactionAt(chunk);
|
||||
int buffer = P.p.getConfig().getInt("world-border.buffer", 0);
|
||||
int buffer = FactionsPlugin.getInstance().getConfig().getInt("world-border.buffer", 0) - 1;
|
||||
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());
|
||||
P.p.getTimers().remove(player.getUniqueId());
|
||||
P.p.getStuckMap().remove(player.getUniqueId());
|
||||
context.msg(TL.COMMAND_STUCK_TELEPORT, tp.getBlockX(), tp.getBlockY(), tp.getBlockZ());
|
||||
FactionsPlugin.getInstance().getTimers().remove(player.getUniqueId());
|
||||
FactionsPlugin.getInstance().getStuckMap().remove(player.getUniqueId());
|
||||
if (!Essentials.handleTeleport(player, tp)) {
|
||||
player.teleport(tp);
|
||||
P.p.debug("/f stuck used regular teleport, not essentials!");
|
||||
FactionsPlugin.getInstance().debug("/f stuck used regular teleport, not essentials!");
|
||||
}
|
||||
this.stop();
|
||||
return false;
|
||||
@@ -101,11 +89,11 @@ public class CmdStuck extends FCommand {
|
||||
}
|
||||
}, delay * 20).getTaskId();
|
||||
|
||||
P.p.getTimers().put(player.getUniqueId(), System.currentTimeMillis() + (delay * 1000));
|
||||
long wait = P.p.getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
|
||||
FactionsPlugin.getInstance().getTimers().put(player.getUniqueId(), System.currentTimeMillis() + (delay * 1000));
|
||||
long wait = FactionsPlugin.getInstance().getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
|
||||
String time = DurationFormatUtils.formatDuration(wait, TL.COMMAND_STUCK_TIMEFORMAT.toString(), true);
|
||||
msg(TL.COMMAND_STUCK_START, time);
|
||||
P.p.getStuckMap().put(player.getUniqueId(), id);
|
||||
context.msg(TL.COMMAND_STUCK_START, time);
|
||||
FactionsPlugin.getInstance().getStuckMap().put(player.getUniqueId(), id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,3 +102,4 @@ public class CmdStuck extends FCommand {
|
||||
return TL.COMMAND_STUCK_DESCRIPTION;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user