#Duplicate drops on BlockBreakEvent

1 messages · Page 1 of 1 (latest)

loud marten
#

so in the plugin im coding im trying to allow players to place a custom block then break it and move it again when they need to
it has lore and everything and is one of multiple blocks that im planning on using a grindstone material for
whenever i break the grindstone it works fine, the lore is there and everything, but i cant figure out why it not only drops the grindstone but also just magically drops a second one into my inventory
i have no other active plugins and this is all of the code in the event handler that is significant to this issue (the rest is other block material checks)
does anyone see why thats happening?

@EventHandler
    public void onPlayerBreakBlock(BlockBreakEvent e) {
        Block block = e.getBlock();
        if (block.getType().equals(Material.GRINDSTONE)) {
            e.setCancelled(true);
            if (Drills.getIndex(block) > -1) {//checks if ive saved this grindstone block to my placed list
                ItemStack drop = Drills.getItems().get(Drills.getIndex(block));//gets the item version of the broken block ive saved
                Item item = block.getWorld().dropItem(block.getLocation(), drop);
            }
            Drills.removeBlock(block);//removes tracked block since its broken
            block.setType(Material.AIR);
        } 
    }
#

ive also tried e.setDropItems(false) and it causes the same issue

carmine hare
#

im not sure if this is the issue, but some blocks, notably doors, beds, and pistons, seemed to drop themselves automagically when i set their block to air in the past. This could be happenning to you. I recommend trying to not cancel the event, combined with setDropItems(false)

#

not sure if it will help, but worth a shot

loud marten
#

sadly ive already tried that to no avail

#

i have some new info to add to this
if i have multiple grindstones placed, and i break one whilst having 2+ grindstones in my inventory, it sets the stack count to 1 and drops the grindstone again

#

oh nevermind im stupid i fixed it on my own
forgot to clone the item so it would just reset the item each time

carmine hare
#

ah

loud marten
#

well that solves that