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
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.
You might use something like Code:java ArrayList<String> msgs=new ArrayList<String>();msgs.put("first");msgs.put("second"); for(String msg:msgs){Bukkit.broadcastMessage(msg); // Output msgtry {Thread.sleep(10000); // Sleep 10 sec.} catch(Exception e){ }} And if you don't want to let your program wait : Code:java public boolean onCommand(...){ArrayList<String> msgs=new ArrayList<String>();msgs.put("first");msgs.put("second"); new Thread(){ public void run() {for(String msg:msgs){Bukkit.broadcastMessage(msg); // Output msgtry {Thread.sleep(10000); // Sleep 10 sec.} catch(Exception e){ }}}.start(); } (Everything is an example, I didn't try this, let me know when it doesn't work !)