Player water level

Discussion in 'Plugin Development' started by deathtaker26, Dec 29, 2012.

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

    deathtaker26

    I need 3 methods. One that checks what the player's current air is underwater, one that sets the players air level and finally, one that checks if the player's air level has changed. Can anybody help me out, because google is being difficult
     
  2. First to check if the player is under water you can get the players location than check the block type, for getting the remaining air and setting it you can do player.getRemainingAir()/player.setRemainingAir()
     
  3. Offline

    deathtaker26

    yeah but then won't it be checking the blocks every time the player moves? That seems a bit of a... laggy method
     
  4. Offline

    MP5K

    hello deathtaker26,
    yes you have to check it every move and no it shouldn't be laggy
     
  5. Offline

    deathtaker26

    Sounds heavy, what about a loop. Like if a player does an event under water a loop is enabled that checks if the player's air is at a certain level and if the level gets to low it resets the air.
     
  6. One thing you can do is make a BukkitRunnable or a SheduledTask and check every 20 ticks. This will make a huge improvement lag wise because first of all it isn't checking every single time a player moves, and second because it's thread safe.
     
  7. Offline

    deathtaker26

    right but where should I put this in to activate it? onEnable? If I do that it would always be running that doesn't seem very ethical
     
  8. Offline

    fireblast709

    deathtaker26 the amount of lag you create depends on what you do in that block of code, and how optimized it is. Also, yes, you start it in onEnable
     
Thread Status:
Not open for further replies.

Share This Page