mirror of
https://github.com/essentials/Essentials.git
synced 2025-09-25 13:49:12 +02:00
Added try/catch around the tnt and creeper protection code. The event will now always canceled, even if our fake explosion code fails.
56 lines
1.4 KiB
Java
56 lines
1.4 KiB
Java
package com.earth2me.essentials.commands;
|
|
|
|
import com.earth2me.essentials.Mob;
|
|
import com.earth2me.essentials.User;
|
|
import com.earth2me.essentials.Util;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.Server;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.block.CreatureSpawner;
|
|
|
|
|
|
public class Commandspawner extends EssentialsCommand
|
|
{
|
|
public Commandspawner()
|
|
{
|
|
super("spawner");
|
|
}
|
|
|
|
@Override
|
|
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
|
{
|
|
if (args.length < 1 || args[0].length() < 2)
|
|
{
|
|
throw new NotEnoughArgumentsException();
|
|
//TODO: user.sendMessage("§7Mobs: Zombie PigZombie Skeleton Slime Chicken Pig Monster Spider Creeper Ghast Squid Giant Cow Sheep Wolf");
|
|
}
|
|
|
|
final Block target = user.getTarget().getTargetBlock();
|
|
if (target.getType() != Material.MOB_SPAWNER)
|
|
{
|
|
throw new Exception(Util.i18n("mobSpawnTarget"));
|
|
}
|
|
|
|
charge(user);
|
|
try
|
|
{
|
|
String name = args[0];
|
|
name = name.equalsIgnoreCase("PigZombie") ? "PigZombie" : Util.capitalCase(name);
|
|
|
|
Mob mob = null;
|
|
mob = Mob.fromName(name);
|
|
if (mob == null)
|
|
{
|
|
user.sendMessage(Util.i18n("invalidMob"));
|
|
return;
|
|
}
|
|
((CreatureSpawner)target.getState()).setCreatureType(mob.getType());
|
|
user.sendMessage(Util.format("setSpawner", mob.name));
|
|
}
|
|
catch (Throwable ex)
|
|
{
|
|
throw new Exception(Util.i18n("mobSpawnError"), ex);
|
|
}
|
|
}
|
|
}
|