1.16.5 Help with delays

Discussion in 'Spigot Plugin Development' started by jaymey, Jun 17, 2021.

  1. I'm trying to make it so that when the player walks over a block for the first time, it changes to yellow stained glass, and when the player walks over the block again it turns to air. The problem I'm having is that when the player steps on a block it instantly turns to yellow stained glass and then instantly turns to air.

    How can I make it so that the first time it turns it glass, then the next time the player walks on it, it turns to air?

    This is the code I have:

    upload_2021-6-17_14-44-39.png
     
  2. add the block and the time in a hashmap and check that the time between the moment you walk and the moment you want to switch to the air block if the time you want has passed.
     
  3. If you do not want your solution to be time dependent, you should create a HashMap where the key is the player and the value is the last block the player walked on. Add a condition to check if the current underblock is the same block as the one in the map.
     
    • Like Like x 1
  4. no the issue is PlayerMoveEvent gets called every single time the player moves.
    even if the player moves their head slightly to the left this event gets called.
    You need to check if the block at e.getTo() and e.getFrom() are different then run your code.
     
  5. Wouldn't the problem still happen if the player moved a small amount while still staying on the same block? (i.e. walking from the left side of the block to the right side of the block)
     
  6. no if the stays on the same block the code wont execute
     
  7. To make it only trigger when entering a new block, you would just put this at the top of your event
    Code (Java):
    Location from = e.getFrom();
    Location to = e.getTo();
    if(to == null || (from.getBlockX() == to.getBlockX() && from.getBlockY() == to.getBlockY() && from.getBlockZ() == to.getBlockZ()))
        return;
    Do note that this will cause the block to turn to air if they jump while on top of yellow glass. If that is not what you want, you can just remove the Y check.
     
  8. Right, cause the #getFrom will be the same as the #getTo, my bad