Java 类org.bukkit.block.CreatureSpawner 实例源码

项目:SuperiorCraft    文件:Slab.java   
@Override
public boolean placeBlock(ArmorStand e, Player p) {
    getTexture().placeBlock(e.getLocation().add(0, -0.40, -0.375));
    //p.sendMessage(e.getLocation().getBlock().getLocation().toString());

    if (getMaterial().equals(Material.MOB_SPAWNER)) {
        CreatureSpawner cs = (CreatureSpawner) e.getLocation().getBlock().getState();
        cs.setSpawnedType(EntityType.DROPPED_ITEM);
        cs.update();
    }
    setLe(e);
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SuperiorCraft.plugin, new Runnable() {
        public void run() {
            e.getLocation().getBlock().setType(Material.STONE_SLAB2);
            e.getLocation().getBlock().setData((byte) 2);
            e.getLocation().getBlock().getWorld().dropItemNaturally(e.getLocation(), new ItemStack(e.getLocation().add(0, -1, 0).getBlock().getType()));
            e.getLocation().add(0, -1, 0).getBlock().setType(Material.GLOWSTONE);
        }
    }, (1 * 20));
    return true;
}
项目:NeverLag    文件:AutoCleanIllegalTypeSpawner.java   
private void autoClean(Chunk chunk) {
    if (chunk == null) {
        return;
    }
    for (BlockState tiles : chunk.getTileEntities()) {
        if (tiles instanceof CreatureSpawner) {
            CreatureSpawner spawner = (CreatureSpawner) tiles;
            // 非法类型检测
            if (cm.illegalSpawnerType.contains(spawner.getCreatureTypeName().toLowerCase())) {
                switch (cm.illegalTypeSpawnerCleanMode) {
                case 0:
                    spawner.getBlock().setType(Material.AIR);
                    break;
                case 1:
                    spawner.setCreatureType(RND_ENTITYTYPE[(int) (Math.random() * RND_ENTITYTYPE.length)]);
                    break;
                default:
                    break;
                }
            }
        }
    }
}
项目:HCFCore    文件:CrowbarListener.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) {
    Block block = event.getBlockPlaced();
    ItemStack stack = event.getItemInHand();
    Player player = event.getPlayer();
    if (block.getState() instanceof CreatureSpawner && stack.hasItemMeta()) {
        ItemMeta meta = stack.getItemMeta();

        if (meta.hasLore() && meta.hasDisplayName()) {
            CreatureSpawner spawner = (CreatureSpawner) block.getState();
            List<String> lore = meta.getLore();
            if (!lore.isEmpty()) {
                String spawnerName = ChatColor.stripColor(lore.get(0).toUpperCase());
                Optional<EntityType> entityTypeOptional = GuavaCompat.getIfPresent(EntityType.class, spawnerName);
                if (entityTypeOptional.isPresent()) {
                    spawner.setSpawnedType(entityTypeOptional.get());
                    spawner.update(true, true);
                    player.sendMessage(ChatColor.AQUA + "Placed a " + ChatColor.BLUE + spawnerName + ChatColor.AQUA + " spawner.");
                }
            }
        }
    }
}
项目:HCFCore    文件:CrowbarListener.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) {
    Block block = event.getBlockPlaced();
    ItemStack stack = event.getItemInHand();
    Player player = event.getPlayer();
    if (block.getState() instanceof CreatureSpawner && stack.hasItemMeta()) {
        ItemMeta meta = stack.getItemMeta();

        if (meta.hasLore() && meta.hasDisplayName()) {
            CreatureSpawner spawner = (CreatureSpawner) block.getState();
            List<String> lore = meta.getLore();
            if (!lore.isEmpty()) {
                String spawnerName = ChatColor.stripColor(lore.get(0).toUpperCase());
                Optional<EntityType> entityTypeOptional = GuavaCompat.getIfPresent(EntityType.class, spawnerName);
                if (entityTypeOptional.isPresent()) {
                    spawner.setSpawnedType(entityTypeOptional.get());
                    spawner.update(true, true);
                    player.sendMessage(ChatColor.AQUA + "Placed a " + ChatColor.BLUE + spawnerName + ChatColor.AQUA + " spawner.");
                }
            }
        }
    }
}
项目:SuperiorCraft    文件:Slab.java   
@Override
public boolean placeBlock(ArmorStand e, Player p) {
    getTexture().placeBlock(e.getLocation().add(0, -0.40, -0.375));
    //p.sendMessage(e.getLocation().getBlock().getLocation().toString());

    if (getMaterial().equals(Material.MOB_SPAWNER)) {
        CreatureSpawner cs = (CreatureSpawner) e.getLocation().getBlock().getState();
        cs.setSpawnedType(EntityType.DROPPED_ITEM);
        cs.update();
    }
    setLe(e);
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SuperiorCraft.plugin, new Runnable() {
        public void run() {
            e.getLocation().getBlock().setType(Material.STONE_SLAB2);
            e.getLocation().getBlock().setData((byte) 2);
            e.getLocation().getBlock().getWorld().dropItemNaturally(e.getLocation(), new ItemStack(e.getLocation().add(0, -1, 0).getBlock().getType()));
            e.getLocation().add(0, -1, 0).getBlock().setType(Material.GLOWSTONE);
        }
    }, (1 * 20));
    return true;
}
项目:factions-top    文件:WorthManager.java   
/**
 * Calculates the spawner worth of a chunk.
 *
 * @param chunk    the chunk.
 * @param spawners the spawner totals to add to.
 * @return the chunk worth in spawners.
 */
