Java Code Examples for org.bukkit.block.Block#getDrops()
The following examples show how to use
org.bukkit.block.Block#getDrops() .
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: MinerAndroid.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Override protected void dig(Block b, BlockMenu menu, Block block) { Collection<ItemStack> drops = block.getDrops(effectivePickaxe); if (!MaterialCollections.getAllUnbreakableBlocks().contains(block.getType()) && !drops.isEmpty() && SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))), block.getLocation(), ProtectableAction.BREAK_BLOCK)) { AndroidMineEvent event = new AndroidMineEvent(block, new AndroidInstance(this, b)); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { return; } // We only want to break non-Slimefun blocks String blockId = BlockStorage.checkID(block); if (blockId == null) { for (ItemStack drop : drops) { if (menu.fits(drop, getOutputSlots())) { menu.pushItem(drop, getOutputSlots()); block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType()); block.setType(Material.AIR); } } } } }
Example 2
Source File: ExplosiveShovel.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Override protected void breakBlock(Player p, ItemStack item, Block b, int fortune, List<ItemStack> drops) { if (MaterialTools.getBreakableByShovel().contains(b.getType()) && SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.BREAK_BLOCK)) { SlimefunPlugin.getProtectionManager().logAction(p, b, ProtectableAction.BREAK_BLOCK); b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); for (ItemStack drop : b.getDrops(getItem())) { if (drop != null) { b.getWorld().dropItemNaturally(b.getLocation(), drop); } } b.setType(Material.AIR); damageItem(p, item); } }
Example 3
Source File: MinerAndroid.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Override protected void moveAndDig(Block b, BlockMenu menu, BlockFace face, Block block) { Collection<ItemStack> drops = block.getDrops(effectivePickaxe); if (!MaterialCollections.getAllUnbreakableBlocks().contains(block.getType()) && !drops.isEmpty() && SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))), block.getLocation(), ProtectableAction.BREAK_BLOCK)) { AndroidMineEvent event = new AndroidMineEvent(block, new AndroidInstance(this, b)); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { return; } // We only want to break non-Slimefun blocks SlimefunItem blockId = BlockStorage.check(block); if (blockId == null) { for (ItemStack drop : drops) { if (menu.fits(drop, getOutputSlots())) { menu.pushItem(drop, getOutputSlots()); block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType()); block.setType(Material.AIR); move(b, face, block); b.setType(Material.AIR); BlockStorage.moveBlockInfo(b.getLocation(), block.getLocation()); } } } } else { move(b, face, block); } }
Example 4
Source File: ExplosiveTool.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
protected void breakBlock(Player p, ItemStack item, Block b, int fortune, List<ItemStack> drops) { if (b.getType() != Material.AIR && !b.isLiquid() && !MaterialCollections.getAllUnbreakableBlocks().contains(b.getType()) && SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.BREAK_BLOCK)) { SlimefunPlugin.getProtectionManager().logAction(p, b, ProtectableAction.BREAK_BLOCK); b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); SlimefunItem sfItem = BlockStorage.check(b); if (sfItem != null && !sfItem.useVanillaBlockBreaking()) { SlimefunBlockHandler handler = SlimefunPlugin.getRegistry().getBlockHandlers().get(sfItem.getID()); if (handler != null && !handler.onBreak(p, b, sfItem, UnregisterReason.PLAYER_BREAK)) { drops.add(BlockStorage.retrieve(b)); } } else if (b.getType() == Material.PLAYER_HEAD || b.getType().name().endsWith("_SHULKER_BOX")) { b.breakNaturally(); } else { boolean applyFortune = b.getType().name().endsWith("_ORE") && b.getType() != Material.IRON_ORE && b.getType() != Material.GOLD_ORE; for (ItemStack drop : b.getDrops(getItem())) { // For some reason this check is necessary with Paper if (drop != null && drop.getType() != Material.AIR) { b.getWorld().dropItemNaturally(b.getLocation(), applyFortune ? new CustomItem(drop, fortune) : drop); } } b.setType(Material.AIR); } damageItem(p, item); } }
Example 5
Source File: LumberAxe.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private void breakLog(Block b) { b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); for (ItemStack drop : b.getDrops(getItem())) { b.getWorld().dropItemNaturally(b.getLocation(), drop); } b.setType(Material.AIR); }
Example 6
Source File: PickaxeOfVeinMining.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private void breakBlocks(Player p, List<Block> blocks, int fortune) { for (Block b : blocks) { if (SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.BREAK_BLOCK)) { b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); for (ItemStack drop : b.getDrops(getItem())) { b.getWorld().dropItemNaturally(b.getLocation(), drop.getType().isBlock() ? drop : new CustomItem(drop, fortune)); } b.setType(Material.AIR); } } }
Example 7
Source File: DataHandler.java From MineTinker with GNU General Public License v3.0 | 4 votes |
public static boolean playerBreakBlock(@NotNull Player player, Block block, @NotNull ItemStack itemStack) { //Trigger BlockBreakEvent BlockBreakEvent breakEvent = new BlockBreakEvent(block, player); ItemMeta meta = itemStack.getItemMeta(); if (meta != null && !meta.hasEnchant(Enchantment.SILK_TOUCH)) breakEvent.setExpToDrop(calculateExp(block.getType())); Bukkit.getPluginManager().callEvent(breakEvent); //Check if Event got cancelled and if not destroy the block and check if the player can successfully break the blocks (incl. drops) //Block#breakNaturally(ItemStack itemStack) can not be used as it drops Items itself (without Event and we don't want that) if (!breakEvent.isCancelled()) { //Get all drops to drop Collection<ItemStack> items = block.getDrops(itemStack); //Set Block to Material.AIR (effectively breaks the Block) block.setType(Material.AIR); //TODO: Play Sound? //Check if items need to be dropped if (breakEvent.isDropItems()) { List<Item> itemEntities = items.stream() .map(entry -> player.getWorld().dropItemNaturally(block.getLocation(), entry)) //World#spawnEntity() does not work for Items .collect(Collectors.toList()); //Trigger BlockDropItemEvent (internally also used for Directing) BlockDropItemEvent event = new BlockDropItemEvent(block, block.getState(), player, new ArrayList<>(itemEntities)); Bukkit.getPluginManager().callEvent(event); //check if Event got cancelled if (!event.isCancelled()) { //Remove all drops that should be dropped itemEntities.removeIf(element -> event.getItems().contains(element)); } itemEntities.forEach(Item::remove); } //Check if Exp needs to be dropped if (breakEvent.getExpToDrop() > 0) { //Spawn Experience Orb ExperienceOrb orb = (ExperienceOrb) player.getWorld().spawnEntity(block.getLocation(), EntityType.EXPERIENCE_ORB); orb.setExperience(breakEvent.getExpToDrop()); } return true; } return false; }