summaryrefslogtreecommitdiffstats
path: root/EssentialsExtra/src/net/ess3/extra/commands/Commandkittycannon.java
blob: cc947ead21b6bea8db8862c4cf8ffea1e070f505 (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
package net.ess3.extra.commands;


import java.util.Random;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Ocelot;
import net.ess3.api.IUser;
import net.ess3.commands.EssentialsCommand;
import net.ess3.extra.AnnotatedCommand;


@AnnotatedCommand(description = "Throw an exploding kitten at your opponent", usage = "/<command>")
public class Commandkittycannon extends EssentialsCommand
{
	private static Random random = new Random();

	@Override
	protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception
	{
		final EntityType cat = EntityType.OCELOT;
		final Ocelot ocelot = (Ocelot)user.getPlayer().getWorld().spawn(user.getPlayer().getEyeLocation(), cat.getEntityClass());
		if (ocelot == null)
		{
			return;
		}
		final int i = random.nextInt(Ocelot.Type.values().length);
		ocelot.setCatType(Ocelot.Type.values()[i]);
		ocelot.setTamed(true);
		ocelot.setVelocity(user.getPlayer().getEyeLocation().getDirection().multiply(2));
		ess.getPlugin().scheduleSyncDelayedTask(
				new Runnable()
				{
					@Override
					public void run()
					{
						final Location loc = ocelot.getLocation();
						ocelot.remove();
						loc.getWorld().createExplosion(loc, 0F);
					}
				}, 20);
	}
}