Solved Countdowns

Discussion in 'Plugin Help/Development/Requests' started by Ryzzzen, Apr 6, 2015.

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

    Ryzzzen

    Hi, i'm trying to make a countdown, with messages like:

    "60 seconds before the game starts !"
    "30 seconds before the game starts !"
    "10 seconds before the game starts !"
    etc.
    Sorry for my bad english, i have no idea how to explain that.
    There is my code, something is wrong but i don't know what.

    My code (open)
    Code:
    public class StartCountdown extends BukkitRunnable {
       int seconds = 60;
    
       public StartCountdown()
       {
         Main.state.setState(GameStateType.STARTING);
       }
    
       @Override
       public void run()
       {
         Common.broadcast(ChatColor.YELLOW + "" + seconds + " seconds before the game starts !");
      seconds--;
    
      if (seconds <= 0)
      {
      Common.broadcast("The game starts!");
      Main.state.setState(GameStateType.PLAYING);
      cancel();
      }
    
       }
    }


    I'm on Spigot 1.8. I tried to search on Github some examples for help me but it didn't helped me. My code is based on Bukkit Wiki: Scheduler Programming.

    EDIT: I found this code, and it works. Sorry for this topic useless :(

    New code (open)

    Code:
    public class StartCountdown extends BukkitRunnable {
    
        float seconds, countdown;
      
        public StartCountdown() {
            float seconds = 30;
          
            this.seconds = this.countdown = seconds;
            this.runTaskTimer(JavaPlugin.getPlugin(Main.class), 0, 10);
            Common.broadcast("La partie commence dans 30 secondes !");
        }
    
        @Override
        public void run() {
            float t = countdown / seconds;
            for (Player p : Bukkit.getOnlinePlayers()) {
                if (p.isDead())
                    continue;
                if (countdown % 2 == 0)
                p.setLevel((int) countdown/2);
                if (countdown == 0)
                    p.setExp(0);
                else p.setExp(t);
                countdown-=0.5;
                if (countdown < 0) {
                    this.cancel();
                }
            }
        }
    }
    
     
    Last edited: Apr 6, 2015
  2. Offline

    nverdier

    @Ryzzzen Please mark your thread as solved. See this for more info.
     
    Ryzzzen likes this.
Thread Status:
Not open for further replies.

Share This Page