I have an array list filled with players, but I don't know how to get all of them to be used in a for loop. How would i do this?
To obtain all elements from an arraylist, you can utilize a for loop. Code (Text): for(Player players : arrayList) {} Then of course, you can use players and execute any methods to all elements in the arraylist.
either Code (Text): for(Player player : playerList) { //Do stuff } Or (Java 8 only): Code (Text): playerList.forEach(player -> { //Do stuff });
This is what I was trying Code (Text): for(String player : red){ Bukkit.broadcastMessage("r"); Bukkit.getPlayer(player).teleport(locr); } But it wouldn't do anything
Is the "r" message being broadcasted? If so, it means that getPlayer(player) is returning null, which means the string name does not match any online player. If "r" is not being broadcasted, it means the list is empty. I suggest you add a null check inside the loop, and a length check before it, for debugging. Code (Java): Player getp = Bukkit.getPlayer(player); if(getp != null) getp.teleport().... Oh, if this is meant to store long-lasting data, use UUIDs instead of player names, to anticipate player name changes. player.getUniqueId().toString(); and UUID.fromString(); i believe are the methods used.
r i not being broadcast, and maybe its how i am adding the players. I getting the players stored into a config and then adding them to them to the list using this: Code (Text): red.addAll(teams.getStringList("Teams.Red")); And this is how the config is: Code (Text): Teams: Red: Xisuma: true xTheGamerPlayz: false
That's not a valid String list, that's why. A string list in yaml would be Code (Text): Teams: Red: - Something - Something Else
I am not at all familiar with yml (i use .txt or .nbt, because .yml is a flaming disaster with highly fallible formatting), but that looks like a list of named booleans, not strings. Also make sure the indentation is correct and there are no newlines/tab whitespace, yml hates that stuff.
Im sorry, but i do not know how to store it in the format you showed me Edit: Should i try this? Code (Text): teams.getStringList("Teams.Red").add(p);