Solved Ik it's stupid but I need help at this

Discussion in 'Spigot Plugin Development' started by ImJustHere, Feb 12, 2020.

  1. Is there a way I can send the player's names in a straight line and not like this? (I'm using an ArrayList)
     

    Attached Files:

  2. FrostedSnowman

    Resource Staff

    This can be accomplished using String::join.

    Specifically:
    Code (Java):
    List<String> data = new ArrayList<>();

    String combined = String.join(", ", data);
    This will separate each element by a comma and space.
     
  3. Can you give me an example of how will I send that in a msg?
     
  4. You would have to loop through the players, add them to the list, then use the String#join method to concatenate them. From there, you can do a normal p.sendMessage or Bukkit.getServer().broadcastMessage to send it.
     
  5. for same reason I have twice the first name that I added
    Code (Text):
    final static ArrayList<UUID> Staff = new ArrayList<UUID>();      

    List<String> data = new ArrayList<>();
            for(UUID staff : Staff)
            {
                data.add(Bukkit.getPlayer(staff).getName().toString());
                String combined = String.join(", ", data);
                player.sendMessage(combined);
            }
     

    Attached Files:

  6. Strahan

    Benefactor

    The join and message should happen at the end, not during the loop. Also you shouldn't use a compound method for something that may fail. For example, if one of your staff members aren't on the plugin will crash.
     
  7. I am putting a method to check if the staff is online or not this is just my test method but thx for the advice
     
  8. I get it thx everyone
     
    • Like Like x 1
    • Friendly Friendly x 1