summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/signs/SignRepair.java
blob: 361cd4c55e2689d88ed33c19dfab92b44dc5d161 (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
package com.earth2me.essentials.signs;

import com.earth2me.essentials.ChargeException;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.commands.Commandrepair;


public class SignRepair extends EssentialsSign
{
	public SignRepair()
	{
		super("Repair");
	}

	@Override
	protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
	{
		final String repairTarget = sign.getLine(1);
		if (repairTarget.isEmpty())
		{
			sign.setLine(1, "Hand");
		}
		else if (!repairTarget.equalsIgnoreCase("all") && !repairTarget.equalsIgnoreCase("hand") )
		{
			throw new SignException(_("invalidSignLine", 2));
		}		
		validateTrade(sign, 2, ess);
		return true;
	}

	@Override
	protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
	{
		final Trade charge = getTrade(sign, 2, ess);
		charge.isAffordableFor(player);
		
		Commandrepair command = new Commandrepair();
		command.setEssentials(ess);
		String[] args = new String[]
		{
			sign.getLine(1)
		};
		try
		{
			command.run(ess.getServer(), player, "repair", args);
		}
		catch (Exception ex)
		{
			throw new SignException(ex.getMessage(), ex);
		}
		charge.charge(player);					
		return true;
	}
}