private double getSpawnerWorth(Chunk chunk, Map<EntityType, Integer> spawners) {
    int count;
    double worth = 0;

    for (BlockState blockState : chunk.getTileEntities()) {
        if (!(blockState instanceof CreatureSpawner)) {
            continue;
        }

        CreatureSpawner spawner = (CreatureSpawner) blockState;
        EntityType spawnType = spawner.getSpawnedType();
        int stackSize = plugin.getSpawnerStackerHook().getStackSize(spawner);
        double blockPrice = plugin.getSettings().getSpawnerPrice(spawnType) * stackSize;
        worth += blockPrice;

        if (blockPrice != 0) {
            count = spawners.getOrDefault(spawnType, 0);
            spawners.put(spawnType, count + stackSize);
        }
    }

    return worth;
}
项目:factions-top    文件:WorthListener.java   
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void updateWorth(SpawnerMultiplierChangeEvent event) {
    // Do nothing if this area should not be calculated.
    Block block = event.getBlock();
    String factionId = plugin.getFactionsHook().getFactionAt(block);
    if (plugin.getSettings().getIgnoredFactionIds().contains(factionId)) {
        return;
    }

    // Get the worth type and price of this event.
    int difference = event.getNewMultiplier() - event.getOldMultiplier();
    WorthType worthType = WorthType.SPAWNER;
    Map<Material, Integer> materials = new HashMap<>();
    Map<EntityType, Integer> spawners = new HashMap<>();

    EntityType spawnType = ((CreatureSpawner) block.getState()).getSpawnedType();
    double price = difference * plugin.getSettings().getSpawnerPrice(spawnType);
    spawners.put(spawnType, difference);

    RecalculateReason reason = difference > 0 ? RecalculateReason.PLACE : RecalculateReason.BREAK;

    // Add block price to the count.
    plugin.getWorthManager().add(block.getChunk(), reason, worthType, price, materials, spawners);
}
项目:Skellett    文件:ExprSpawnerDelay.java   
@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode){
    if (spawner != null) {
        Number delay = (Number)delta[0];
        Number delayNow = ((CreatureSpawner)spawner.getSingle(e).getState()).getDelay();
        CreatureSpawner spawn = ((CreatureSpawner)spawner.getSingle(e).getState());
        if (mode == ChangeMode.SET) {
            spawn.setDelay(delay.intValue());
        } else if (mode == ChangeMode.ADD) {
            spawn.setDelay(delayNow.intValue() + delay.intValue());
        } else if (mode == ChangeMode.REMOVE) {
            spawn.setDelay(delayNow.intValue() - delay.intValue());
        }
        spawn.update();
    }
}
项目:libelula    文件:MapManager.java   
private void placeWoolSpawner(Location loc, String colorName) {
    Wool wool = new Wool(DyeColor.valueOf(colorName));
    final Block block = loc.getBlock();
    block.setType(Material.MOB_SPAWNER);
    final BlockState genericBlockState = block.getState();
    final CreatureSpawner cs = (CreatureSpawner) block.getState();
    final ItemStack stack = wool.toItemStack(1);
    Bukkit.getScheduler().runTask(plugin, new Runnable() {
        @Override
        public void run() {
            cs.setSpawnedType(block.getWorld().dropItem(block.getLocation(), stack).getType());
            genericBlockState.update();
        }
    });

}
项目:libelula    文件:MapManager.java   
private void placeWoolSpawner(Location loc, String colorName) {
    Wool wool = new Wool(DyeColor.valueOf(colorName));
    final Block block = loc.getBlock();
    block.setType(Material.MOB_SPAWNER);
    final BlockState genericBlockState = block.getState();
    final CreatureSpawner cs = (CreatureSpawner) block.getState();
    final ItemStack stack = wool.toItemStack(1);
    Bukkit.getScheduler().runTask(plugin, new Runnable() {
        @Override
        public void run() {
            cs.setSpawnedType(block.getWorld().dropItem(block.getLocation(), stack).getType());
            genericBlockState.update();
        }
    });

}
项目:SuperiorCraft    文件:CustomTexturedBlock.java   
@Override
public boolean placeBlock(ArmorStand e, Player p) {
    getTexture().placeBlock(e.getLocation().add(0, 0.125, -0.375));
    e.getLocation().getBlock().setType(getMaterial());
    if (getMaterial().equals(Material.MOB_SPAWNER)) {
        CreatureSpawner cs = (CreatureSpawner) e.getLocation().getBlock().getState();
        cs.setSpawnedType(EntityType.DROPPED_ITEM);
        cs.update();
    }
    setLe(e);
    return true;
}
项目:HCFCore    文件:CoreListener.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event) {
    Player player = event.getPlayer();
    if (player.getWorld().getEnvironment() == World.Environment.NETHER && event.getBlock().getState() instanceof CreatureSpawner
            && !player.hasPermission(ProtectionListener.PROTECTION_BYPASS_PERMISSION)) {

        event.setCancelled(true);
        player.sendMessage(ChatColor.RED + "You may not break spawners in the nether.");
    }
}
项目:HCFCore    文件:CoreListener.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event) {
    Player player = event.getPlayer();
    if (player.getWorld().getEnvironment() == World.Environment.NETHER && event.getBlock().getState() instanceof CreatureSpawner
            && !player.hasPermission(ProtectionListener.PROTECTION_BYPASS_PERMISSION)) {

        event.setCancelled(true);
        player.sendMessage(ChatColor.RED + "You may not place spawners in the nether.");
    }
}
项目:HCFCore    文件:CoreListener.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event) {
    Player player = event.getPlayer();
    if (player.getWorld().getEnvironment() == World.Environment.NETHER && event.getBlock().getState() instanceof CreatureSpawner
            && !player.hasPermission(ProtectionListener.PROTECTION_BYPASS_PERMISSION)) {

        event.setCancelled(true);
        player.sendMessage(ChatColor.RED + "You may not break spawners in the nether.");
    }
}
项目:HCFCore    文件:CoreListener.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event) {
    Player player = event.getPlayer();
    if (player.getWorld().getEnvironment() == World.Environment.NETHER && event.getBlock().getState() instanceof CreatureSpawner
            && !player.hasPermission(ProtectionListener.PROTECTION_BYPASS_PERMISSION)) {

        event.setCancelled(true);
        player.sendMessage(ChatColor.RED + "You may not place spawners in the nether.");
    }
}
项目:SuperiorCraft    文件:CustomTexturedBlock.java   
@Override
public boolean placeBlock(ArmorStand e, Player p) {
    getTexture().placeBlock(e.getLocation().add(0, 0.125, -0.375));
    e.getLocation().getBlock().setType(getMaterial());
    if (getMaterial().equals(Material.MOB_SPAWNER)) {
        CreatureSpawner cs = (CreatureSpawner) e.getLocation().getBlock().getState();
        cs.setSpawnedType(EntityType.DROPPED_ITEM);
        cs.update();
    }
    setLe(e);
    return true;
}
项目:factions-top    文件:EpicSpawnersHook.java   
@Override
public int getStackSize(CreatureSpawner spawner) {
    if (api == null) {
        return 1;
    }

    return api.getSpawnerMultiplier(spawner.getLocation());
}
项目:factions-top    文件:EpicSpawnersHook.java   
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void updateWorth(SpawnerChangeEvent event) {
    CreatureSpawner spawner = (CreatureSpawner) event.getSpawner().getState();
    int oldMultiplier = event.getOldMulti();
    int newMultiplier = event.getCurrentMulti();
    SpawnerMultiplierChangeEvent event1 = new SpawnerMultiplierChangeEvent(spawner, oldMultiplier, newMultiplier);

    if (plugin.getServer().isPrimaryThread()) {
        plugin.getServer().getPluginManager().callEvent(event1);
        return;
    }

    plugin.getServer().getScheduler().runTask(plugin, () ->
            plugin.getServer().getPluginManager().callEvent(event1));
}
项目:Skellett    文件:EffSpawnerForce.java   
@Override
protected void execute(Event e) {
    if (spawner != null) {
        int delay = ((CreatureSpawner)spawner.getSingle(e)).getDelay();
        CreatureSpawner state = (CreatureSpawner)spawner.getSingle(e).getState();
        state.setDelay(0);
        state.update();
        state.setDelay(delay);
        state.update();
    }
}
项目:Skellett    文件:ExprSpawnerType.java   
@SuppressWarnings("deprecation")
@Override
@Nullable
protected String[] get(Event e) {
    if (spawner != null) {
        return new String[]{((CreatureSpawner)spawner.getSingle(e).getState()).getCreatureTypeName()};
    }
    return null;
}
项目:Skellett    文件:ExprSpawnerType.java   
@SuppressWarnings("deprecation")
@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode){
    if (spawner != null) {
        CreatureSpawner spawn = ((CreatureSpawner)spawner.getSingle(e).getState());
        if (mode == ChangeMode.SET) {
            spawn.setCreatureTypeByName((String)delta[0]);
        }
        spawn.update();
    }
}
项目:Skellett    文件:ExprSpawnerDelay.java   
@Override
@Nullable
protected Number[] get(Event e) {
    if (spawner != null) {
        return new Number[]{((CreatureSpawner)spawner.getSingle(e).getState()).getDelay()};
    }
    return null;
}
项目:Steel    文件:BlockStateSerializer.java   
@SuppressWarnings("deprecation")
public static Optional<String> serializeState(BlockState state) {
    YamlConfiguration yaml = new YamlConfiguration();

    // http://minecraft.gamepedia.com/Block_entity was used as a reference for this method

    if (state instanceof InventoryHolder) {
        yaml.set(INVENTORY_KEY, InventoryHelper.serializeInventory(((InventoryHolder) state).getInventory()));
    }

    if (state instanceof Sign) {
        yaml.set(SIGN_LINES_KEY, Arrays.asList(((Sign) state).getLines()));
    } else if (Support.BANNER && state instanceof Banner) {
        yaml.set(BANNER_BASE_COLOR_KEY, ((Banner) state).getBaseColor().name());
        ConfigurationSection patternSection = yaml.createSection(BANNER_PATTERNS_KEY);
        List<Pattern> patterns = ((Banner) state).getPatterns();
        for (int i = 0; i < patterns.size(); i++) {
            ConfigurationSection subSection = patternSection.createSection("" + i);
            subSection.set(BANNER_PATTERN_COLOR_KEY, patterns.get(i).getColor().name());
            subSection.set(BANNER_PATTERN_TYPE_KEY, patterns.get(i).getPattern().name());
        }
    } else if (state instanceof CreatureSpawner) {
        yaml.set(SPAWNER_TYPE_KEY, ((CreatureSpawner) state).getSpawnedType().name());
        yaml.set(SPAWNER_DELAY_KEY, ((CreatureSpawner) state).getDelay());
    } else if (state instanceof NoteBlock) {
        yaml.set(NOTE_OCTAVE_KEY, ((NoteBlock) state).getNote().getOctave());
        yaml.set(NOTE_TONE_KEY, ((NoteBlock) state).getNote().getTone().name());
    } else if (state instanceof Jukebox) {
        if (((Jukebox) state).isPlaying()) {
            yaml.set(JUKEBOX_DISC_KEY, ((Jukebox) state).getPlaying());
        }
    } else if (state instanceof Skull) {
        yaml.set(SKULL_OWNER_KEY, ((Skull) state).getOwner());
        yaml.set(SKULL_ROTATION_KEY, ((Skull) state).getRotation().name());
    } else if (state instanceof CommandBlock) {
        yaml.set(COMMAND_NAME_KEY, ((CommandBlock) state).getName());
        yaml.set(COMMAND_CMD_KEY, ((CommandBlock) state).getCommand());
    } else if (state instanceof FlowerPot) {
        yaml.set(FLOWER_TYPE_KEY, ((FlowerPot) state).getContents().getItemType().name());
        yaml.set(FLOWER_DATA_KEY, ((FlowerPot) state).getContents().getData());
    }

    if (yaml.getKeys(false).size() > 0) {
        return Optional.of(yaml.saveToString());
    }
    return Optional.absent();
}
项目:askygrid    文件:SkyGridPop.java   
private void setSpawner(Block b, Random random) {
CreatureSpawner spawner = (CreatureSpawner) b.getState();
TreeMap<Integer,EntityType> spawns = WorldStyles.get(b.getWorld().getEnvironment()).getSpawns();
int randKey = random.nextInt(spawns.lastKey());
//Bukkit.getLogger().info("DEBUG: spawner rand key = " + randKey + " out of " + spawns.lastKey());
EntityType type = spawns.ceilingEntry(randKey).getValue();
//Bukkit.getLogger().info("DEBUG: spawner type = " + type);
spawner.setDelay(120);
spawner.setSpawnedType(type);
spawner.update(true);
   }
