Message for a certain player

Discussion in 'Plugin Development' started by 123keelos, Jun 8, 2015.

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

    123keelos

    Hello Bukkit! I want to add something into my plugins which is a join message for only me. Like lets say...

    k! So lets pretend 123keelos joined the game. In coding, it would have 123keelos, developer of <plugin> joined the game

    How would I be able to do this? Some other plugins did it (i lost it though). How can I do this? Please help :)
     
  2. http://toastedtruth.me/bukkit_apidocs/org/bukkit/event/player/PlayerEvent.html#getPlayer--
    Get the player from PlayerJoinEvent ^

    http://toastedtruth.me/bukkit_apido...inEvent.html#setJoinMessage-java.lang.String-

    Set the join message ^

    Use Player#getName() to get their username.

    Although, if you want to make it so ONLY you get the message:
    Code:
    if (event.getPlayer().getName().equals("123keelos")) {
        event.getPlayer().sendMessage(ChatColor.YELLOW + event.getPlayer().getName() + ", developer of Test joined the game.");
    }
    
    This'll still send you, and everyone else, the default join message on the server too.
     
  3. Offline

    Edvio

    You are pretty new to bukkit right? I am too so dont call me out. I think you can do it this way:
    @EventHander
    public voin onPlayerJoin(PlayerJoinEvent e) {
    Player p = e.getPlayer());
    if(p.getName().equals("123keelos") {
    for final Player all : Bukkit.getOnlinePlayers {
    all.sendMessage("123keelos, developer of plugin joined the game);
    }


    Thats all code I had in my mind, goodnight.
     
  4. Offline

    Konato_K

    @Edvio If you're going to send to all players is probably better to use broadcastMessage (either on Bukkit or the Server class) or broadcast(String, String) which also takes a permission and will send the message to the players with the specified permission.
     
Thread Status:
Not open for further replies.

Share This Page