Solved Timer Issue

Discussion in 'Plugin Development' started by Aragone, Jun 25, 2019.

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

    Aragone

    Hi there,

    I did a timer but I don't know why the arguments into it are executed a lot of time. I want to do that just one time. This timer was given to me in the past by @KarimAKL .

    Do you have any issue ?

    <Edit by Moderator: Redacted code to keep passwords safe, never post those, long live configs>

    BukkitRunnable into the PlayerMoveEvent

    What I want to do is : The player is detected on the block, wait any time, and execute.
     
    Last edited by a moderator: Jun 25, 2019
  2. Offline

    KarimAKL

    @Aragone It's probably because it's inside the PlayerMoveEvent and gets called a lot of times.
    Btw, you can do '0.2f' or 'o.2F' instead of '(float) 0.2'.
    EDIT: Just in case you are wondering why it would call a lot of times even though it's inside an if statement. I would guess that's because getX() gets rounded. e.g. -104.4 = -104, -103.9 = 104, etc.
     
  3. Offline

    Aragone

    It doesn't work... I have to put an int because the game can't detect too precise coordinates
     
  4. Offline

    Kars

    You should use Math.round() instead of casting to an int.

    I can't say for sure but @KarimAKL is probably right. The task gets scheduled multiple times because the move event gets fired multiple times.

    You could keep a list of players for which the task is scheduled. Inside the task, as the last statement, remove the player from that list. Do not schedule a task for a player when he exists in the list. Simple.
     
  5. Offline

    Aragone

    I solved the problem. I put a variable which check if the event has been started.
     
  6. I would recommend changing your DB password and also moving that to a config.
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page