org.bukkit.block.CreatureSpawner Java Examples

The following examples show how to use org.bukkit.block.CreatureSpawner. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayerListener.java    From Carbon with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
   public void onPlayerInteractMobSpawner(PlayerInteractEvent evt) {
       if (plugin.getConfig().getBoolean("features.monsterEggMobSpawner", true)) {
           if (evt.getAction() == Action.RIGHT_CLICK_BLOCK) {
               if (evt.getPlayer().getItemInHand().getType() == Material.MONSTER_EGG && evt.getClickedBlock().getType() == Material.MOB_SPAWNER) {
                   ItemStack egg = evt.getPlayer().getItemInHand();
                   CreatureSpawner cs = (CreatureSpawner) evt.getClickedBlock().getState();
                   cs.setSpawnedType(EntityType.fromId(egg.getData().getData()));
                   cs.update(true);
                   evt.setUseItemInHand(Event.Result.DENY);
                   evt.setCancelled(true);
               }
           }
       }
   }
 
Example #2
Source File: PickaxeOfContainment.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private ItemStack breakSpawner(Block b) {
    // If the spawner's BlockStorage has BlockInfo, then it's not a vanilla spawner and
    // should not give a broken spawner.
    ItemStack spawner = SlimefunItems.BROKEN_SPAWNER.clone();

    if (BlockStorage.hasBlockInfo(b)) {
        spawner = SlimefunItems.REPAIRED_SPAWNER.clone();
    }

    ItemMeta im = spawner.getItemMeta();
    List<String> lore = im.getLore();

    for (int i = 0; i < lore.size(); i++) {
        if (lore.get(i).contains("<Type>")) {
            lore.set(i, lore.get(i).replace("<Type>", ChatUtils.humanize(((CreatureSpawner) b.getState()).getSpawnedType().toString())));
        }
    }

    im.setLore(lore);
    spawner.setItemMeta(im);
    return spawner;
}
 
Example #3
Source File: BlockPlacer.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private void placeSlimefunBlock(SlimefunItem sfItem, ItemStack item, Block block, Dispenser dispenser) {
    block.setType(item.getType());
    BlockStorage.store(block, sfItem.getID());
    block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, item.getType());

    if (item.getType() == Material.SPAWNER && sfItem instanceof RepairedSpawner) {
        Optional<EntityType> entity = ((RepairedSpawner) sfItem).getEntityType(item);

        if (entity.isPresent()) {
            CreatureSpawner spawner = (CreatureSpawner) block.getState();
            spawner.setSpawnedType(entity.get());
            spawner.update(true, false);
        }
    }

    if (dispenser.getInventory().containsAtLeast(item, 2)) {
        dispenser.getInventory().removeItem(new CustomItem(item, 1));
    }
    else {
        Slimefun.runSync(() -> dispenser.getInventory().removeItem(item), 2L);
    }
}
 
Example #4
Source File: RepairedSpawner.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public BlockPlaceHandler getItemHandler() {
    return (p, e, item) -> {
        // We need to explicitly ignore the lore here
        if (SlimefunUtils.isItemSimilar(item, SlimefunItems.REPAIRED_SPAWNER, false, false)) {
            Optional<EntityType> entity = getEntityType(item);

            if (entity.isPresent()) {
                CreatureSpawner spawner = (CreatureSpawner) e.getBlock().getState();
                spawner.setSpawnedType(entity.get());
                spawner.update(true, false);
            }

            return true;
        }
        else {
            return false;
        }
    };
}
 
Example #5
Source File: WorthListener.java    From factions-top with MIT License 6 votes vote down vote up
@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);
}
 
Example #6
Source File: WorthManager.java    From factions-top with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: SpawnerSpawnListener.java    From IridiumSkyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler
public void onSpawnerSpawn(SpawnerSpawnEvent event) {
    try {
        final Location location = event.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        final Island island = islandManager.getIslandViaLocation(location);
        if (island == null) return;

        if (island.getSpawnerBooster() == 0) return;

        final IridiumSkyblock plugin = IridiumSkyblock.getInstance();
        final CreatureSpawner spawner = event.getSpawner();
        Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> spawner.setDelay(spawner.getDelay() / 2), 0);
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example #8
Source File: ExprSpawnerType.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) {
	for (Block b : getExpr().getArray(e)) {
		if (b.getType() != MATERIAL_SPAWNER)
			continue;
		CreatureSpawner s = (CreatureSpawner) b.getState();
		switch (mode) {
			case SET:
				s.setSpawnedType(toBukkitEntityType((EntityData) delta[0]));
				break;
			case RESET:
				s.setSpawnedType(org.bukkit.entity.EntityType.PIG);
				break;
		}
		s.update(); // Actually trigger the spawner's update 
	}
}
 
