how to send message to every player online without broadcasting

Discussion in 'Plugin Development' started by RuthlessRage, Apr 7, 2015.

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

    RuthlessRage

    seems like whenever i post this question it gets deleted... i don't know the awnser thats why i'm asking. i want to use the method player.sendMessage(event.getName()" has joined the server") and to send that to ever player online.

    public void onJoin(PlayerJoinEvent e) {
    Player player = e.getPlayer();

    for(Player p1 : Bukkit.getOnlinePlayers()) {
    if (p1 != null && p1.isOnline()) {

    p1.sendMessage(player.getName()" has joined the server")
    }

    its not working and whoever keeps delteing my question stop it; i don't know the awnser !
     
  2. Offline

    nverdier

    @RuthlessRage They are probably getting deleted because you're being rude and very disrespectful.
     
  3. Offline

    sgavster

    If you want help be nice.. Please.

    Are your events registered?
    Do you have @EventHandler?
    You need a + between player.getName() and " has joined the server"
    You need a ; after you send the message..
    You don't need to check if p1 is null
    You dont need to check if p1 is online
     
  4. Offline

    RuthlessRage

    @sgavster
    Thanks ok so i have this now which i had when i tested. the problem is it only sends to one player

    public void onJoin(PlayerJoinEvent e) {
    Player player = e.getPlayer();

    for(Player p1 : Bukkit.getOnlinePlayers()) {


    p1.sendMessage(player.getName() + " has joined the server");
    }
     
  5. Offline

    Gater12

  6. @RuthlessRage You want to send to everyone... Why not use #setJoinMessage?
     
  7. Offline

    RuthlessRage

    @bwfcwalshy @Gater12I'm just seeing if there are alternatives; already know how to broadcast or set join message. really would like to be able to do the same with .sendMessage
     
  8. @RuthlessRage But all you are doing is causing it to be inefficient...
     
    nzkiwi.5000 likes this.
  9. Offline

    Gater12

    @RuthlessRage
    If I may question, why? What are you REALLY trying to accomplish?
     
  10. Offline

    RuthlessRage

    @Gater12 @bwfcwalshy When a player joins it will send a message to all the online players with the method- .sendMessage(), that's what id like to see happen.
     
  11. Offline

    timtower Administrator Administrator Moderator

  12. Offline

    uksspy

    @RuthlessRage Put some debug code in your event to make sure it is firing.
     
Thread Status:
Not open for further replies.

Share This Page