I have an a ArrayList which I would like to display in order and loop continuously, but I'm not sure how to do so. I seem to only be able to use the specific type of String used in the current code, but if you know of a workaround so I can iterate it, that would be great.
The current code for the ArrayList and string is:
public void showBarChanging(final Player p)
{
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
{
public void run()
{
ArrayList<String> list = new ArrayList<String>();
list.add(DCBar.this.getConfig().getString("1").replaceAll("&", "§"));
list.add(DCBar.this.getConfig().getString("2").replaceAll("&", "§"));
list.add(DCBar.this.getConfig().getString("3").replaceAll("&", "§"));
list.add(DCBar.this.getConfig().getString("4").replaceAll("&", "§"));
list.add(DCBar.this.getConfig().getString("5").replaceAll("&", "§"));
list.add(DCBar.this.getConfig().getString("6").replaceAll("&", "§"));
list.add(DCBar.this.getConfig().getString("7").replaceAll("&", "§"));
String message = (String)list.get(list.size());
BarAPI.setMessage(p, message);
}
}, 0L, 100L);
}
Config file (where integers come from) looks like this:
1: '&bTest 1'
2: '&bTest 2'
3: '&bTest 3'
4: '&bTest 4'
5: '&bTest 5'
6: '&bTest 6'
7: '&bTest 7'
It currently infinitely displays the seventh integer's message.
EDIT:
Jason suggested the following code, which works, but it does not cycle through the integers. The "5" in BarAPI.setMessage(p, message, 5); is equal to five seconds.
ArrayList<String> list = new ArrayList<String>();
for (int i=1;i<=7;i++){
list.add(DCBar.this.getConfig().getString(Integer.toString(i)).replaceAll("&", "§"));
}
String message = (String)list.get(list.size()-1);
BarAPI.setMessage(p, message, 5);
list.get(list.size())should always trigger an exception, sincelist.size()is one more than the maximum legal index. What are you trying to accomplish? What's the problem with looping through an array list either by index or with an iterator (or with an enhancedforloop, which uses an iterator)?getConfig()and what methods does that type have, other thangetString()?