Cancel a blockFlow event

Discussion in 'Plugin Development' started by Mattie112, Mar 4, 2011.

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

    Mattie112

    Hai,

    For my plugin RedstoneSponges i need to cancel the "onBlockFlow" event triggered by water and/or lava.

    This is what i use:
    Code:
    public void onBlockFlowEvent(BlockFromToEvent event)
    {
    //do some checks
    event.setCancelled(true);
    }
    
    This works, however the water flows back after a moment.
    It did work on the "old" bukkit version (#440), however in the new recommend build (#493) it does not.
    I'm using: bukkit #432.

    Did this change? Or is it just a bukkit error?

    thanks,
    Mattie
     
  2. Offline

    Mattie112

    Anyone???
    It still doesn't works on:
    CraftBukkit: #527
    Bukkit: #451
     
  3. Offline

    MadMonkeyCo

    I think you need to change it to this:
    PHP:
    @Override
    public void onBlockFlow(BlockFromToEvent event)
    {
    //do some checks
    event.setCancelled(true);
    }
     
  4. Offline

    Mattie112

    Sorry, i've tried that

    Code:
      
    [B]public[/B] [B]void[/B] onBlockFlow(BlockFromToEvent event)
    {
    //do some checks
    event.setCancelled(true);
    }
    
    and it doesn't work ;(
     
  5. Offline

    MadMonkeyCo

    Yeah I noticed that by trying it myself.
    You need to use a BlockPhysicsEvent and onBlockPhysics.
     
  6. Offline

    Mattie112

    Thanks, but the water is still flows back :(
    any other ideas?
     
  7. Offline

    MadMonkeyCo

    Did you use @Override? It worked for me on 493.
     
  8. Offline

    Mattie112

    Yeah i did and it doesn't work. Guess they changed it again .....
    I'm running out of ideas, i tried everything i could think off ;(
     
  9. Offline

    MadMonkeyCo

    I just tested it in the latest recommended build and cancelling the physics event works.
    Maybe you forgot to register it...
     
  10. Offline

    Mattie112

    I have this:

    Code:
      getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACED, new RedstoneSpongeBlockListener(this), Priority.Normal, this);
      getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PHYSICS, new RedstoneSpongeBlockListener(this), Priority.Normal, this);
    
    and

    Code:
     public void onBlockPhysics(BlockPhysicsEvent event)
     {
      World world = event.getBlock().getWorld();
      Block blockFrom = event.getBlock();
      Block blockTo = event.getBlock();
      boolean isLava = blockFrom.getTypeId() == 10 || blockFrom.getTypeId() == 11;
      boolean isWater = blockFrom.getTypeId() == 8 || blockFrom.getTypeId() == 9;
      boolean waterSponge = plugin.isWaterSpongeEnabled();
      boolean lavaSponge = plugin.isLavaSpongeEnabled();
      if ((lavaSponge && isLava) || (waterSponge && isWater))
      {
       cancelFlow(world, blockTo, event);
      }
     }
    
    Am i missing something?
     
  11. Offline

    MadMonkeyCo

    I looks like the error is elsewhere in the code. Can you post it all or if you don't like releasing it publically then PM it to me. I might be able to spot something there. This part of the code looks correct but I can't tell for sure since I don't know what your methods are doing.
     
  12. Offline

    Mattie112

  13. Offline

    MadMonkeyCo

    Just to get this straight...
    A powered sponge doesn't drain water and lava when the block-when-powered is set to false.
    [MERGETIME="1300137699"][/MERGETIME]
    The problem rests somewhere in your cancelFlow method. Powered always returns false no matter what... might be a broken method in bukkit. I've tried everything I can think of but nothing seems to work, it only drains when it's powered. I did notice though that Eclipse said there was a "Dead code" at RadZ++ in the cancelFlow method. I'm sorry I can't be of more help.
     
  14. Offline

    Mattie112

    My eclipse doesn't say 'dead code'.
    The plugin generates a properties file so you can choose if you want sponges to be active WITH or WITHOUT redstone power.
    The problem is that is does remove the water only it flows-back immediately.
    Do you get what i mean :) ?
     
  15. Offline

    MadMonkeyCo

    There are some errors in your code, you need to pay more attention to where you put ! and how you use it in your if checks. Changing them did not fix the main problem but it did fix the problem where having a redstone torch on top of the sponge cleared water around no matter what the settings were. I've been testing for about an hour and a half and I'm just blank. I don't understand why it's not working. I think you should just use your clearWater and clearLava in the cancelFlow. Cancelling the event doesn't seem to be working.
     
  16. Offline

    Mattie112

    Ok, thanks.
    I think some things changed with bukkit. It worked really good on the 'old' bukkit. So i don't know if the redstone-torch thing you're talking about is wheter bukkit changed the isPowered or that it's an error of me. I'll look into that.
    Really strange that canceling the event doesn't work anymore, it was just a perfect way to solve the 'flow-back' problem.
    If anyone else know's a way to get it back to work please let me know!
     
  17. Offline

    MadMonkeyCo

    It might be that your all your for loops (3 each physics event, which occur twice everytime water or lava flows) are slower to execute than all the physics events. I don't know if it halts the event until you've decided if you want to cancel it or not. However the error is not in bukkit since it works perfectly without all your loops and checks.
    The redstone torch was a problem in your code because of the NOTs (!) in your methods if checks. You use (!powered || !poweredIndirectly) when the right way is !(powered || poweredIndirectly). Also you sometimes have a NOT for blockWhenPowered = false and sometimes you don't. I suggest fixing it for more accurate testing.
     
  18. Offline

    Mattie112

    Ah, so it does work without the loops, thanks! in that case i know the problem is something in my code and not a broken bukkit feature!
    I'll look into the NOT things you point out to me. It is possible it used to be 'good' but because i didn't get it to work I changed lots of things :p
    again thanks for your time and help!
     
Thread Status:
Not open for further replies.

Share This Page