Example #9
Source File: ExprSpawnerType.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public EntityData convert(final Block b) {
	if (b.getType() != MATERIAL_SPAWNER)
		return null;
	return toSkriptEntityData(((CreatureSpawner) b.getState()).getSpawnedType());
}
 
Example #10
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets spawners to their type
 * @param e - event
 */
@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
                }
            }
        }
    }
}
 
Example #11
Source File: EpicSpawnersHook.java    From factions-top with MIT License 5 votes vote down vote up
@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));
}
 
Example #12
Source File: EpicSpawnersHook.java    From factions-top with MIT License 5 votes vote down vote up
@Override
public int getStackSize(CreatureSpawner spawner) {
    if (api == null) {
        return 1;
    }

    return api.getSpawnerMultiplier(spawner.getLocation());
}
 
Example #13
Source File: Island.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public void initBlocks() {
    updating = true;

    final Config config = IridiumSkyblock.getConfiguration();
    final IridiumSkyblock plugin = IridiumSkyblock.getInstance();
    final BukkitScheduler scheduler = Bukkit.getScheduler();
    final Runnable task = new InitIslandBlocksRunnable(this, config.blocksPerTick, () -> {
        if (IridiumSkyblock.blockspertick != -1) {
            config.blocksPerTick = IridiumSkyblock.blockspertick;
            IridiumSkyblock.blockspertick = -1;
        }
        scheduler.cancelTask(initBlocks);
        initBlocks = -1;
        plugin.updatingBlocks = false;
        updating = false;
        valuableBlocks.clear();
        spawners.clear();
        for (Location location : tempValues) {
            final Block block = location.getBlock();
            if (!(Utils.isBlockValuable(block) || !(block.getState() instanceof CreatureSpawner))) continue;
            final Material material = block.getType();
            final XMaterial xmaterial = XMaterial.matchXMaterial(material);
            valuableBlocks.compute(xmaterial.name(), (xmaterialName, original) -> {
                if (original == null) return 1;
                return original + 1;
            });
        }
        tempValues.clear();
        calculateIslandValue();
    });
    initBlocks = scheduler.scheduleSyncRepeatingTask(plugin, task, 0, 1);
}
 
Example #14
Source File: SpawnerPlaceListener.java    From MineableSpawners with MIT License 5 votes vote down vote up
private void handlePlacement(Player player, Block block, EntityType type, double cost) {
    CreatureSpawner spawner = (CreatureSpawner) block.getState();
    spawner.setSpawnedType(type);
    spawner.update();

    if (plugin.getConfigurationHandler().getBoolean("placing", "log")) {
        Location loc = block.getLocation();
        System.out.println("[MineableSpawners] Player " + player.getName() + " placed a " + type.name().toLowerCase() + " spawner at x:" + loc.getX() + ", y:" + loc.getY() + ", z:" + loc.getZ() + " (" + loc.getWorld().getName() + ")");
    }

    if (cost > 0) {
        player.sendMessage(plugin.getConfigurationHandler().getMessage("placing", "transaction-success").replace("%type%", Chat.uppercaseStartingLetters(type.name())).replace("%cost%", df.format(cost).replace("%balance%", df.format(plugin.getEcon().getBalance(player)))));
    }
}
 
Example #15
Source File: Island.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public void forceInitBlocks(CommandSender sender, int blocksPerTick, String name) {
    final Config config = IridiumSkyblock.getConfiguration();
    final Messages messages = IridiumSkyblock.getMessages();
    if (sender != null)
        sender.sendMessage(Utils.color(messages.updateStarted
                .replace("%player%", name)
                .replace("%prefix%", config.prefix)));
    updating = true;
    final IridiumSkyblock plugin = IridiumSkyblock.getInstance();
    final BukkitScheduler scheduler = Bukkit.getScheduler();
    final Runnable task = new InitIslandBlocksWithSenderRunnable(this, blocksPerTick, sender, name, () -> {
        if (sender != null)
            sender.sendMessage(Utils.color(messages.updateFinished
                    .replace("%player%", name)
                    .replace("%prefix%", config.prefix)));
        scheduler.cancelTask(initBlocks);
        initBlocks = -1;
        updating = false;
        valuableBlocks.clear();
        spawners.clear();
        for (Location location : tempValues) {
            final Block block = location.getBlock();
            if (!(Utils.isBlockValuable(block) || !(block.getState() instanceof CreatureSpawner))) continue;
            final Material material = block.getType();
            final XMaterial xmaterial = XMaterial.matchXMaterial(material);
            valuableBlocks.compute(xmaterial.name(), (xmaterialName, original) -> {
                if (original == null) return 1;
                return original + 1;
            });
        }
        tempValues.clear();
        calculateIslandValue();
    });
    initBlocks = scheduler.scheduleSyncRepeatingTask(plugin, task, 0, 1);
}
 
