Getting player IP address PlayerLoginEvent

Discussion in 'Plugin Development' started by r0w, Jan 20, 2011.

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

    r0w

    Hi,

    I'd like to have the IP address of the player in PlayerLoginEvent, but :
    Code:
    public void onPlayerLogin (PlayerLoginEvent event)
        {
            Player player = event.getPlayer();
            System.out.println(player.getAddress());
        }
    isn't working at all :\

    And with PlayerEvent with PLAYER_JOIN event, this works fine :
    Code:
    event.getPlayer().getAddress().getAddress().getHostAddress()
    I'd like to keep PLAYER_LOGIN event, if possible
     
  2. Offline

    MadMichi

    Code:
    System.out.println(event.getPlayer().getAddress().toString());
    You are not getting a string, but a socket class ;)
     
  3. Offline

    r0w

    Oops, I copied the wrong code


    Code:
    public void onPlayerLogin (PlayerLoginEvent event)
    {
        Player player = event.getPlayer();
    
        System.out.println(player.getAddress().getAddress().getHostAddress());
        System.out.println("DAMN");
    
    }
    

    Stack Trace :

    Code:
    22 janv. 2011 00:47:23 org.bukkit.plugin.SimplePluginManager callEvent
    GRAVE: Could not pass event PLAYER_LOGIN to Sample Plugin
    java.lang.NullPointerException
            at org.bukkit.craftbukkit.entity.CraftPlayer.getAddress(CraftPlayer.java
    :37)
            at com.r0w.bukkit.sample.SamplePluginPlayer.onPlayerLogin(SamplePluginPl
    ayer.java:38)
            at org.bukkit.plugin.java.JavaPluginLoader.callEvent(JavaPluginLoader.ja
    va:149)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:199)
            at net.minecraft.server.ServerConfigurationManager.a(ServerConfiguration
    Manager.java:114)
            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:261)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:197)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:512)
     
  4. Offline

    MadMichi

    I was curious and made a test plugin. Now i know what you mean.
    There seems to be a bug in the PlayerLoginEvent.
    Because with the BlockDamageEvent for example it went fine to give out the address...
    Would you like to report the bug?
     
  5. Offline

    Raphfrk

    This was also true for hmod (the loginCheck hook only gave a player name string rather than a Player object). I wonder if the Player objects are actually in existence at that point in the login process?
     
  6. Offline

    r0w

    Many things still works, like getting the location of the player, getting the isOnline status, etc.

    Isn't is coming from a Player object? I didn't look at the code in bukkit :\

    By the way : I found an alternative to do what I wanted
     
  7. Offline

    MadMichi

    I tryed to save the player object on PlayerLoginEvent and then gained the address later. That actually worked. So the player object is present, but the address is not obtained at that certain moment.
     
  8. Offline

    Danza

    Please say how you did? I have the same problem ) Sample please if u can.
     
Thread Status:
Not open for further replies.

Share This Page