Displaying StringLists

Discussion in 'Plugin Development' started by Raydond123, Jan 22, 2015.

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

    Raydond123

    Hello, I'm working that show people online that have a certain permission.
    Here's what I have for displaying the players:

    Code:
    List<String> players = getConfig().getStringList("staff");
    for (String s : players) {
                        String[] playerList = s.split(", ");
                        player.sendMessage(playerList);
                    }
    But when I type the command, it displays the players like:

    Code:
    Raydond123
    Mineflow_
    dragonx10101
    Instead of displaying it like:

    Code:
    Raydond123, Mineflow_, dragonx10101
    Any help would be appreciated.
    Thanks!
     
  2. Offline

    Skionz

    @Raydond123 Your creating the array and sending it every time. Create it, iterate and parse it, then one complete send the message.
     
  3. Offline

    Raydond123

    @Skionz How would I do that? Because if I set the "for" statement somewhere else, trying to send the player the list wouldn't work.
    It's because the "String[] playerList" isn't a local variable anymore.
     
  4. Offline

    teej107

  5. @Raydond123
    Code:
    List<String> players = getConfig().getStringList("staff");
    String str = "";
    for (String s : players) str += s + ", ";
    p.sendMessage(str.substring(0, str.length-2));
     
    Raydond123 likes this.
  6. Offline

    Raydond123

  7. Offline

    1Rogue

    Don't use that method, it's extremely inefficient. Use a StringBuilder and the #append(String) method for it.

    Or better yet:

    Code:java
    1. p.sendMessage(StringUtils.join(getConfig().getStringList("staff"), ", "));
     
  8. Offline

    Raydond123

    @1Rogue Hey, in the code you provided you used StringUtils...
    There are several that Eclipse allows me to import but which one do I import for StringUtiles?
     
  9. Offline

    1Rogue

    NathanWolf likes this.
  10. Offline

    Raydond123

    @1Rogue Thanks! I'll be using the StringUtils in the future. ;)
     
Thread Status:
Not open for further replies.

Share This Page