Example #16
Source File: InitIslandBlocksIterator.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Long next() {
    if (currentX < islandMaxX) {
        currentX++;
    } else if (currentZ < islandMaxZ) {
        currentX = islandMinX;
        currentZ++;
    } else if (currentY < maxWorldHeight) {
        currentX = islandMinX;
        currentZ = islandMinZ;
        currentY++;
    } else if (config.netherIslands && currentWorld.getName().equals(config.worldName)) {
        currentWorld = islandManager.getNetherWorld();
        currentX = islandMinX;
        currentY = 0;
        currentZ = islandMinZ;
    } else {
        throw new NoSuchElementException();
    }

    if (plugin.updatingBlocks) {
        final Location location = new Location(currentWorld, currentX, currentY, currentZ);
        final Block block = location.getBlock();
        if (Utils.isBlockValuable(block) && !(block.getState() instanceof CreatureSpawner))
            island.tempValues.add(location);
    }

    return currentBlock++;
}
 
Example #17
Source File: EntityExplodeListener.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMonitorEntityExplode(EntityExplodeEvent event) {
    try {
        final Entity entity = event.getEntity();
        final Location location = entity.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        if (!islandManager.isIslandWorld(location)) return;

        final UUID uuid = entity.getUniqueId();
        final IridiumSkyblock plugin = IridiumSkyblock.getInstance();
        final Map<UUID, Island> entities = plugin.entities;
        Island island = entities.get(uuid);
        if (island != null && island.isInIsland(location)) {
            event.setCancelled(true);
            entity.remove();
            entities.remove(uuid);
            return;
        }

        island = islandManager.getIslandViaLocation(location);
        if (island == null) return;

        for (Block block : event.blockList()) {
            if (!island.isInIsland(block.getLocation())) {
                final BlockState state = block.getState();
                IridiumSkyblock.nms.setBlockFast(block, 0, (byte) 0);
                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> state.update(true, true));
            }

            if (!Utils.isBlockValuable(block)) continue;

            if (!(block.getState() instanceof CreatureSpawner)) {
                final Material material = block.getType();
                final XMaterial xmaterial = XMaterial.matchXMaterial(material);
                island.valuableBlocks.computeIfPresent(xmaterial.name(), (name, original) -> original - 1);
            }

            if (island.updating)
                island.tempValues.remove(block.getLocation());
        }
        island.calculateIslandValue();
    } catch (Exception ex) {
        IridiumSkyblock.getInstance().sendErrorMessage(ex);
    }
}
 
Example #18
Source File: AdvancedSpawners.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
public static int getSpawnerAmount(CreatureSpawner spawner) {
    return ASAPI.getSpawnerAmount(spawner.getBlock());
}
 
Example #19
Source File: IslandBlock.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
    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(true, false);
    } else if (banner != null) {
        banner.set(block);
    } else if (skull != null){
        skull.set(block);
    } else if (pot != null){
        pot.set(nms, block);
    } else if (spawnerBlockType != null) {
        if (block.getTypeId() != typeId) {
            block.setTypeId(typeId);
        }
        CreatureSpawner cs = (CreatureSpawner)block.getState();
        cs.setSpawnedType(spawnerBlockType);
        //Bukkit.getLogger().info("DEBUG: setting spawner");
        cs.update(true, false);
    } else if (!chestContents.isEmpty()) {
        if (block.getTypeId() != typeId) {
            block.setTypeId(typeId);
        }
        //Bukkit.getLogger().info("DEBUG: inventory holder "+ block.getType());
        // Check if this is a double chest
        
        InventoryHolder chestBlock = (InventoryHolder) block.getState();
        //InventoryHolder iH = chestBlock.getInventory().getHolder();
        if (chestBlock instanceof DoubleChest) {
            //Bukkit.getLogger().info("DEBUG: double chest");
            DoubleChest doubleChest = (DoubleChest) chestBlock;
            for (ItemStack chestItem: chestContents.values()) {
                doubleChest.getInventory().addItem(chestItem);
            }
        } else {
            // Single chest
            for (Entry<Byte, ItemStack> en : chestContents.entrySet()) {
                //Bukkit.getLogger().info("DEBUG: " + en.getKey() + ","  + en.getValue());
                chestBlock.getInventory().setItem(en.getKey(), en.getValue());
            }
        }
    }
}
 
Example #20
Source File: UltimateStacker.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
public static int getSpawnerAmount(CreatureSpawner spawner) {
    return com.songoda.ultimatestacker.UltimateStacker.getInstance().getSpawnerStackManager().getSpawner(spawner.getBlock()).getAmount();
}
 
