Sending a message to an entire team.

Discussion in 'Plugin Development' started by davidude, Jul 22, 2014.

Thread Status:
Not open for further replies.
  1. I am using the bukkit Teams API and have created a team named one
    Code:
    //Team 1
        Scoreboard oBoard = sbManager.getNewScoreboard();
        Team one = oBoard.registerNewTeam("one");
        Objective objOne = oBoard.registerNewObjective(ChatColor.GOLD + "Lobby: " + ChatColor.GREEN + "1", "dummy");
    And I want to send a message to all players on team 'one' with out broadcasting it to all players.
    Any thoughts.
     
  2. Offline

    The Fancy Whale

    Loop through the players on the team in a for loop and send them all a message.
     
  3. Offline

    LugnutsK

    Code:java
    1. for (OfflinePlayer name : team.getPlayers()) {
    2. if (!name.isOnline())
    3. continue;
    4. name.getPlayer().sendMessage(message);
    5. }
     
  4. I tried that but I wasn't sure how to go about it. From what I saw I needed to use an array list to use an for loop with all the team members. I am unsure how to create such a array list, I saw there is a
    Code:java
    1. one.getPlayers().toArray();
    but I didn't know how to use it, if you could help it would be great.

    Thanks I think this should work(I haven't been able to try it yet).

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Offline

    _Filip

    LugnutsK I don't use the continue keyword much, but I'm pretty sure that wouldn't work.
     
  6. Offline

    LugnutsK

    'continue' skips to the next iteration. The code above is equivalent to:
    Code:java
    1. for (OfflinePlayer name : team.getPlayers()) {
    2. if (name.isOnline())
    3. name.getPlayer().sendMessage(message);
    4. }

    It's just a matter of style. This version is probably easier for most people to read.
     
Thread Status:
Not open for further replies.

Share This Page