String List

Discussion in 'Plugin Development' started by CaptainBern, Feb 15, 2013.

Thread Status:
Not open for further replies.
  1. Hello all! I have a string list and I need to get the first string, and on a command or after a specific amount of time it should display the second string, then after a specific amount of time again it should display the third string and so go on.. and when it reached the last string it should return to the first string, I know I probably should iterate trough the list and set an index and stuff (thats what they said in a tutorial) can someone please explain me how iterating works? and will it do what I want? I know iteration looks like: if(iterator.hasNext()){ and stuff...anyway thanks for reading I'm kinda a noob and I'm incredibly tired right now so sorry... :s
  2. Offline


    Where do want to get a string from?
    A file, arraylist, hashmap or something else?
  3. from a config
    like this: List<String> msgs = Main.config.getStringList("messages");

    I really need a solution.....somebody has to know how to do this...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 31, 2016
  4. Offline


    I would help you if I could, but don't know how.
  5. Offline


    You might use something like

    1. ArrayList<String> msgs=new ArrayList<String>();
    2. msgs.put("first");
    3. msgs.put("second");
    5. for(String msg:msgs){
    6. Bukkit.broadcastMessage(msg); // Output msg
    7. try {
    8. Thread.sleep(10000); // Sleep 10 sec.
    9. } catch(Exception e){
    11. }
    12. }

    And if you don't want to let your program wait :

    1. public boolean onCommand(...){
    2. ArrayList<String> msgs=new ArrayList<String>();
    3. msgs.put("first");
    4. msgs.put("second");
    6. new Thread(){ public void run() {
    7. for(String msg:msgs){
    8. Bukkit.broadcastMessage(msg); // Output msg
    9. try {
    10. Thread.sleep(10000); // Sleep 10 sec.
    11. } catch(Exception e){
    13. }
    14. }}.start();
    16. }

    (Everything is an example, I didn't try this, let me know when it doesn't work !)
  6. Offline


    This necro-post doe...
    Xp10d3 likes this.
Thread Status:
Not open for further replies.

Share This Page