2011-03-30 06:03:21 +02:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2011-11-18 18:42:26 +01:00
|
|
|
import com.earth2me.essentials.Trade;
|
2011-03-30 06:03:21 +02:00
|
|
|
import com.earth2me.essentials.User;
|
2013-06-08 23:31:19 +02:00
|
|
|
import com.earth2me.essentials.utils.LocationUtil;
|
2017-06-11 02:17:43 +02:00
|
|
|
import com.google.common.collect.Lists;
|
2011-11-18 18:42:26 +01:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Server;
|
2011-12-07 02:12:36 +01:00
|
|
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
2011-03-30 06:03:21 +02:00
|
|
|
|
2017-06-11 02:17:43 +02:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
2012-10-06 04:31:34 +02:00
|
|
|
// This method contains an undocumented sub command #EasterEgg
|
2015-04-15 06:06:16 +02:00
|
|
|
public class Commandjump extends EssentialsCommand {
|
|
|
|
public Commandjump() {
|
|
|
|
super("jump");
|
|
|
|
}
|
2011-03-30 06:03:21 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
@Override
|
|
|
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
|
|
|
if (args.length > 0 && args[0].contains("lock") && user.isAuthorized("essentials.jump.lock")) {
|
|
|
|
if (user.isFlyClickJump()) {
|
|
|
|
user.setRightClickJump(false);
|
2020-08-11 20:09:22 +02:00
|
|
|
user.sendMessage(tl("jumpEasterDisable"));
|
2015-04-15 06:06:16 +02:00
|
|
|
} else {
|
|
|
|
user.setRightClickJump(true);
|
2020-08-11 20:09:22 +02:00
|
|
|
user.sendMessage(tl("jumpEasterEnable"));
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2012-08-31 01:47:53 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
Location loc;
|
|
|
|
final Location cloc = user.getLocation();
|
2011-03-30 06:03:21 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
try {
|
|
|
|
loc = LocationUtil.getTarget(user.getBase());
|
|
|
|
loc.setYaw(cloc.getYaw());
|
|
|
|
loc.setPitch(cloc.getPitch());
|
|
|
|
loc.setY(loc.getY() + 1);
|
|
|
|
} catch (NullPointerException ex) {
|
|
|
|
throw new Exception(tl("jumpError"), ex);
|
|
|
|
}
|
2011-03-30 06:03:21 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
final Trade charge = new Trade(this.getName(), ess);
|
|
|
|
charge.isAffordableFor(user);
|
2020-06-24 10:52:25 +02:00
|
|
|
user.getAsyncTeleport().teleport(loc, charge, TeleportCause.COMMAND, getNewExceptionFuture(user.getSource(), commandLabel));
|
2020-08-16 23:40:58 +02:00
|
|
|
|
|
|
|
throw new NoChargeException();
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
2017-06-11 02:17:43 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
|
|
|
|
if (args.length == 1 && user.isAuthorized("essentials.jump.lock")) {
|
|
|
|
// XXX these actually do the same thing
|
|
|
|
return Lists.newArrayList("lock", "unlock");
|
|
|
|
} else {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
2011-03-30 06:03:21 +02:00
|
|
|
}
|