Cancel a block drop in 1.15.2

Discussion in 'Plugin Development' started by BlaSfaiMe, Jun 17, 2020.

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

    BlaSfaiMe

    Hi,
    I've a problem : I want to cancel a block drop.
    If I'm ask here, that because all of solutions don't working. I've tried in the BlockBreakEvent :
    • e.setDropItems(false) : ineffective.
    • e.getBlock().setType(Material.AIR) : ineffective.
    I've tried in BlockDropItemEvent too, but not more effective...

    Do you have a solution ? Thanks !
    (btw, like the title says : I'm in 1.15.2)
    (btw 2 sorry for my english, I'm french)
     
  2. Online

    timtower Administrator Administrator Moderator

    @BlaSfaiMe Please post your code.

    And what exact drop do you want to stop?
     
  3. Offline

    BlaSfaiMe

    Ok, so, I want to cancel the drop of a furnace.
    For my code, I use a custom block manager, but i think that's not the problem :

    Code:
        @EventHandler
        public void breakBlock(BlockBreakEvent e){
            if(plugin.getBlockManager().getBlocks().containsKey(e.getBlock().getLocation())){
                e.getPlayer().sendMessage("you break a known block");
                e.getBlock().setType(Material.AIR);
                plugin.getBlockManager().dropBlock(e.getBlock().getLocation());
                plugin.getBlockManager().removeBlock(e.getBlock().getLocation());
            }
        }
    For infos, the message is sent ! this is only the setType() line (btw, now, with this method, the drop is not effective) that's cause problems
     
  4. Online

    timtower Administrator Administrator Moderator

  5. Offline

    BlaSfaiMe

    I just re-try this method and it's doesn't work. Like the 3rd line does'nt work. Nothing in the console.
     
  6. Online

    timtower Administrator Administrator Moderator

    You might want to drop the block before you set it to air.
     
  7. Offline

    BlaSfaiMe

    I'll try this

    Edit : @timtower It's doen't working... With the setBlock type to AIR, the custom drop doen't appear, and thez regular furnace still drop
     
    Last edited: Jun 17, 2020
  8. Offline

    gochi9

    Cancel the event and the set the type of the block to air
     
  9. Online

    timtower Administrator Administrator Moderator

    Code?
     
  10. Offline

    BlaSfaiMe

    @timtower

    Code:
               plugin.getBlockManager().dropBlock(e.getBlock().getLocation());
                e.getBlock().setType(Material.AIR);
                plugin.getBlockManager().removeBlock(e.getBlock().getLocation());
    @gochi9
    It doesn't working anymore
     
    Last edited: Jun 17, 2020
  11. Offline

    gochi9

    Ok so by canceling the event i meant e.setCancelled(true); and then setting the
    e.getBlock().setType(Material.AIR);
    Code:
    if(plugin.getBlockManager().getBlocks().containsKey(e.getBlock().getLocation())){
                ev.setCancelled(true);
                e.getBlock().setType(Material.AIR);
                ev.getPlayer().sendMessage("you break a known block");
    
            }
    
    This should work just fine if you want to break the block without getting the drop
     
Thread Status:
Not open for further replies.

Share This Page