[Feature] Allow the placing of spawners with predefined network id's (/i spawner:50)

[Permission] essentials.spawnerconvert.<mobname> - Allow the placing of specific mobspawners with premade network id's.
This commit is contained in:
KHobbits 2013-06-23 16:11:24 +01:00
parent 88d025cd0f
commit 1cb9ddf9fe
2 changed files with 39 additions and 8 deletions

View File

@ -1,7 +1,12 @@
package com.earth2me.essentials;
import com.earth2me.essentials.utils.LocationUtil;
import java.util.Locale;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -28,19 +33,38 @@ public class EssentialsBlockListener implements Listener
{
return;
}
if (is.getType() == Material.MOB_SPAWNER && event.getItemInHand() != null && event.getPlayer() != null
&& event.getItemInHand().getType() == Material.MOB_SPAWNER)
{
final BlockState blockState = event.getBlockPlaced().getState();
if (blockState instanceof CreatureSpawner)
{
final CreatureSpawner spawner = (CreatureSpawner)blockState;
final EntityType type = EntityType.fromId(event.getItemInHand().getData().getData());
if (type != null && Mob.fromBukkitType(type) != null)
{
if (ess.getUser(event.getPlayer()).isAuthorized("essentials.spawnerconvert." + Mob.fromBukkitType(type).name().toLowerCase(Locale.ENGLISH)))
{
spawner.setSpawnedType(type);
}
}
}
}
final User user = ess.getUser(event.getPlayer());
if (user.hasUnlimited(is) && user.getGameMode() == GameMode.SURVIVAL)
{
ess.scheduleSyncDelayedTask(
new Runnable()
{
@Override
public void run()
{
user.getInventory().addItem(is);
user.updateInventory();
}
});
{
@Override
public void run()
{
user.getInventory().addItem(is);
user.updateInventory();
}
});
}
}
}

View File

@ -50,6 +50,7 @@ public enum Mob
MINECART_FURNACE("FurnaceMinecart", Enemies.NEUTRAL, EntityType.MINECART_FURNACE),
MINECART_TNT("TNTMinecart", Enemies.NEUTRAL, EntityType.MINECART_TNT),
MINECART_HOPPER("HopperMinecart", Enemies.NEUTRAL, EntityType.MINECART_HOPPER),
MINECART_MOB_SPAWNER("SpawnerMinecart", Enemies.NEUTRAL, EntityType.MINECART_MOB_SPAWNER),
ENDERCRYSTAL("EnderCrystal", Enemies.NEUTRAL, EntityType.ENDER_CRYSTAL),
EXPERIENCEORB("ExperienceOrb", Enemies.NEUTRAL, EntityType.EXPERIENCE_ORB);
public static final Logger logger = Logger.getLogger("Minecraft");
@ -73,12 +74,14 @@ public enum Mob
final public Enemies type;
final private EntityType bukkitType;
private static final Map<String, Mob> hashMap = new HashMap<String, Mob>();
private static final Map<EntityType, Mob> bukkitMap = new HashMap<EntityType, Mob>();
static
{
for (Mob mob : Mob.values())
{
hashMap.put(mob.name.toLowerCase(Locale.ENGLISH), mob);
bukkitMap.put(mob.bukkitType, mob);
}
}
@ -127,6 +130,10 @@ public enum Mob
return hashMap.get(name.toLowerCase(Locale.ENGLISH));
}
public static Mob fromBukkitType(final EntityType type)
{
return bukkitMap.get(type);
}
public static class MobException extends Exception
{