summaryrefslogtreecommitdiffstats
path: root/EssentialsSigns/src/net/ess3/signs/signs/SignSpawnmob.java
blob: a0398e9fc4be576c540cfb342cb452c1b35c5cd0 (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
package net.ess3.signs.signs;

import net.ess3.SpawnMob;
import net.ess3.api.ChargeException;
import net.ess3.api.IEssentials;
import net.ess3.api.IUser;
import net.ess3.economy.Trade;
import net.ess3.signs.EssentialsSign;

import java.util.List;


public class SignSpawnmob extends EssentialsSign
{
	public SignSpawnmob()
	{
		super("Spawnmob");
	}

	@Override
	protected boolean onSignCreate(ISign sign, IUser player, String username, IEssentials ess) throws SignException, ChargeException
	{
		validateInteger(sign, 1);
		validateTrade(sign, 3, ess);
		return true;
	}

	@Override
	protected boolean onSignInteract(ISign sign, IUser player, String username, IEssentials ess) throws SignException, ChargeException
	{
		final Trade charge = getTrade(sign, 3, ess);
		charge.isAffordableFor(player);
		try
		{
			List<String> mobParts = SpawnMob.mobParts(sign.getLine(2));
			List<String> mobData = SpawnMob.mobData(sign.getLine(2));
			SpawnMob.spawnmob(ess, ess.getServer(), player, player, mobParts, mobData, Integer.parseInt(sign.getLine(1)));
		}
		catch (Exception ex)
		{
			throw new SignException(ex.getMessage(), ex);
		}
		charge.charge(player);
		return true;
	}
}