Example #21
Source File: MergedSpawners.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
public static int getSpawnerAmount(CreatureSpawner spawner) {
    return MergedSpawnerAPI.getInstance().getCountFor(spawner.getBlock());
}
 
Example #22
Source File: Wildstacker.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
public static int getSpawnerAmount(CreatureSpawner spawner) {
    return WildStackerAPI.getSpawnersAmount(spawner);
}
 
Example #23
Source File: EpicSpawners.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
public static int getSpawnerAmount(CreatureSpawner spawner) {
    return com.songoda.epicspawners.EpicSpawners.getInstance().getSpawnerManager().getSpawnerFromWorld(spawner.getLocation()).getSpawnCount();
}
 
Example #24
Source File: WorthListener.java    From factions-top with MIT License 4 votes vote down vote up
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);
}
 
Example #25
Source File: Craftbukkit18R3.java    From factions-top with MIT License 4 votes vote down vote up
@Override
public EntityType getSpawnerType(ItemStack item) {
    BlockStateMeta bsm = (BlockStateMeta) item.getItemMeta();
    CreatureSpawner bs = (CreatureSpawner) bsm.getBlockState();
    return bs.getSpawnedType();
}
 
Example #26
Source File: EggChangeListener.java    From MineableSpawners with MIT License 4 votes vote down vote up
@EventHandler
public void onEggChange(PlayerInteractEvent e) {
    if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
        return;
    }

    Player player = e.getPlayer();
    ItemStack itemInHand = e.getItem();

    if (itemInHand == null || itemInHand.getType().equals(Material.AIR)) {
        return;
    }

    String itemName = itemInHand.getType().name();
    Material targetBlock = e.getClickedBlock().getType();

    if (targetBlock != XMaterial.SPAWNER.parseMaterial() || !itemName.contains("SPAWN_EGG")) {
        return;
    }

    if (plugin.getConfigurationHandler().getList("eggs", "blacklisted-worlds").contains(player.getWorld().getName())) {
        e.setCancelled(true);
        player.sendMessage(plugin.getConfigurationHandler().getMessage("eggs", "blacklisted"));
        return;
    }

    if (plugin.getConfigurationHandler().getBoolean("eggs", "require-permission")) {
        if (!player.hasPermission("mineablespawners.eggchange")) {
            e.setCancelled(true);
            player.sendMessage(plugin.getConfigurationHandler().getMessage("eggs", "no-permission"));
            return;
        }
    }

    String to = itemName.split("_SPAWN_EGG")[0].replace("_", " ").toLowerCase();

    if (plugin.getConfigurationHandler().getBoolean("eggs", "require-individual-permission")) {
        if (!player.hasPermission("mineablespawners.eggchange." + to.replace(" ", "_"))) {
            e.setCancelled(true);
            player.sendMessage(plugin.getConfigurationHandler().getMessage("eggs", "no-individual-permission"));
            return;
        }
    }

    CreatureSpawner spawner = (CreatureSpawner) e.getClickedBlock().getState();
    String from = spawner.getSpawnedType().toString().replace("_", " ").toLowerCase();

    if (from.equals(to)) {
        e.setCancelled(true);
        player.sendMessage(plugin.getConfigurationHandler().getMessage("eggs", "already-type"));
        return;
    }

    player.sendMessage(plugin.getConfigurationHandler().getMessage("eggs", "success").replace("%from%", from).replace("%to%", to));
}
 
Example #27
Source File: Utils.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
public static boolean isBlockValuable(Block b) {
    return IridiumSkyblock.getBlockValues().blockvalue.containsKey(XMaterial.matchXMaterial(b.getType())) || b.getState() instanceof CreatureSpawner || IridiumSkyblock.getConfiguration().limitedBlocks.containsKey(XMaterial.matchXMaterial(b.getType()));
}
 
Example #28
Source File: SpawnerMultiplierChangeEvent.java    From factions-top with MIT License 4 votes vote down vote up
public CreatureSpawner getSpawner() {
    return spawner;
}
 
Example #29
Source File: SpawnerMultiplierChangeEvent.java    From factions-top with MIT License 4 votes vote down vote up
public SpawnerMultiplierChangeEvent(CreatureSpawner spawner, int oldMultiplier, int newMultiplier) {
    super(spawner.getBlock());
    this.spawner = spawner;
    this.oldMultiplier = oldMultiplier;
    this.newMultiplier = newMultiplier;
}
 
Example #30
Source File: VanillaSpawnerStackerHook.java    From factions-top with MIT License 4 votes vote down vote up
@Override
public int getStackSize(CreatureSpawner spawner) {
    return 1;
}