Question every 10minutes and 3minutes answer time

Discussion in 'Plugin Development' started by MadMarvin, Jun 20, 2019.

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

    MadMarvin

    Hi guys I'm currently writing the plugin and now I have the problem with a task.
    Every 10 minutes a question is asked which I can answer with /e [answer].
    You have 3 minutes time to give your answer and the first person who got the answer right wins and the task is stopped you can't answeranymore.
    If nobody has answered, after 3 minutes a sentence will be issued that nobody has won. After correctly answering the question, the winner will be issued and no more answers can be given.
    I know you can do that with a scheduler.
    However, I don't have much idea how to do it, maybe someone could give me an approach on how to do it.
    ~MadMarvin
    Sorry for my bad Englisch
     
  2. Offline

    DerDonut

    Code:Java
    1. int timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    2. @Override
    3. public void run() {
    4. count++;
    5. if(count == 3 * 60) {
    6. //for example display message that nobody won
    7. }
    8. }
    9. }, 0L, 20L);

    This creates a scheduler which runs every second (20 ticks). Count the seconds and act whenever one of your events should happen.

    Tell more exactly where we can help you.
     
  3. Offline

    KarimAKL

    I think another way to do it would be to do something like this:
    Code:Java
    1. private boolean waiting = false;
    2.  
    3. private BukkitTask task = null;
    4.  
    5. public void start() {
    6. waiting = true;
    7. task = new BukkitRunnable() {
    8. public void run() {
    9. waiting = false;
    10. cancel();
    11. }
    12. }.runTaskLater(this, 20*60*3);
    13. }
    14.  
    15. @Override
    16. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    17. if (!cmd.getName().equalsIgnoreCase("e")) return false;
    18. if (!waiting) {
    19. sender.sendMessage("No question has been asked!");
    20. return true;
    21. }
    22. if (args.length == 0) {
    23. sender.sendMessage("You need to give an answer!");
    24. return true;
    25. }
    26. if (!args[0].equalsIgnoreCase("correct")) {
    27. sender.sendMessage("Incorrect answer!");
    28. return true;
    29. }
    30. waiting = false;
    31. task.cancel();
    32. return true;
    33. }
     
  4. Offline

    bwfcwalshy Retired Staff

    Repeating task every 10 mins, when fired then runTaskLater with 3 mins. When answered set a UUID and ignore the others. Once 3 mins is up, check if UUID != null and reward player.
    Make sure to set the UUID back to null after the 3 mins are up.
     
    DerDonut likes this.
  5. Offline

    MadMarvin

    runTaskLater didn't work
    command works, but it only send No Question asked


    console Output:
    Code:
    [17:08:30 INFO]: No question has been asked!
    >e
    [17:11:20 INFO]: No question has been asked!
    >e
    [17:11:27 INFO]: No question has been asked!
    >e
    [17:11:29 INFO]: No question has been asked!
    >e
    [17:11:30 INFO]: No question has been asked!
    >e
    [17:11:30 INFO]: No question has been asked!
    >e
    [17:11:31 INFO]: No question has been asked!
    >e
    [17:11:31 INFO]: No question has been asked!
    >e
    [17:11:32 INFO]: No question has been asked!
    >e
    [17:11:32 INFO]: No question has been asked!
    >e
    [17:11:33 INFO]: No question has been asked!
    >e
    [17:11:33 INFO]: No question has been asked!
    >e
    [17:11:34 INFO]: No question has been asked!
    >e
    [17:11:34 INFO]: No question has been asked!
    >e
    [17:11:34 INFO]: No question has been asked!
    >e
    [17:11:35 INFO]: No question has been asked!
    and in my Code ther is an info for runTaskLater
    something with cast Plugin? but it also dont work :C
     
    Last edited: Jun 24, 2019
  6. Offline

    KarimAKL

    I'm guessing you didn't give the runnable your main class instance.
     
Thread Status:
Not open for further replies.

Share This Page