Skip to content

Commit

Permalink
[Feature] Allow the placing of spawners with predefined network id's …
Browse files Browse the repository at this point in the history
…(/i spawner:50)

[Permission] essentials.spawnerconvert.<mobname> - Allow the placing of specific mobspawners with premade network id's.
  • Loading branch information
khobbits committed Jun 23, 2013
1 parent 98ee079 commit 3823344
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -28,19 +33,38 @@ public void onBlockPlace(final BlockPlaceEvent event)
{
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();
}
});
}
}
}
7 changes: 7 additions & 0 deletions Essentials/src/com/earth2me/essentials/Mob.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -73,12 +74,14 @@ private Mob(String n, Enemies en, EntityType type)
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);
}
}

Expand Down Expand Up @@ -127,6 +130,10 @@ public static Mob fromName(final String name)
return hashMap.get(name.toLowerCase(Locale.ENGLISH));
}

public static Mob fromBukkitType(final EntityType type)
{
return bukkitMap.get(type);
}

public static class MobException extends Exception
{
Expand Down

0 comments on commit 3823344

Please sign in to comment.