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

import static net.ess3.I18n._;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
import net.ess3.permissions.Permissions;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;


public class Commandtpohere extends EssentialsCommand
{
	@Override
	public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
	{
		if (args.length < 1)
		{
			throw new NotEnoughArgumentsException();
		}

		//Just basically the old tphere command
		final IUser player = ess.getUserMap().matchUser(args[0], false);

		ISettings settings = ess.getSettings();
		//todo - common method
		if (user.getPlayer().getWorld() != player.getPlayer().getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions() && !Permissions.WORLD.isAuthorized(
				player, user.getPlayer().getWorld().getName()))
		{
			throw new Exception(_("You do not have the {0} permission.", "essentials.world." + user.getPlayer().getWorld().getName()));
		}
		if (settings.getData().getGeneral().isPerGroupTeleport() && !Permissions.PERGROUPTELEPORT.isAuthorized(
					user, ess.getRanks().getMainGroup(player)))
			{
				throw new Exception(_("You do not have the {0} permission.", "essentials.teleport.groups." + ess.getRanks().getMainGroup(player)));
			}


		// Verify permission
		if (user.getPlayer().canSee(player.getPlayer()) || Permissions.TELEPORT_HIDDEN.isAuthorized(user))
		{
			player.getTeleport().now(user.getPlayer(), false, TeleportCause.COMMAND);
			user.sendMessage(_("Teleporting..."));
		}
		else
		{
			throw new NoSuchFieldException(_("Player not found."));
		}
	}
}