Solved Send message at certain points of runnable

Discussion in 'Plugin Development' started by TheDeathMachine, May 23, 2013.

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

    TheDeathMachine

    So i'm making a minigame plugin, and i want people to get a message every 30 seconds and the last 10 seconds of the timer.
    How to do this?

    i have this so far:

    Code:
                plugin.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) this, new Runnable(){
                    int timer = plugin.getConfig().getInt("Timer");
                   
                    public void run(){
                            if(timer != -1){
                                if(timer != 0){
                                    for (Player p : Bukkit.getOnlinePlayers()){
                                    p.sendMessage(ChatColor.LIGHT_PURPLE + "Game starts in "+ ChatColor.GOLD + timer);
                                    }
                                    timer--;
                                }else{
                                    for (Player p : Bukkit.getOnlinePlayers()){
                                        p.sendMessage(ChatColor.GOLD + "HFFA" + ChatColor.LIGHT_PURPLE + " has started!");
                                        p.setHealth(20);
                                        p.setFoodLevel(20);
                                        p.setFireTicks(0);
                                        }
                                    timer--;
                                }
                        }
                    }
                }, 0L, 20L);
     
  2. Offline

    mcat95

    Check the value of timer and do something like this

    Code:
    if(timer<=10){
     p.sendMessage.....
    }else if(timer==20 || timer==30 || timer==40)
     p.sendMessage....
    
     
  3. Offline

    TheDeathMachine

    mcat95 ofcourse... Thank you!

    mcat95 so this will do?

    Code:
                                    for (Player p : Bukkit.getOnlinePlayers()){
                                        if(timer < 15){
                                    p.sendMessage(ChatColor.LIGHT_PURPLE + "Game starts in "+ ChatColor.GOLD + timer);
                                        }
                                        if(timer == 30 || timer == 60 || timer == 90 || timer == 120 || timer == 150 || timer == 180 || timer == 210 ||
                                                timer == 240 || timer == 270 || timer == 300 || timer == 330 || timer == 360 || timer == 390 || timer == 420
                                                || timer == 450 || timer == 480 || timer == 510 || timer == 540 || timer == 570 || timer == 600){
                                            p.sendMessage(ChatColor.LIGHT_PURPLE + "Game starts in "+ ChatColor.GOLD + timer);
                                        }
                                    }
                                    timer--;
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  4. Offline

    mcat95

    Sure!
     
  5. Offline

    TheDeathMachine

Thread Status:
Not open for further replies.

Share This Page