summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java
blob: 921b9bc8950fc88e5bcb689b39f328d9c437beac (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 com.earth2me.essentials.commands;

import com.earth2me.essentials.Charge;
import org.bukkit.Server;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;


public class Commandtpaccept extends EssentialsCommand
{
	public Commandtpaccept()
	{
		super("tpaccept");
	}

	@Override
	public void run(Server server, User user, String commandLabel, String[] args) throws Exception
	{

		User p = user.getTeleportRequest();
		if (p == null)
		{
			throw new Exception(Util.i18n("noPendingRequest"));
		}

		Charge charge = new Charge(this);
		if (user.isTeleportRequestHere())
		{
			charge.isAffordableFor(user);
		}
		else
		{
			charge.isAffordableFor(p);
		}
		user.sendMessage(Util.i18n("requestAccepted"));
		p.sendMessage(Util.i18n("requestAccepted"));
		
		if (user.isTeleportRequestHere())
		{
			user.getTeleport().teleport(p, charge);
		}
		else
		{
			p.getTeleport().teleport(user, charge);
		}
		user.requestTeleport(null, false);
	}
}