Player Name Bug?

Discussion in 'Plugin Development' started by ChucknorisSR, Jun 27, 2015.

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

    ChucknorisSR

    So my friend is new to coding so he asked me to help him out. He created a simple join message plugin but for some reason when the player joins it says: "Hi randy CraftPlayer{name=Ninjka}! I have never seen this before. Here is the code:
    Code:
    package main;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class main extends JavaPlugin implements Listener {
       
        @Override
        public void onEnable() {
            System.out.println("Welcome enabled!"); 
            getServer().getPluginManager().registerEvents(this, this);
           
        }
       
        @Override
        public void onDisable() {
            System.out.println("Welcome disabled!");
           
        }    
       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            Player p = (Player)e.getPlayer();
            p.sendMessage(ChatColor.DARK_RED + "Hi randy " + ChatColor.BLUE + e.getPlayer() + ChatColor.DARK_RED + "!");
        }
       
    }
    
     
  2. Offline

    Boomer

    Line 28
    It is writing the output of the getplayer player object to string on the screen, when you prob want it to be the getname from that gotten player...
     
  3. Offline

    poepdrolify

    e.getPlayer()#getName()
     
  4. Offline

    Rahat

  5. Offline

    tytwining

    As pretty much said above, getPlayer() returns a Player which contains the player's UUID, Location, etc, including the player's name. Player is NOT a string of the player's name. In order to get the name, use e.getPlayer().getName()
     
    Sulphate likes this.
  6. Offline

    Evaluations

    I'm almost positive you're lying. YOU are new to coding.
     
  7. Offline

    Boomer

    @Rahat -- User asked questions get the mail, no tag required...
     
Thread Status:
Not open for further replies.

Share This Page