summaryrefslogtreecommitdiffstats
path: root/Essentials/src/net/ess3/commands/Commandgetpos.java
blob: 43965577665fdc20d39526d16bb29e67aa3b756e (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
package net.ess3.commands;

import net.ess3.api.IUser;
import net.ess3.permissions.Permissions;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import static net.ess3.I18n._;



public class Commandgetpos extends EssentialsCommand
{
	@Override
	public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
	{
		final Player mainPlayer = user.getPlayer();
		final Location mainPlayerLoc = mainPlayer.getLocation();
		if (args.length > 0 && Permissions.GETPOS_OTHERS.isAuthorized(user))
		{
			//todo permissions
			final IUser otherUser = ess.getUserMap().matchUser(args[0], false);
			if (mainPlayer.canSee(otherUser.getPlayer()) || Permissions.LIST_HIDDEN.isAuthorized(user))
			{
				outputPosition(user, otherUser.getPlayer().getLocation(), mainPlayerLoc);
				return;
			}

		}
		outputPosition(user, mainPlayerLoc, null);
	}

	@Override
	protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
	{
		if (args.length < 1)
		{
			throw new NotEnoughArgumentsException();
		}
		final IUser user = ess.getUserMap().matchUser(args[0], false);
		outputPosition(sender, user.getPlayer().getLocation(), null);
	}

	private void outputPosition(final CommandSender sender, final Location coords, final Location distance)
	{
		final World world = coords.getWorld();
		sender.sendMessage(_("getposWorld", world.getName()));
		sender.sendMessage(_("getposX", coords.getBlockX()));
		sender.sendMessage(_("getposY", coords.getBlockY()));
		sender.sendMessage(_("getposZ", coords.getBlockZ()));
		sender.sendMessage(_("getposYaw", (coords.getYaw() + 540) % 360));
		sender.sendMessage(_("getposPitch", coords.getPitch()));
		if (distance != null && world.equals(distance.getWorld()))
		{
			sender.sendMessage(_("getposDistance", coords.distance(distance)));
		}
	}
}