Hi Bukkit, I'm coding a plugin that's essentially got lots off assistance for Prison servers. Regardless, I'm having trouble at developing this autoinventory plugin: The method I am using: Code: public static void addToInventory(Player player, Block block) { PlayerInventory pi = player.getInventory(); block.getDrops().forEach(itemStack -> pi.addItem(itemStack)); block.getDrops().clear(); } The part in which I call method (BlockBreakEvent): Code: if (getConfig().getBoolean("BlocksToInventory") == true) { WorldGuardPlugin wg = (WorldGuardPlugin) getServer().getPluginManager().getPlugin("WorldGuard"); if (!(wg.canBuild(player, block.getLocation()))) { } else if (player.getGameMode() != GameMode.CREATIVE) { addToInventory(player, block); event.setCancelled(true); block.setType(Material.AIR); } }
It doesn't factor in enchantments (fortune, silktouch etc.) when delivering items to a player's inventory.
@PQE Method has no way of knowing what the tool is either with your method. https://jd.bukkit.org/org/bukkit/block/Block.html#getDrops(org.bukkit.inventory.ItemStack)
How would I do this then? EDIT: I thought I had solved it, but even this does not work: Code: public static void addToInventory(Player player, Block block, ItemStack inHand) { PlayerInventory pi = player.getInventory(); Collection<ItemStack> drops = block.getDrops(inHand); drops.forEach(itemStack -> pi.addItem(itemStack)); block.getDrops().clear(); }
@PQE What do you mean by does not work? Is the collection empty? Are you getting the items? Are you sure the block has dropped items?
It doesn't work because it doesn't factor in the enchantment on the item held (fortune, silktouch etc.)
I'm actually curious about this too, I've never found one good solution to applying enchantments to block drops. At least not a solution that's built into Bukkit itself. I mean, I can write up the formulae for all the enchants myself, but that's not a great solution.
Well a similar thread on the spigot forum resolved in a bug request being filled, and it was checked as solved for >1.10.2 Sendt fra min ALE-L21 med Tapatalk