Hide join message from player who joined?

Discussion in 'Plugin Development' started by elementalgodz11, Jan 13, 2014.

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

    elementalgodz11

    I would like to set the join message for the player who joined to null, otherwise if it isn't the player, send everyone else the join message:

    I have tried using:
    Code:java
    1. for (Player players : Bukkit.getOnlinePlayers()) {
    2.  
    3. if (!players.getName().equals(p.getName())) {
    4.  
    5. e.setJoinMessage(ChatColor.RED + "joinmsg");
    6.  
    7. }
    8.  
    9. }


    Which didn't seem to work. Thanks!
     
  2. Offline

    ThunderWaffeMC

    Even though you're looping online players, you must check if the player is online. Example:

    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerLogin(PlayerLoginEvent) {
    4. Player player = event.getPlayer();
    5. for(Player aPlayer : Bukkit.getOnlinePlayers()) {
    6. if(aPlayer.isOnline()) {
    7. if(!(aPlayer.getName().equals(player.getName()))) {
    8. aPlayer.sendMessage(player.getName() + " has joined the game!");
    9. }
    10. }
    11. }
    12. }
    13.  
     
    elementalgodz11 likes this.
  3. Why check that the player is online? As you can see, its Bukkit.getONLINEPlayers()
     
  4. Offline

    xlrion

    I'm not so sure about needing to check if a player is online. However, you may want to:
    Code:java
    1. e.setJoinMessage("");

    You're re-setting the join message that's sent to all players with every time that's called in your current code. Setting that to "" means that the original functionality where the join message is broadcast to everyone is removed. Now no one would get notified. Then we need to notify those that need to be notified AKA everyone other than the newly logged in player.
    in the for each, use:
    Code:java
    1. player.sendMessage(ChatColor.RED+ "joinmsg");
     
  5. Offline

    ThunderWaffeMC

    It's a good habit to do this. In some cases checking online players may involve you needing to check offline players; therefore you need to check if the offline player is online (which also works).
     
  6. Offline

    BaconStripzMan

    EDIT: I read your post wrong
     
  7. It is not a good habit because it is inefficient.
     
  8. Offline

    stuntguy3000

    Agreed. And you can never loop a offline player.
     
  9. Bukkit.getOfflinePlayers
     
  10. Offline

    Deleted user

  11. I know we won't need that most of the time, i'm just saying that function exists.
     
  12. Offline

    Garris0n

    It's not a good habit unless you are, for some reason, storing player objects after they've left, and you shouldn't be storing them in the first place.
     
    stuntguy3000 likes this.
Thread Status:
Not open for further replies.

Share This Page