Delay between messages read from list in config.

Discussion in 'Plugin Development' started by pablo67340, May 27, 2014.

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

    pablo67340

    Hi, I am using the following code to read in a list and send a message for every line in the list.

    Code:java
    1.  
    2. for(String m : this.getConfig().getStringList("message")){
    3. e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', m).replace("%player%", e.getPlayer().getName()));
    4. }


    Problem is, it sais all the lines at once. I need to make a delay between each line so it has a credit or star wars words effect. String list? Arrays? Someone help! i am stuck. Mind F**k moment.
     
  2. Code:
     
    for(String m : this.getConfig().getStringList("message")){
                        e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', m).replace("%player%", e.getPlayer().getName()));
    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
     
    public void run(){
    }
    },1*20);
                    }
    
    this will print every message with 1 second delay
     
  3. Offline

    pablo67340

    This will print one line at a time with a delay or all the lines with a delay? i need one line at a time
     
  4. Offline

    minoneer

    pablo67340 a different suggestion:

    Code:
    final Player player = ...;
    final List<String> messages = config.getStringList("path");
    final int id = Bukkit.getScheduler().scheduleSynchRepeatingTask(plugin, new Runnable()
    {
        int i = 0;
     
        @Override
        public void run()
        {
            if (i < messages.size())
            {
                player.sendMessage(messages.get(i));
                i++;
            }
     
            else
            {
                Bukkit.getScheduler().cancleTask(id);
            }
        }
    }, 0, 10);
     
  5. Offline

    pablo67340

    Ill test. Thanks!

    minoneer

    'ID' is red in Bukkit.getScheduler().cancelTask(id);

    Sais the variable has might not been initiated

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page