use of org.bukkit.block.CreatureSpawner in project Essentials by drtshock.
the class BlockMetaSpawnerProvider method getEntityType.
@Override
public EntityType getEntityType(ItemStack is) {
BlockStateMeta bsm = (BlockStateMeta) is.getItemMeta();
CreatureSpawner bs = (CreatureSpawner) bsm.getBlockState();
return bs.getSpawnedType();
}
use of org.bukkit.block.CreatureSpawner in project Essentials by drtshock.
the class BlockMetaSpawnerProvider method setEntityType.
@Override
public ItemStack setEntityType(ItemStack is, EntityType type) {
BlockStateMeta bsm = (BlockStateMeta) is.getItemMeta();
BlockState bs = bsm.getBlockState();
((CreatureSpawner) bs).setSpawnedType(type);
bsm.setBlockState(bs);
is.setItemMeta(bsm);
return setDisplayName(is, type);
}
use of org.bukkit.block.CreatureSpawner in project Towny by ElgarL.
the class TownyRegenAPI method regenChunk.
/**
* Regenerate the chunk the player is stood in and store the block data so it can be undone later.
*
* @param player
*/
public static void regenChunk(Player player) {
try {
Coord coord = Coord.parseCoord(player);
World world = player.getWorld();
Chunk chunk = world.getChunkAt(player.getLocation());
int maxHeight = world.getMaxHeight();
Object[][][] snapshot = new Object[16][maxHeight][16];
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < maxHeight; y++) {
//Current block to save
BlockState state = chunk.getBlock(x, y, z).getState();
if (state instanceof org.bukkit.block.Sign) {
BlockSign sign = new BlockSign(BukkitTools.getTypeId(state), BukkitTools.getDataData(state), ((org.bukkit.block.Sign) state).getLines());
sign.setLocation(state.getLocation());
snapshot[x][y][z] = sign;
} else if (state instanceof CreatureSpawner) {
BlockMobSpawner spawner = new BlockMobSpawner(((CreatureSpawner) state).getSpawnedType());
spawner.setLocation(state.getLocation());
spawner.setDelay(((CreatureSpawner) state).getDelay());
snapshot[x][y][z] = spawner;
} else if ((state instanceof InventoryHolder) && !(state instanceof Player)) {
BlockInventoryHolder holder = new BlockInventoryHolder(BukkitTools.getTypeId(state), BukkitTools.getDataData(state), ((InventoryHolder) state).getInventory().getContents());
holder.setLocation(state.getLocation());
snapshot[x][y][z] = holder;
} else {
snapshot[x][y][z] = new BlockObject(BukkitTools.getTypeId(state), BukkitTools.getDataData(state), state.getLocation());
}
}
}
}
TownyUniverse.getDataSource().getResident(player.getName()).addUndo(snapshot);
Bukkit.getWorld(player.getWorld().getName()).regenerateChunk(coord.getX(), coord.getZ());
} catch (NotRegisteredException e) {
// Failed to get resident
}
}
use of org.bukkit.block.CreatureSpawner in project Essentials by drtshock.
the class Commandspawner method run.
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
if (args.length < 1 || args[0].length() < 2) {
throw new NotEnoughArgumentsException(tl("mobsAvailable", StringUtil.joinList(Mob.getMobList())));
}
final Location target = LocationUtil.getTarget(user.getBase());
if (target == null || target.getBlock().getType() != Material.MOB_SPAWNER) {
throw new Exception(tl("mobSpawnTarget"));
}
String name = args[0];
int delay = 0;
Mob mob = null;
mob = Mob.fromName(name);
if (mob == null) {
throw new Exception(tl("invalidMob"));
}
if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH))) {
throw new Exception(tl("disabledToSpawnMob"));
}
if (!user.isAuthorized("essentials.spawner." + mob.name.toLowerCase(Locale.ENGLISH))) {
throw new Exception(tl("noPermToSpawnMob"));
}
if (args.length > 1) {
if (NumberUtil.isInt(args[1])) {
delay = Integer.parseInt(args[1]);
}
}
final Trade charge = new Trade("spawner-" + mob.name.toLowerCase(Locale.ENGLISH), ess);
charge.isAffordableFor(user);
try {
CreatureSpawner spawner = (CreatureSpawner) target.getBlock().getState();
spawner.setSpawnedType(mob.getType());
spawner.setDelay(delay);
spawner.update();
} catch (Throwable ex) {
throw new Exception(tl("mobSpawnError"), ex);
}
charge.charge(user);
user.sendMessage(tl("setSpawner", mob.name));
}
Aggregations