Solved Delay between message list

Discussion in 'Plugin Development' started by Krumb069, May 30, 2015.

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

    Krumb069

    I want to send message list with delays. Example config:
    Messages:
    - Hello
    - Welcome to server
    - Hope you enjoy server
    Delay: 20
    It will send Hello, wait 1 seconds, then send Welcome to Server, wait 1 seconds, send Hope ...
    How can I do it ?
     
  2. Offline

    glory_fades

    @Krumb069
    maybe have it written out like
    - Hello
    delay: (your number)
    - Welcome to the server
    delay: (your number)
    - Hope you enjoy the server
    delay: (your number)
     
  3. Offline

    16austin16

    Thry This And If It Doesn't Work Then Play Around With It And A Bonus You Can Also Use & ColorCodes In The Config
    Code:
        Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
              public void run() {
                  if(Main.this.getConfig().getStringList("Messages") != null) {
                      int I = 1;
                      String Msg = ChatColor.translateAlternateColorCodes('&', (String)Main.this.getConfig().getStringList("Messages").get(I));
                      Bukkit.broadcastMessage(Msg);
                  }
              }
            }
            , 0L, getConfig().getLong("Deley") * 20L);
    Then The Config:
    Code:
    Messages:     
    - 'You Can Have More Than One Message! Just Copy This.'
    - '&b&l&o&nYou Can Also Use Color Codes!'
    - '&c&lPlugin Made By 16austin16.'
    - '&a&lType /simplecommands help for help.'
    - '&a&lType /simplecommands config for config help.'
    #This is measured is seconds. Be careful!
    Time: 300
     
    Krumb069 likes this.
  4. Offline

    Krumb069

    It may be used too, but I don't know how to do this I only know sending message list

    Thanks I will try it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  5. Offline

    16austin16

    The Only Thing You Need To Play Around With Is The If Statement And Adding 1 To I After Each Run
     
  6. Offline

    Krumb069

    error at this line ?
    String Msg = ChatColor.translateAlternateColorCodes('&', (String)Main.this.getConfig().getStringList("Messages").get(I));
    Create class "ChatColor"
    It was working on string but I don't know why it didn't work on string list ?
     
  7. Offline

    16austin16

    Did You Import ChatColor?
    Code:
    import org.bukkit.ChatColor;
     
  8. Offline

    Krumb069

    Sorry eclipse didn't suggested it :D

    @16austin16
    It sends same message with delays, it only sends seconds line

    @16austin16
    I don't want to have custom count messages, It will send message 2 if it exist, then send 3, 4, etc..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  9. I update it to a working code:
    Code:
    new BukkitRunnable() {
    int i = 0;
    List<String> messages = getConfig().getStringList("messages");
    public void run() {
    if (i >= messages.size()) {
    cancel();
    return;
    }
    Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', messages.get(i));
    i++;
    }
    }.runTaskTimer(this, 0, getConfig().getLong("Delay") * 20);
    And the config is the same. Except that "Time" is "Delay" in my version
    The scheduler cancels itself after all messages are sent. If you want to start from the beginning again, replace:
    Code:
    cancel();
    return;
    with
    Code:
    i = 0;
     
    Krumb069 likes this.
  10. Offline

    Krumb069

    Thanks now it is working

    @FisheyLP how to add variables to string ? I tried
    List<String> mesajlar1 = getConfig().getStringList("Messages.Line1");
    String isim = o.getName();
    List<String>mesajlar1 = mesajlar1.replaceAll("%player", isim);

    @FisheyLP
    solved

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

Share This Page