Search in sources :

Example 6 with CreatureSpawner

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();
}
Also used : BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Example 7 with CreatureSpawner

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);
}
Also used : BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) BlockState(org.bukkit.block.BlockState) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Example 8 with CreatureSpawner

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
    }
}
Also used : Player(org.bukkit.entity.Player) BlockInventoryHolder(com.palmergames.bukkit.towny.regen.block.BlockInventoryHolder) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) World(org.bukkit.World) Chunk(org.bukkit.Chunk) CreatureSpawner(org.bukkit.block.CreatureSpawner) WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) Coord(com.palmergames.bukkit.towny.object.Coord) BlockMobSpawner(com.palmergames.bukkit.towny.regen.block.BlockMobSpawner) BlockState(org.bukkit.block.BlockState) BlockSign(com.palmergames.bukkit.towny.regen.block.BlockSign) BlockObject(com.palmergames.bukkit.towny.regen.block.BlockObject) Sign(org.bukkit.block.Sign) BlockSign(com.palmergames.bukkit.towny.regen.block.BlockSign) InventoryHolder(org.bukkit.inventory.InventoryHolder) BlockInventoryHolder(com.palmergames.bukkit.towny.regen.block.BlockInventoryHolder) BlockObject(com.palmergames.bukkit.towny.regen.block.BlockObject)

Example 9 with CreatureSpawner

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));
}
Also used : Mob(com.earth2me.essentials.Mob) Trade(com.earth2me.essentials.Trade) Location(org.bukkit.Location) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Aggregations

CreatureSpawner (org.bukkit.block.CreatureSpawner)9 BlockState (org.bukkit.block.BlockState)5 Sign (org.bukkit.block.Sign)4 Block (org.bukkit.block.Block)2 CommandBlock (org.bukkit.block.CommandBlock)2 Skull (org.bukkit.block.Skull)2 Player (org.bukkit.entity.Player)2 InventoryHolder (org.bukkit.inventory.InventoryHolder)2 BlockStateMeta (org.bukkit.inventory.meta.BlockStateMeta)2 Mob (com.earth2me.essentials.Mob)1 Trade (com.earth2me.essentials.Trade)1 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)1 Coord (com.palmergames.bukkit.towny.object.Coord)1 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)1 BlockInventoryHolder (com.palmergames.bukkit.towny.regen.block.BlockInventoryHolder)1 BlockMobSpawner (com.palmergames.bukkit.towny.regen.block.BlockMobSpawner)1 BlockObject (com.palmergames.bukkit.towny.regen.block.BlockObject)1 BlockSign (com.palmergames.bukkit.towny.regen.block.BlockSign)1 ChangeResult (me.botsko.prism.appliers.ChangeResult)1 BlockStateChange (me.botsko.prism.events.BlockStateChange)1