Solved Protect blaze spawners

Discussion in 'Plugin Development' started by Zeluboba, May 31, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Zeluboba

    Hi all,

    my code, that must protect blaze spawners, does not work. Anyone can help me to fix this? I think i do everything right.

    Code:
    @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
    public void onBlockBreak(BlockBreakEvent event) {
        if (event.getBlock().equals(Block.MOB_SPAWNER)) {
            CraftCreatureSpawner mobblock = new CraftCreatureSpawner(event.getBlock());
            if ((mobblock.getSpawnedType() == EntityType.BLAZE) && (!event.getPlayer().hasPermission("blazeprotect.exempt"))) {
                event.getPlayer().sendMessage(ChatColor.RED + getConfig().getString("message"));
                event.setCancelled(true);
            }
        }
    }
     
  2. Offline

    Minecrell

    Zeluboba I don't know if this is the problem, but can't you use the Bukkit API for that?:
    Code:java
    1. @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
    2. public void onBlockBreak(BlockBreakEvent event) {
    3. if (event.getBlock().getType() == Material.MOB_SPAWNER) {
    4. CreatureSpawner spawner = (CreatureSpawner) event.getBlock().getState();
    5.  
    6. if ((spawner.getSpawnedType() == EntityType.BLAZE) && (!event.getPlayer().hasPermission("blazeprotect.exempt"))) {
    7. event.getPlayer().sendMessage(ChatColor.RED + getConfig().getString("message"));
    8. event.setCancelled(true);
    9. }
    10. }
    11. }
     
  3. Offline

    Zeluboba

    Haha, i thought i've used it oO okay, thx, i'll try to use this code.
     
Thread Status:
Not open for further replies.

Share This Page