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

import static net.ess3.I18n._;
import net.ess3.api.IUser;
import net.ess3.economy.Trade;
import net.ess3.permissions.Permissions;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;


public class Commandspawn extends EssentialsCommand
{
	@Override
	public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
	{
		final Trade charge = new Trade(commandName, ess);
		charge.isAffordableFor(user);
		if (args.length > 0 && Permissions.SPAWN_OTHERS.isAuthorized(user))
		{
			final IUser otherUser = ess.getUserMap().matchUserExcludingHidden(args[0], user.getPlayer());
			respawn(otherUser, null);
			if (!otherUser.equals(user))
			{
				otherUser.sendMessage(_("{0} teleported you to {1}.", user.getPlayer().getDisplayName(), "spawn"));
				user.sendMessage(_("Teleporting..."));
			}
		}
		else
		{
			respawn(user, 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);
		respawn(user, null);
		user.sendMessage(_("{0} teleported you to {1}.", user.getPlayer().getDisplayName(), "spawn"));
		sender.sendMessage(_("Teleporting..."));
	}

	private void respawn(final IUser user, final Trade charge) throws Exception
	{
		final Location spawn = ess.getSpawns().getSpawn(ess.getRanks().getMainGroup(user));
		user.getTeleport().teleport(spawn, charge, TeleportCause.COMMAND);
	}
}