AutoInventory

Discussion in 'Plugin Development' started by PQE, Feb 5, 2017.

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

    PQE

    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);
                }
            }
    
     
  2. Offline

    timtower Administrator Administrator Moderator

    @PQE And what exactly is the issue?
     
  3. Offline

    PQE

    It doesn't factor in enchantments (fortune, silktouch etc.) when delivering items to a player's inventory.
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    PQE

    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();
        }
    
     
    Last edited: Feb 5, 2017
  6. Offline

    Zombie_Striker

    @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?
     
  7. Offline

    PQE

    It doesn't work because it doesn't factor in the enchantment on the item held (fortune, silktouch etc.)
     
  8. Offline

    Rayzr522

    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.
     
  9. Offline

    JanTuck

    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
     
Thread Status:
Not open for further replies.

Share This Page