onBlockBreak not functioning correctly?

Discussion in 'Plugin Development' started by MuisYa, Jul 15, 2012.

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

    MuisYa

    Dear Bukkit Developers.

    I got a problem with my code. I have been working with BlockBreakEvent for a year now, and never had a problem with it. But now i do.
    This is my code:

    Code:
    @EventHandler
    public void onBlockBreak(BlockBreakEvent event) {
        if (event.isCancelled()) {
            Bukkit.broadcastMessage("Event was already cancelled.");
            return;
        }
        else {
            Bukkit.broadcastMessage("We got a Block break!'');
            event.setCancelled(true);
            return;
        }
    }
    And this gives me a total random output when breaking a redstone torch ONCE.
    Possibilities:

    Code:
    Nr1. it gives me the "We got a Block break!" message twice. (Happens most of the time!)
    Nr2. It gives me the "We got a Block break!" message once.
    
    I am trying to break a Redstone torch,

    Thanks for helping! MuisYa
     
  2. Offline

    bloggershaft

    This should work.
    It exports with an error..but on startup and in-game works fine!
    Hope it helped!:)




    Code:
     public static Material[] brokenBlacklist = {Material.REDSTONE_TORCH_ON,Material.REDSTONE_TORCH_OFF};
     
    @EventHandler(priority = EventPriority.HIGH)
    public void onBlockBreak(BlockBreakEvent event) {
    Player player = event.getPlayer();
    for(Material m : brokenBlacklist){
    if(event.getBlock().getType() == m){
    Bukkit.broadcastMessage("We got a block break!");
    event.setCancelled(true);
    }
    }
    }
     
     
    }
     
  3. Offline

    r0306

    MuisYa
    Try this:
    Code:
    @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onBlockBreak(BlockBreakEvent event) {
            Bukkit.broadcastMessage("We got a Block break!'');
            event.setCancelled(true);
            return;
    }
     
  4. Offline

    lololmaker

    You shouldn't EVER change the outcome in priority of MONITOR, It's made for what it says, monitoring of outcome.
     
    MrMag518 likes this.
  5. Offline

    Etsijä

    I am having exactly this same problem, both with BlockBreakEvent and BlockDamageEvent. I am trying to cancel block damage to redstone repeaters, when clicked with my workbench (my plugin uses workbench for specific purposes), but the problem is, most of the time the event gets fired twice with each left-click of the repeater. Anyone know how to prevent this?
     
  6. Offline

    Giant

    I have noticed that in rare occasions BlockBreakEvent seems to fire twice, though it hasn't occurred enough for me to consider it a true bug. I suspect it's more related to lag then an actual bug... :)
     
  7. Offline

    Etsijä

    I have written a plugin (see my signature) which rotates some blocks when left-clicking them with a workbench. The plugin works perfectly for ordinary items like logs, stairs, slabs etc. But with redstone repeaters, the repeater is broken with a single hit, and that's why I need to cancel its block break event. Problem is, it is constantly (about 80% of the time) firing twice, and making it impossible to rotate the repeater with a single click - 80% of the time it looks like when you're in fact clicking the repeater once, looks like it took two "hits".
     
  8. Offline

    Giant

    Etsijä In that case, I would suggest writing to a temporary list in case the repeater is "broken", this list would be something like List<String>, where String stand for the player name. Next you would check if the player is on the list if it gets fired again for the same block. And I admit, whilst this method is quite far from perfect, it should sort of work.

    And as back to the firing twice, could it be it depends on the type of block broken? Say if it is a block that breaks in 1 hit, minecraft somehow sends the break packet twice?

    Off topic:
    Jeesh, whats with the hard to write names today :(
     
  9. Offline

    Etsijä

    I am suspecting this is the case, since this never happens to blocks which do not have their InstaBreak set.

    As for your other idea: thanks, I'll give it a try.
     
  10. Offline

    Etsijä

    I'm currently trying to implement your idea for the "block breaking twice" event handling, but fail to grasp the idea. Could you please elaborate a bit? That would be great.
     
Thread Status:
Not open for further replies.

Share This Page