Java Code Examples for org.bukkit.block.CreatureSpawner#update()
The following examples show how to use
org.bukkit.block.CreatureSpawner#update() .
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: ExprSpawnerType.java From Skript with GNU General Public License v3.0 | 6 votes |
@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 2
Source File: RepairedSpawner.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@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 3
Source File: BlockPlacer.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
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: PlayerListener.java From Carbon with GNU Lesser General Public License v3.0 | 6 votes |
@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 5
Source File: SpawnerPlaceListener.java From MineableSpawners with MIT License | 5 votes |
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 6
Source File: SetSubCommand.java From MineableSpawners with MIT License | 4 votes |
public void execute(MineableSpawners plugin, CommandSender sender, String type) { if (!(sender instanceof Player)) { System.out.println("[MineableSpawners] Only players can run this command!"); return; } Player player = (Player) sender; if (plugin.getConfigurationHandler().getList("set", "blacklisted-worlds").contains(player.getWorld().getName())) { player.sendMessage(plugin.getConfigurationHandler().getMessage("set", "blacklisted")); return; } EntityType entityType; try { entityType = EntityType.valueOf(type.toUpperCase()); } catch (IllegalArgumentException e) { player.sendMessage(plugin.getConfigurationHandler().getMessage("set", "invalid-type")); return; } if (plugin.getConfigurationHandler().getBoolean("set", "require-individual-permission")) { if (!player.hasPermission("mineablespawners.set." + type.toLowerCase())) { player.sendMessage(plugin.getConfigurationHandler().getMessage("set", "no-individual-permission")); return; } } Block target = player.getTargetBlock(invisibleBlocks, 5); if (target.getState().getBlock().getType() != XMaterial.SPAWNER.parseMaterial()) { player.sendMessage(plugin.getConfigurationHandler().getMessage("set", "not-looking-at")); return; } CreatureSpawner spawner = (CreatureSpawner) target.getState(); String from = Chat.uppercaseStartingLetters(spawner.getSpawnedType().name()); String to = Chat.uppercaseStartingLetters(type); if (from.equals(to)) { player.sendMessage(plugin.getConfigurationHandler().getMessage("set", "already-type")); return; } spawner.setSpawnedType(entityType); spawner.update(); player.sendMessage(plugin.getConfigurationHandler().getMessage("set", "success").replace("%from%", from).replace("%to%", to)); }
Example 7
Source File: IslandBlock.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * 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()); } } } }