Execute a specific line in the code

Discussion in 'Plugin Development' started by Aragone, Jul 18, 2019.

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

    Aragone

    Hello !

    I would like to execute a specific line into this code : https://pastebin.com/raw/USV8pQu8

    At 'if(sql.getOui() + sql.getNon() == Bukkit.getServer().getOnlinePlayers().size())' I would like to execute the bukkit runnable run() (which has 1800 ticks) and then, stop the bukkit runnable. Is it possible ?

    Thanks for your help !
     
  2. Offline

    Reflxction

    If I recall correctly, runTaskTimer returns an integer representing the task ID, which is required by Bukkit.getScheduler()#cancelTask(int).
     
    Aragone likes this.
  3. Offline

    KarimAKL

    @Aragone Your BukkitRunnable is not repeating, so there's no need to stop it.
    Let me know if i misunderstood the question.
     
  4. Offline

    Aragone

    @KarimAKL sorry this system is a vote. When an admin performs the command /request day/night/weather, I start the BukkitRunnable which contains the final instructions to do when the timer is ending. But, I would like to make a system : When all players of the server have a vote, then you can stop the timer, say "everyone has a vote" and give results (so execute the instructions in the BukkitRunnable more quick than it had to do). But you have to stop the timer too because if an admins restart a vote too quickly, the last timer which is not at its end will be called. It will not start a new timer I think. I'm talking about conflict.

    My question is : How can I execute the instructions in the BukkitRunnable when everybody has a vote without writing a second time all of these instructions in the if()? And then how can I stop the timer before its truth ending (1800 ticks)?

    Sorry for my English lol

    I will look for that thank you

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.

    @Reflxction How can I keep the taskId from this code ? I don't know where to put the instruction

    @KarimAKL Any idea ?
     
    Last edited: Jul 19, 2019
  5. Offline

    KarimAKL

    @Aragone You should be able to do something like this:
    Code:Java
    1. BukkitTask task = new BukkitRunnable() {
    2. public void run() {
    3. // Your code
    4. }
    5. }.runTaskLater(plugin, delay);
    6. task.cancel();

    Just save that 'BukkitTask' and then call cancel on it whenever you want it cancelled.
     
  6. Offline

    Aragone

  7. Offline

    KarimAKL

    @Aragone
    1. That's not an error, that's a warning.
    2. You are getting that warning because you aren't using the variable. (you aren't cancelling the task anywhere)
     
  8. Offline

    Aragone

    @KarimAKL I use the variable in the if() section no ?
     
  9. Offline

    KarimAKL

    @Aragone In that case, it shouldn't be giving you that warning, did you save the file? You can just suppress the warning.
     
  10. Offline

    Aragone

    I had supressed warning and I have an error when I perform command /vote oui

    upload_2019-7-20_16-38-25.png

    The line is task1.cancel() and task2.cancel().

    Code : https://pastebin.com/raw/Tf6J6tAh
     
  11. Offline

    KarimAKL

    @Aragone You need to initialize the task before you can use it. Check if the tasks are null, and if so, send them a message saying something like "No vote has begun".
     
  12. Offline

    Aragone

    @KarimAKL I think I will let this system for the moment. The plugin runs well, it's just not complete. I have others things to do on the server. Thank you for your help @KarimAKL
     
Thread Status:
Not open for further replies.

Share This Page