PlayerLoginEvent.getHostname() not working?

Discussion in 'Plugin Development' started by TomShar, Jan 22, 2014.

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

    TomShar

    I've tried multiple servers using domains and just raw IP's to connect but nothing, the method never returns anything.

    Is it broken?
     
  2. Offline

    acecheesecr14

    Post the code?
     
  3. Offline

    TomShar

    it is in the title...
     
  4. What are you trying to do? Get the players host name? Or IP?
     
    acecheesecr14 likes this.
  5. Offline

    acecheesecr14

  6. acecheesecr14
    It's just a way of telling people what class the said method is in. If he would have made the title "getHostName()" or "e.getHostName()", it would be quite tough to figure out what method he is talking about.

    Also, your code does absolutely nothing. At least try to give proper examples.
     
  7. Offline

    TomShar

    Lionhard get the hostname that they use to connect to the server with. e.g domain.com
    which is .getHostname() but it returns nothing for some reason.
     
  8. Offline

    acecheesecr14


    It returns blank if its unknown...

    And there was nothing wrong with that example...
    Assist
    I asked for the code and he said in the title.. I corrected the code.
     
  9. Offline

    TomShar

    there was nothing to correct.
     
  10. acecheesecr14 idk maybe its because you use entity instead of player?

    EDIT: lol this post should go to TomShar I got confused and somehow mixed you two up. :D
     
    acecheesecr14 likes this.
  11. Offline

    RawCode

    learn to read source code (LoginListener), this field never set and always blank, left for upcoming versions (this you can read inside commit comment)
     
  12. Offline

    acecheesecr14

    Point taken... But it wasn't intended!
     
  13. TomShar Hey, actually, I think I found the problem. You use e.getPlayer().getHostname().
    Isn't it e.getPlayer().getAddress().getHostName(); ?
    Try that, maybe it works!
     
  14. acecheesecr14
    I'm not upset, I was just pointing out a mistake in your post, but you for some reason became hostile.

    What did I help you with? Well first, you didn't seem to know what Class.method() means, so I explained it to you. Second, I corrected your mistake of thinking that getHostName() returns a String, not a Player.

    Also, I don't help people and expect to get a thank you, but you kind of hinted me that you would say "Oh thank you...", so I'm waiting for my thank you :)

    Lastly, in the future, please merge your posts instead of posting several ones in a row.

    Edit: Lionhard correct me if I'm wrong, but I believe you have to call getAddress() twice in a row before getHostAddress().
     
  15. Assist I just tried it in eclipse and player.getAddress().getHostName() seemed to work. If you would use player.getAddress().getAddress() it should work too, but that would give you the IP, I believe. TomShar told he wants the domain he is connecting from (Probably the domain of the players internet provider. Sorry, I have no experience with this and how they are called its just like host-2.my-city.com or something like that).

    EDIT: Uhm, actually, you're right. player.getAddress().getAddress().getHostAddress() works too. :D
     
  16. Offline

    acecheesecr14

    Please quote the post where I became hostile, I shall quote yours.

    And also, does RawCode 's input not help anything here?

    This made me feel like it was wrong, and in my mind it made sense.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  17. acecheesecr14 How do you mean that? Sorry, didn't understand that. And Also it is actually really wrong what I told, I thought the e he uses is for entity, but that is actually the event. :oops:
     
  18. Offline

    acecheesecr14

    Well when you tagged me in it I saw it and though "Oh yeah that makes sense", I'm tired you see. But the code I posted wasn't wrong at all, I still changed it, thinking you were correct. But read the JavaDocs because they say that you can use the getHostname() function with the PlayerLoginEvent.
     
  19. acecheesecr14 You can do that actually even without that event and I did not tell your code is wrong. ;)
    Let's see when the creator of this thread comes on and checks for the help, I think it might solve his problem with doing player.getAddress().getHostName(). Even though your event.getPlayer().getHostName() might work too.
     
  20. Offline

    acecheesecr14

    Yeah you didn't mean too, you misstagged me in that post, not a problem bro.. But he is trying to get the hostname of the server (I think), and to me that looks like it will get the hostname of the player (?) Its entirely possible for the player to have a host name.. Mine is cpc5-croy22-2-0-cust465.19-2.cable.virginm.net
     
  21. acecheesecr14 Uhm... I don't think he can look for what wasthe player's input in the direct connect thingy, or in their favorites.
    And I thought he wants to check the hostname of the players and yes, I did also told that the players have a hostname, you must missunderstood me thinking that I'm telling that the players do not have a hostname.
    Yeah, by english is bad.

    Anyways, with this:
    get the hostname that they use to connect to the server with. e.g domain.com
    which is .getHostname() but it returns nothing for some reason.
    I understood that he wants to to get the hostname of the players who connects to the server.

    But if he wants to get the domain the players use to connect to the server,
    he is probably wrong with getHostname as this gets the player's host name, not what they put in at the connect.

    In this case, I think the problem is solved. :eek:
     
  22. Offline

    acecheesecr14

  23. acecheesecr14 :O

    acecheesecr14 In this case, here should be the solution:
    Code:java
    1. @EventHandler
    2. public void onPlayerLogin(PlayerLoginEvent event){
    3. String hostname = event.getHostname();
    4. // Do whatever you want
    5. }


    TomShar Try this! ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  24. Offline

    acecheesecr14

    Hahaha the JavaDocs are there for a reason... It explains why they were blank, i think that it gets the hostname from the server.properties (I'm not sure)...
    http://jd.bukkit.org/rb/apidocs/org/bukkit/event/player/PlayerLoginEvent.html#getHostname()

    ...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  25. acecheesecr14 "This post has been edited 4 times. It was last edited by acecheesecr14 38 minutes ago." I can't read it everytime you have edited it... :D Before it was something else.

    EDIT: Oh, and also: String hostname = event.getHostname();
    Thats the right way. ;)
     
  26. Offline

    acecheesecr14

  27. Offline

    acecheesecr14

  28. Offline

    RawCode

    getting IP of player and getting hostname player used for login is different things...
     
Thread Status:
Not open for further replies.

Share This Page