Get All World Names

Discussion in 'Plugin Development' started by Vinceguy1, Jun 10, 2012.

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

    Vinceguy1

    How do you get all world names in bukkit, you can do Bukkit.getWorlds().toString(); but it will come out like CraftBukkit name={world}
     
  2. Offline

    r0306

    Vinceguy1
    Using the toString() method with a list causes it to print the value of the whole List. Instead, loop through the list and put them into a string. You can use a method like this.

    Code:
    public String getWorldNames (List<World> worlds) {
    String worldNames = "";
    for (World w: worlds) {
    worldNames += w.getName() + ", ";
    }
    return worldNames;
    }
     
  3. Use a loop.

    Code:java
    1.  
    2. String[] worldNames = new String[Bukkit.getServer().getWorlds().size()];
    3. int count = 0;
    4. for(World w : Bukkit.getServer().getWorlds()){
    5. worldNames[count] = w.getName();
    6. count++;
    7. }
    8. for(String s : worldNames){
    9. System.out.println("World Names = " + s);
    10. }
    11.  
     
Thread Status:
Not open for further replies.

Share This Page