Unable to clear drops from a block

Discussion in 'Plugin Development' started by Mee8a, Sep 1, 2015.

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


    Hey all,

    I cannot figure out why I cannot stop blocks dropping items

    This is my code :)
    AntiDrops.java (open)

    package me.Mee8a.prison.utils;
    import org.bukkit.GameMode;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    public class AutoInvBlock implements Listener{
         * Stopping blocks dropping, Adding blocks to inventory
        public void onBreak(BlockBreakEvent e) {
            Player p = e.getPlayer();
            if(p.getGameMode() == GameMode.CREATIVE) return;
            if(p.isOp()) return;
                Material type = e.getBlock().getType();
                Block block = e.getBlock();
                ItemStack item = new ItemStack(type);
                PlayerInventory pi = p.getInventory();

    Thanks in advance
  2. Offline


    Unfortunately, there isn't an easy way to do this with Bukkit. Your code would work, except that block.getDrops() just gives you a list of things that block would drop if it got broken, so changing the list doesn't do anything. A while ago I tried to get them to add a (changeable) drop list to the BlockBreakEvent class but unsurprisingly I don't think they did anything.

    The only solution I could come up with was to cancel the event, set the block to air, play a block break sound at its location, and spawn my own set of dropped items. If you find a better way to do it, let me know.
  3. Offline


    That sounds like a lot of work, I'm farily sure their are plugins that do this, hopefully ones open source so I can have a look how they did it,
Thread Status:
Not open for further replies.

Share This Page