1. Jongh

    Jongh Member

    Jongh
    VIP
    Messages:
    49
    So I'm currently trying to get the session of a player, but I don't exactly understand how to accomplish this.

    I was taking a look at the getSession example: https://github.com/HypixelDev/Publi...va/net/hypixel/example/GetSessionExample.java

    And I'm sort of lost.

    So I understand that once I get a SessionReply, I can get the Session from that and then use whatever information from that. But how do I get the SessionReply?

    Looking at the example code I linked, it looks like it first sets an API key, then creates a new request for a player of type sessionreply, then it makes a request using getASync to an instance of the api. But then how do I get the session and save it somewhere so I can access it? And why is there a method defined within in arguments of the getASync method?

    If someone could help me out that'd be wonderful.
     
    #1
    • Funny Funny x 1
  2. #2
    • Funny Funny x 1
  3. Initially you have to set your personal API key (do /api on the server). Then the request gets created.
    In this example it will asynchronously request what you're asking for. Because it's asynchronously you have to provide a callback instance (it's implemented as an anonymous class).
    "result" is the actual reply you get, which is somewhat a wrapper for the text response you're receiving. SessionReply#getSession() will return the JSON of the session information as a JsonObject. You can use Gson to extract the information you need / want.
    EDIT: Check out the Sync example and that'll be much less confusing :) You can synchronously request everything aswell, although there is only one example for it - it's pretty straight forward.

    Just use this in your browser to see what's happening. The API provides classes like SessionReply to help you deal with the information you're getting. Just look inside of them, what they're doing!

    I would assume that you have to catch up with general Java knowledge at first to understand it, but incase someone else reads this here and is wondering^
    This is a Java (programming language) implementation to help requesting and using information the public API provides.
     
    #3
    • Funny Funny x 1

Share This Page