How to send message to player on login?

Discussion in 'Plugin Development' started by dafen, Jan 25, 2012.

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

    dafen

    Hi Bukkit,

    I am new to Bukkit Plugins programming and I'm just learning at the moment.

    I want to send a message to a player as that player joins the server. I have tried this:

    Code:
    @EventHandler
    public void playerLogin(PlayerLoginEvent event) {
        playerJoined = event.getPlayer();
        playerJoined.sendMessage("Willkommen, "+ playerJoined.getName());
    }
    I have also tried:
    Code:
    Bukkit.getServer().broadcastMessage("Hi, "+ playerJoined.getName());
    But they both do not work, why? No errors and no message...

    Thanks for help!
    Dafen
     
  2. Offline

    uruhax

    Did you make sure to register the event in the main class or in the listener class? You register an event by using Bukkit.getServer().getPluginManager().registerEvents(<listener goes here>, this);
     
  3. Offline

    dafen

    Yeah the event is working fine because using:
    Code:
    log.info("<playername> joined the server");
    prints a message in the console on a player's login.

    Thanks for your reply!

    @Seadragon91
    Thanks a lot! It's working just like I want. =)

    Greets from Berlin.


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  4. Offline

    tboss

    How did you do finally ?
     
  5. Offline

    EllBristow

    Did you swap PlayerLoginEvent for PlayerJoinEvent ? That's how I would have done it!
     
    ringknight05 likes this.
  6. Offline

    RROD

    Yeah you should have used PlayerJoinEvent. Also for reference, there's PlayerQuitEvent, not PlayerLogout.
     
  7. Offline

    tboss

    Yep but all the rest of my plugin is running on player login. So i have to do a list with my messages for the players set onplayerlogin and write the message onplayerjoin ? Is there no better way ?
     
  8. Offline

    bergerkiller

    Yup, you have to use onPlayerJoin to interact with the player through the network. This is because, during the login event, the player has no real connection (netServerHandler is null or not used). Any attempt to send a packet will fail at that point, including messages.

    Getting the network address will fail as well, since no network socket is made yet.
     
  9. Offline

    tboss

    I use his ip, when he is not refused kick message contains his ip. So I finally used onPlayerJoin to send the message even if the verification is made onPlayerLogin. I store my message into a list and I send it to the player when he joins.
     
Thread Status:
Not open for further replies.

Share This Page