countdown before game ?

Discussion in 'Plugin Development' started by oxilo, Jun 18, 2021.

  1. Offline


    Hello i'm new at creating a plugin but i want to do a game with a countdown before launch it and when the countdown is finish that start a game is that possible ?
    Like this :

    start countdown
    continue countdown
    delete countdown
    start the game
  2. Offline


    Definitly not like this. The server will probably crash when the countdown is too long because it blocks the main thread
    Use a delayed task instead like this
    Set countdown
    new BukkitRunnable () -> { (not valid code)
    start game

    More information and better examples:
  3. Offline


    It would be much easier to make a synchronous task timer, which runs the code every second as it decreases the countdown variable. There are more things you could add, such as utilizing "this.cancel();" to stop the timer if a player leaves, for example.
    new BukkitRunnable() {
                int i = 10;
                public void run() {
                    if (i > 0) Bukkit.broadcastMessage("§bGame starts in " + i + " seconds!");
                    else startGame() //your method to start the game here
                    i = i - 1;
            }.runTaskTimer(plugin, 0, 20l)

Share This Page