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

import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.entity.CreatureType;


public class Commandspawner extends EssentialsCommand
{
	public Commandspawner()
	{
		super("spawner");
	}

	@Override
	protected void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception
	{
		if (args.length < 1)
		{
			user.sendMessage(ChatColor.RED + "Usage: /" + commandLabel + " [mob]");
			return;
		}

		Block target = user.getTarget().getTargetBlock();
		if (target.getType() != Material.MOB_SPAWNER)
			throw new Exception("Target block must be a mob spawner.");

		try
		{
			user.charge(this);
			((CreatureSpawner)target).setCreatureType(CreatureType.fromName(args[0]));
		}
		catch (Throwable ex)
		{
		}
	}
}