2011-03-30 06:03:21 +02:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2011-06-13 15:05:11 +02:00
|
|
|
import com.earth2me.essentials.Trade;
|
2011-11-18 18:42:26 +01:00
|
|
|
import com.earth2me.essentials.User;
|
2017-06-11 02:17:43 +02:00
|
|
|
import com.google.common.collect.Lists;
|
2011-03-30 06:03:21 +02:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.World;
|
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;
|
2015-04-15 06:06:16 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
2011-03-30 06:03:21 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
public class Commandworld extends EssentialsCommand {
|
|
|
|
public Commandworld() {
|
|
|
|
super("world");
|
|
|
|
}
|
2011-03-30 06:03:21 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
@Override
|
|
|
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
|
|
|
World world;
|
2011-03-30 06:03:21 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
if (args.length < 1) {
|
|
|
|
World nether = null;
|
2011-11-21 02:55:26 +01:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
final List<World> worlds = server.getWorlds();
|
2011-10-11 02:03:38 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
for (World world2 : worlds) {
|
|
|
|
if (world2.getEnvironment() == World.Environment.NETHER) {
|
|
|
|
nether = world2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nether == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
world = user.getWorld() == nether ? worlds.get(0) : nether;
|
|
|
|
} else {
|
|
|
|
world = ess.getWorld(getFinalArg(args, 0));
|
|
|
|
if (world == null) {
|
|
|
|
user.sendMessage(tl("invalidWorld"));
|
|
|
|
user.sendMessage(tl("possibleWorlds", server.getWorlds().size() - 1));
|
|
|
|
user.sendMessage(tl("typeWorldName"));
|
|
|
|
throw new NoChargeException();
|
|
|
|
}
|
|
|
|
}
|
2011-03-30 06:03:21 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
if (ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + world.getName())) {
|
|
|
|
throw new Exception(tl("noPerm", "essentials.worlds." + world.getName()));
|
|
|
|
}
|
2011-12-03 18:13:42 +01:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
double factor;
|
|
|
|
if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL) {
|
|
|
|
factor = 8.0;
|
|
|
|
} else if (user.getWorld().getEnvironment() == World.Environment.NORMAL && world.getEnvironment() == World.Environment.NETHER) {
|
|
|
|
factor = 1.0 / 8.0;
|
|
|
|
} else {
|
|
|
|
factor = 1.0;
|
|
|
|
}
|
2011-03-30 06:03:21 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
final Location loc = user.getLocation();
|
|
|
|
final Location target = new Location(world, loc.getBlockX() * factor + .5, loc.getBlockY(), loc.getBlockZ() * factor + .5);
|
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(target, 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) {
|
|
|
|
List<String> worlds = Lists.newArrayList();
|
|
|
|
for (World world : server.getWorlds()) {
|
|
|
|
if (ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + world.getName())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
worlds.add(world.getName());
|
|
|
|
}
|
|
|
|
return worlds;
|
|
|
|
} else {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
2011-03-30 06:03:21 +02:00
|
|
|
}
|