项目:Almura-Server    文件:CraftEventFactory.java   
/**
 * Mob spawner event
 */
public static SpawnerSpawnEvent callSpawnerSpawnEvent(Entity spawnee, int spawnerX, int spawnerY, int spawnerZ) {
    org.bukkit.craftbukkit.entity.CraftEntity entity = spawnee.getBukkitEntity();
    BlockState state = entity.getWorld().getBlockAt(spawnerX, spawnerY, spawnerZ).getState();

    if (!(state instanceof CreatureSpawner)) {
        state = null;
    }

    SpawnerSpawnEvent event = new SpawnerSpawnEvent(entity, (CreatureSpawner) state);
    entity.getServer().getPluginManager().callEvent(event);
    return event;
}
项目:acidisland    文件:IslandGuard.java   
/**
 * Sets spawners to their type
 * @param e
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSpawnerBlockPlace(final BlockPlaceEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: block place");
    if (inWorld(e.getPlayer()) && Util.playerIsHolding(e.getPlayer(), Material.MOB_SPAWNER)) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: in world");
        // Get item in hand
        for (ItemStack item : Util.getPlayerInHandItems(e.getPlayer())) {
            if (item.getType().equals(Material.MOB_SPAWNER) && item.hasItemMeta() && item.getItemMeta().hasLore()) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: spawner in hand with lore");
                List<String> lore = item.getItemMeta().getLore();
                if (!lore.isEmpty()) {
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: lore is not empty");
                    for (EntityType type : EntityType.values()) {
                        if (lore.get(0).equals(Util.prettifyText(type.name()))) {
                            // Found the spawner type
                            if (DEBUG)
                                plugin.getLogger().info("DEBUG: found type");
                            e.getBlock().setType(Material.MOB_SPAWNER);
                            CreatureSpawner cs = (CreatureSpawner)e.getBlock().getState();
                            cs.setSpawnedType(type);
                        }
                    }
                    // Spawner type not found - do anything : it may be another plugin's spawner
                }
            }
        }
    }
}
项目:Tweakkit-Server    文件:CraftEventFactory.java   
/**
 * Mob spawner event
 */
