Solved send message to all players

Discussion in 'Plugin Development' started by Christian210x, Apr 21, 2017.

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


    i'm trying to send a message to every player (reward system).
    but when it sends it send everyone rewards to each player.
    so like i got everyone else reward.

                        for(Player player : Bukkit.getOnlinePlayers()){
                            int cash = points.get(player.getName());
                            int give = cash/10;
                            goldpieces.addGoldPieces(player, give);
                            Bukkit.broadcastMessage("                   §eReward Summary");
                            Bukkit.broadcastMessage("    ");
                            Bukkit.broadcastMessage("§eKills: §7(§6" + killCount.get(player.getName()) + "§7)");
                            Bukkit.broadcastMessage("§eGoldpieces:§7(§6" + killCount.get(player.getName()) + "§7)");
                            Bukkit.broadcastMessage("     ");
                            Bukkit.broadcastMessage("    ");
  2. Offline


    You want to everyone recive message when some one get gold ?
  3. Offline


    no at end of game it send message to all players on how many kills they got and gold pieces
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline


    it is not doing it, i send every player a reward message. but i get everyone reward message (so theirs more than one in my chat.)
  6. Offline


    Last edited: Apr 21, 2017
  7. Offline


    Last edited by a moderator: Apr 21, 2017
  8. Offline


    Well you're looping through it for every online player. And then you are printing it for every online player.
    Instead of broadcasting for every online player, get a for loop for all the online players, and then just print the values you get once for each player. You currently loop for every player.
  9. @Christian210x
    Your problem is:
    You do loop trough all players, but you aren't sending the message only to the selected player, you are sending it to all. (Broadcast always send it to all players who are online)

    So, do stmh like that:
    foreach player (maybe not everyone, just the ones who have played?):
        player.sendMessage("You got XXX goldcoins,...");
    Edit: i would recommend not to use playernames in your method. Instead, juse the UUID. It's much better and not the big difference in your code.
  10. Offline


    well i want to send it to all players that played even dead ones
    And you guys want me to do the same thing aagain read what you said.
    @thechrisanator & @Erumeldor

    my bad everyone i see what i did i.
    i didnt see the bukkit.broadcastmessage...
    it all works now.
    Last edited: Apr 21, 2017
Thread Status:
Not open for further replies.

Share This Page