Detecting motion of water

Discussion in 'Spigot Plugin Development' started by Strahan, May 4, 2017.

  1. Strahan

    Benefactor

    I'm having an annoying problem. I saw in another thread a guy was asking about something that blocks water but allows players to pass. I was thinking this would be easy to do in a plugin; monitor the BlockFromToEvent and cancel if water is detected entering the desired block. Problem is, it's freaking not working right for me.

    In my test, I used this code:

    Code (Text):
    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onBlockFromTo(BlockFromToEvent e) {
      Block block = e.getToBlock();
      String loc = block.getWorld().getName().toLowerCase() + "/" + block.getX() + "/" + block.getY() + "/" + block.getZ();
      if (block.getType() == Material.WATER) {
          this.getLogger().log(Level.INFO, "Water moving to block " + loc);
      }
    }
    I was on a beach and made a trench 1 block X and 4 blocks Z - 1478/389 to 1478/386. I poured water from a bucket in 1478/389 and got this output:

    Code (Text):
    [10:56:46 INFO]: [Test] Water moving to block zearth/1478/63/388
    [10:56:46 INFO]: [Test] Water moving to block zearth/1478/63/388
    [10:56:46 INFO]: [Test] Water moving to block zearth/1478/63/387
    [10:56:46 INFO]: [Test] Water moving to block zearth/1478/63/387
    WTF? What is the proper, reliable way to track the progress of water's flow? It definitely moved into 386 as I see it there lol.
     
  2. NathanWolf

    Supporter

    I think you also need to watch the physics event, which unfortunate because that fires a lot.