public static SpawnerSpawnEvent callSpawnerSpawnEvent(Entity spawnee, int spawnerX, int spawnerY, int spawnerZ) {
    org.bukkit.craftbukkit.entity.CraftEntity entity = spawnee.getBukkitEntity();
    BlockState state = entity.getWorld().getBlockAt(spawnerX, spawnerY, spawnerZ).getState();

    if (!(state instanceof CreatureSpawner)) {
        state = null;
    }

    SpawnerSpawnEvent event = new SpawnerSpawnEvent(entity, (CreatureSpawner) state);
    entity.getServer().getPluginManager().callEvent(event);
    return event;
}
项目:askyblock    文件:IslandGuard.java   
/**
 * Sets spawners to their type
 * @param e
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSpawnerBlockPlace(final BlockPlaceEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: block place");
    if (inWorld(e.getPlayer()) && Util.playerIsHolding(e.getPlayer(), Material.MOB_SPAWNER)) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: in world");
        // Get item in hand
        for (ItemStack item : Util.getPlayerInHandItems(e.getPlayer())) {
            if (item.getType().equals(Material.MOB_SPAWNER) && item.hasItemMeta() && item.getItemMeta().hasLore()) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: spawner in hand with lore");
                List<String> lore = item.getItemMeta().getLore();
                if (!lore.isEmpty()) {
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: lore is not empty");
                    for (EntityType type : EntityType.values()) {
                        if (lore.get(0).equals(Util.prettifyText(type.name()))) {
                            // Found the spawner type
                            if (DEBUG)
                                plugin.getLogger().info("DEBUG: found type");
                            e.getBlock().setType(Material.MOB_SPAWNER);
                            CreatureSpawner cs = (CreatureSpawner)e.getBlock().getState();
                            cs.setSpawnedType(type);
                        }
                    }
                    // Spawner type not found - do anything : it may be another plugin's spawner
                }
            }
        }
    }
}
项目:Necessities    文件:CmdSpawner.java   
public boolean commandUse(CommandSender sender, String[] args) {
    Variables var = Necessities.getVar();
    if (sender instanceof Player) {
        Player p = (Player) sender;
        User u = Necessities.getUM().getUser(p.getUniqueId());
        Location l = u.getLookingAt();
        if (l == null) {
            p.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "Block out of range.");
            return true;
        }
        if (l.getBlock().getState() instanceof CreatureSpawner) {
            CreatureSpawner spawner = (CreatureSpawner) l.getBlock().getState();
            if (args.length == 0) {
                p.sendMessage(var.getMessages() + "Spawner type is " + spawner.getSpawnedType().toString().replaceAll("_", " ").toLowerCase() + '.');
                return true;
            }
            EntityType spawnerType = getType(args[0]);
            if (spawnerType == null) {
                p.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "Invalid mob type.");
                p.sendMessage(var.getMessages() + "Valid mob types: " + ChatColor.WHITE + validTypes());
                return true;
            }
            spawner.setSpawnedType(spawnerType);
            spawner.update();
            p.sendMessage(var.getMessages() + "Spawner type set to " + var.getObj() + spawner.getSpawnedType().toString().replaceAll("_", " ").toLowerCase() + var.getMessages() + '.');
            return true;
        }
        sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "That block is not a spawner.");
        return true;
    } else
        sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You cannot change the type of spawner because you cannot look at the spawner.");
    return true;
}
项目:rftd    文件:BlockListener.java   
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
    if(controller.isStarting())
        e.setCancelled(true);
    else if(controller.isPlaying()
            && e.getBlock().getType() == Material.MOB_SPAWNER) {
        CreatureSpawner spawner = (CreatureSpawner) e.getBlock().getState();
        if(spawner.getSpawnedType() == EntityType.BLAZE)
            e.setCancelled(true);
    }
}
项目:Wayward    文件:SpawnerCommand.java   
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender.hasPermission("wayward.essentials.command.spawner")) {
        if (args.length >= 1) {
            if (sender instanceof Player) {
                Player player = (Player) sender;
                Block block = getTargetBlock(player);
                if (block.getType() == Material.MOB_SPAWNER) {
                    CreatureSpawner spawner = (CreatureSpawner) block.getState();
                    try {
                        EntityType entityType = EntityType.valueOf(args[0].toUpperCase());
                        spawner.setSpawnedType(entityType);
                        sender.sendMessage(plugin.getPrefix() + ChatColor.GREEN + "Spawner type set.");
                    } catch (IllegalArgumentException exception) {
                        sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "That entity does not exist.");
                    }
                } else {
                    sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "That's not a mob spawner.");
                }
            } else {
                sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "You must be a player to use this command.");
            }
        } else {
            sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "You must specify the mob type.");
        }
    } else {
        sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "You do not have permission.");
    }
    return true;
}
项目:tregmine    文件:SetSpawnerCommand.java   
@Override
public boolean handlePlayer(TregminePlayer player, String[] args)
{
    if (!player.getRank().canSetSpawners()) {
        return true;
    }

    if (args.length != 1) {
        player.sendMessage(RED + "Type /spawner <mobname> whilst pointing "
                + "at a spawner");
        return false;
    }

    Block target = player.getDelegate().getTargetBlock((Set<Material>) null, 15);
    if (!target.getType().equals(Material.MOB_SPAWNER)) {
        player.sendMessage(RED + "Please point at a spawner.");
        return false;
    }

    CreatureSpawner spawner = (CreatureSpawner) target.getState();
    try {
        spawner.setSpawnedType(EntityType.valueOf(args[0].toUpperCase()));
    } catch (Exception error) {
        player.sendMessage(RED
                + "An error occured. Did you specify a valid "
                + "mob type?");
    }

    return true;
}
项目:MausWasHere    文件:BlockListener.java   
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent e) {
    Block block = e.getBlockPlaced();
    ItemStack spawner = e.getItemInHand();
    if (spawner.getType().equals(Material.MOB_SPAWNER) && !e.isCancelled()) {
        if (spawner.getItemMeta().hasLore()) {
            if (spawner.getItemMeta().getLore().toString().contains("Spawner")) {
                CreatureSpawner placedSpawner = (CreatureSpawner) block.getState();
                if (spawner.getItemMeta().getLore().toString().contains("Pig")) {
                    placedSpawner.setSpawnedType(EntityType.PIG);
                } else if (spawner.getItemMeta().getLore().toString().contains("Skeleton")) {
                    placedSpawner.setSpawnedType(EntityType.SKELETON);
                } else if (spawner.getItemMeta().getLore().toString().contains("Spider")) {
                    placedSpawner.setSpawnedType(EntityType.SPIDER);
                } else if (spawner.getItemMeta().getLore().toString().contains("Zombie")) {
                    placedSpawner.setSpawnedType(EntityType.ZOMBIE);
                } else if (spawner.getItemMeta().getLore().toString().contains("Cave Spider")) {
                    placedSpawner.setSpawnedType(EntityType.CAVE_SPIDER);
                } else if (spawner.getItemMeta().getLore().toString().contains("Blaze")) {
                    placedSpawner.setSpawnedType(EntityType.BLAZE);
                } else if (spawner.getItemMeta().getLore().toString().contains("SilverFish")) {
                    placedSpawner.setSpawnedType(EntityType.SILVERFISH);
                }
                placedSpawner.update();
            }
        }
    }
}
项目:bskyblock    文件:IslandBlock.java   
/**
 * Paste this block at blockLoc
 * @param nms
 * @param blockLoc
 */
