help, How to get the player name!

Discussion in 'Spigot Help' started by zabir, Jul 6, 2021.

  1. How to get Name of a player. Most likely when a player join the server. I want to say bukkit.broadcastMessage(" [Player_name] joined the server). So how to get the player name of the player. plz help!
  2. You’ll want to use the PlayerJoinEvent, and get the event player as a player. Then, just use .getName() to return the player’s username.

    For example:

    Code (Java):
    public void customJoin(PlayerJoinEvent e) {
        Player player = e.getPlayer();
        String username = player.getName();
        String msg =[player] joined da server :O”.    
        Bukkit.broadcastMessage(msg.replace([player]”, username));
  3. Thanks, that works :)