player.sendMessage apparently Null.

Discussion in 'Plugin Development' started by Samkio, Jan 29, 2011.

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

    Samkio

    Hey going crazy trying to get this to work,
    Basically when a user logs in i get the player that logged in and try to send them a messasge but it dosn't want to work.

    Console error:
    Show Spoiler

    Code:
    2011-01-29 13:02:08 [INFO] Done! For help, type "help" or "?"
    138 recipes
    Player logged in
    CraftPlayer{name=Samkio}
    29-Jan-2011 13:02:11 org.bukkit.plugin.SimplePluginManager callEvent
    SEVERE: Could not pass event PLAYER_LOGIN to Levelcraft
    java.lang.NullPointerException
            at org.bukkit.craftbukkit.entity.CraftPlayer.sendMessage(CraftPlayer.jav
    a:58)
            at com.bukkit.samkio.levelcraft.LCPlayerListener.onPlayerLogin(LCPlayerL
    istener.java:44)
            at org.bukkit.plugin.java.JavaPluginLoader.callEvent(JavaPluginLoader.ja
    va:153)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:216)
            at net.minecraft.server.ServerConfigurationManager.a(ServerConfiguration
    Manager.java:116)
            at net.minecraft.server.NetLoginHandler.b(SourceFile:113)
            at net.minecraft.server.NetLoginHandler.a(SourceFile:89)
            at net.minecraft.server.Packet1Login.a(SourceFile:46)
            at net.minecraft.server.NetworkManager.a(SourceFile:232)
            at net.minecraft.server.NetLoginHandler.a(SourceFile:53)
            at net.minecraft.server.NetworkListenThread.a(SourceFile:91)
            at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:265)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:201)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:512)
    2011-01-29 13:02:11 [INFO] Samkio [/127.0.0.1:52039] logged in with entity id 3
    Player count: 1


    And the code in question:
    Code:
    public void onPlayerLogin(PlayerLoginEvent event) {
            Player player = event.getPlayer();
    
            System.out.println("Player logged in");
            System.out.println("" + player);
            player.sendMessage(ChatColor.GOLD    + "Welcome player!");
    }
     
  2. Offline

    DerpinLlama

    Why are you printing the player object...? Use player.getName().
     
  3. Offline

    Samkio

    This is just a debug. To see if player actually exsisted.
     
  4. Offline

    DerpinLlama

    Try removing the colour bit.
     
  5. Offline

    Dinnerbone Bukkit Team Member

    At PLAYER_LOGIN, the player object only exists to provide details on who is logging in. Do not trust its methods. You only use this event for "they can log in" or "they can't". You're after PLAYER_JOIN.
     
  6. Offline

    Samkio

    Thankyou :)
    Changed too Player_Join and worked
    Much appreciated :)
     
Thread Status:
Not open for further replies.

Share This Page