//@SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")
public void paste(NMSAbstraction nms, Location blockLoc, boolean usePhysics, Biome biome) {
    // Only paste air if it is below the sea level and in the overworld
    Block block = new Location(blockLoc.getWorld(), x, y, z).add(blockLoc).getBlock();
    block.setBiome(biome);
    block.getChunk().load();
    nms.setBlockSuperFast(block, typeId, data, usePhysics);
    if (signText != null) {
        if (block.getTypeId() != typeId) {
            block.setTypeId(typeId);
        }
        // Sign
        Sign sign = (Sign) block.getState();
        int index = 0;
        for (String line : signText) {
            sign.setLine(index++, line);
        }
        sign.update();
    } else if (banner != null) {
        banner.set(block);
    } else if (spawnerBlockType != null) {
        if (block.getTypeId() != typeId) {
            block.setTypeId(typeId);
        }
        CreatureSpawner cs = (CreatureSpawner)block.getState();
        cs.setSpawnedType(spawnerBlockType);
    } else if (!chestContents.isEmpty()) {
        if (block.getTypeId() != typeId) {
            block.setTypeId(typeId);
        }
        // Check if this is a double chest
        Chest chestBlock = (Chest) block.getState();
        InventoryHolder iH = chestBlock.getInventory().getHolder();
        if (iH instanceof DoubleChest) {
            //Bukkit.getLogger().info("DEBUG: double chest");
            DoubleChest doubleChest = (DoubleChest) iH;
            for (ItemStack chestItem: chestContents.values()) {
                doubleChest.getInventory().addItem(chestItem);
            }
        } else {
            // Single chest
            for (Entry<Byte, ItemStack> en : chestContents.entrySet()) {
                chestBlock.getInventory().setItem(en.getKey(), en.getValue());
            }
        }
    }
}
项目:KingdomFactions    文件:BlockPlace.java   
public void setSpawner(Block block, EntityType ent) {
    BlockState blockState = block.getState();
    CreatureSpawner spawner = ((CreatureSpawner) blockState);
    spawner.setSpawnedType(ent);
    blockState.update();
}
项目:factions-top    文件:VanillaSpawnerStackerHook.java   
@Override
public int getStackSize(CreatureSpawner spawner) {
    return 1;
}
项目:factions-top    文件:SpawnerMultiplierChangeEvent.java   
public SpawnerMultiplierChangeEvent(CreatureSpawner spawner, int oldMultiplier, int newMultiplier) {
    super(spawner.getBlock());
    this.spawner = spawner;
    this.oldMultiplier = oldMultiplier;
    this.newMultiplier = newMultiplier;
}
项目:factions-top    文件:SpawnerMultiplierChangeEvent.java   
public CreatureSpawner getSpawner() {
    return spawner;
}
项目:factions-top    文件:Craftbukkit18R3.java   
@Override
public EntityType getSpawnerType(ItemStack item) {
    BlockStateMeta bsm = (BlockStateMeta) item.getItemMeta();
    CreatureSpawner bs = (CreatureSpawner) bsm.getBlockState();
    return bs.getSpawnedType();
}
项目:factions-top    文件:WorthListener.java   
private void updateWorth(Block block, RecalculateReason reason, boolean negate) {
    // Do nothing if this area should not be calculated.
    String factionId = plugin.getFactionsHook().getFactionAt(block);
    if (plugin.getSettings().getIgnoredFactionIds().contains(factionId)) {
        return;
    }

    // Get the worth type and price of this event.
    int multiplier = negate ? -1 : 1;
    double price = multiplier * plugin.getSettings().getBlockPrice(block.getType());
    WorthType worthType = WorthType.BLOCK;
    Map<Material, Integer> materials = new HashMap<>();
    Map<EntityType, Integer> spawners = new HashMap<>();

    plugin.getWorthManager().add(block.getChunk(), reason, worthType, price,
            ImmutableMap.of(block.getType(), multiplier), spawners);

    switch (block.getType()) {
        case MOB_SPAWNER:
            worthType = WorthType.SPAWNER;
            CreatureSpawner spawner = (CreatureSpawner) block.getState();
            EntityType spawnedType = spawner.getSpawnedType();
            multiplier *= plugin.getSpawnerStackerHook().getStackSize(spawner);
            price = multiplier * plugin.getSettings().getSpawnerPrice(spawnedType);
            spawners.put(spawnedType, multiplier);
            break;
        case CHEST:
        case TRAPPED_CHEST:
            if (plugin.getSettings().isDisableChestEvents()) {
                return;
            }

            worthType = WorthType.CHEST;
            Chest chest = (Chest) block.getState();
            ChestWorth chestWorth = negate ? getWorthNegative(chest.getBlockInventory()) : getWorth(chest.getBlockInventory());
            price = chestWorth.getTotalWorth();
            materials.putAll(chestWorth.getMaterials());
            spawners.putAll(chestWorth.getSpawners());
            break;
        default:
            return;
    }

    // Add block price to the count.
    plugin.getWorthManager().add(block.getChunk(), reason, worthType, price, materials, spawners);
}