block break event setCancelled(false) #42


  • New
  • Other
Open
Assigned to axeldios
  • blablubb created this issue Jun 15, 2013

    Hey,
    I noticed this:

    else {
            event.setCancelled(false);
          }

    at the end of your block break listener. What if an other plugin already canclled the event, before it has reached your event? Wouldn't it be better to not modify the setCanclled-state, instead of setting it to false?

  • blablubb added the tags New Other Jun 15, 2013
  • AxelDios posted a comment Jun 17, 2013

    First off, if someone canceled the event before me the my plugin will never get the event.

    The end of the block break event looks like this:

    / / region doesn't exist, regular ore block

    if (ProtectionStones.noSilkTouch) {

    pb.breakNaturally();

    event.setCancelled(true);

    } else {

    event.setCancelled(false);

    }

    That event.setCancelled(false) is in that block not an else event of the entire block break event. And what that does logic is concerned with is if the block isn't defining a region and PS isn't set to block silktouch pickaxes against a block in the PS Block List.

    In other words I'm not cancelling the event so other plugins will see it.


    Edited Jun 17, 2013
  • blablubb posted a comment Aug 17, 2013

    I am not exactly sure at the moment what the problem was, but I think to remember there was a problem with this in combination with another plugin..

    I will try to see if I can remember the exact case..

    Edit: Okay I remember what the issue was:

    See the comment of a user of my plugin AntiXRay here:
    dev.bukkit.org/bukkit-plugins/anti-x-ray/?comment=472

    Basicly AntiXray was checking with normal or low priority (basicly: before your plugin), if the player shall be allowed to break a block, and cancles it, if the block shall not be able to be broken.

    The problem now is, that even though I cancelled the block-breaking in  AntiXRay, ProtectionStones later in the event queue set the event to "not cancelled", without checking if an other plugin has already cancelled the event / doesn't want the block to be broken.. You are basicly overwriting all decisions made by other plugins whose BlockBreakEvent is called before..

    I fixed it in this case on my end by listenting to the block break event with higher priority then your plugin (to make sure the event gets cancelled..).

    Just wanted to let you know with this ticket, that you shouldn't set events to being "not cancelled", if it could conflict with other plugins, which want to cancle the event ..

    ["if someone canceled the event before me the my plugin will never get the event."]
    I don't see any code which jumps out of your event if the event is cancelled, nor do I see an "ignoreCancelled = true" in your EventHandler settings.. So how does it come, that you think your plugin would never get the event, if it was cancelled before?

    Also, even if you assume that the event is not cancelled anyway when you get it (which is not the case by the way..), there shouldn't be any reason to set the event to "not cancelled" then, because it already would be "not cancelled" without that. So you could just leave it, the way it already is..


    Edited Aug 17, 2013

To post a comment, please login or register a new account.