summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/commands/Commandworld.java
blob: 41a2d270de102f91eea9c5abf5f127cc2f819ca8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.earth2me.essentials.commands;

import java.util.List;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;


public class Commandworld extends EssentialsCommand
{
	public Commandworld()
	{
		super("world");
	}

	@Override
	protected void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception
	{
		World world;
		List<World> worlds = server.getWorlds();

		if (args.length < 1)
		{
			world = worlds.get(user.getWorld() == worlds.get(0) && worlds.size() > 1 ? 1 : 0);
		}
		else
		{
			try
			{
				int wid = Integer.parseInt(args[0]);
				world = server.getWorlds().get(wid);
			}
			catch (Throwable ex)
			{
				try
				{
					world = server.getWorld(getFinalArg(args, 0));
					if (world == null) throw new Exception();
				}
				catch (Throwable ex2)
				{
					user.sendMessage("§cInvalid world.");
					user.sendMessage("§7Possible worlds are the numbers 0 through " + (server.getWorlds().size() - 1) + ".");
					user.sendMessage("§7You can also type the name of a specific world.");
					return;
				}
			}
		}

		double factor;
		if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL)
			factor = 16;
		else if (user.getWorld().getEnvironment() != world.getEnvironment())
			factor = 1 / 16;
		else
			factor = 1;

		Location loc = user.getLocation();
		loc = new Location(world, loc.getBlockX() * factor + .5, loc.getBlockY(), loc.getBlockZ() * factor + .5);

		user.canAfford(this);
		user.teleportCooldown();
		user.teleportTo(loc, this.getName());
	}
}