OfflinePlayer Game Profile

Discussion in 'Spigot Plugin Development' started by FrostedSnowman, Apr 22, 2017.

  1. FrostedSnowman

    Resource Staff

    how would i get an offline player game profile?

    ex:
    notch's game profile.

    i've tried this, but it returns an empty properties map.

    Code (Java):

    CraftOfflinePlayer offlinePlayer = (CraftOfflinePlayer) Bukkit.getOfflinePlayer("Notch");
    GameProfile gameProfileO =  offlinePlayer.getProfile();
    System.out.println(gameProfileO.getProperties());
    System.out.println(gameProfileO.getProperties().get("textures"));
    Code (Text):

    [21:34:14 INFO]: {}
    [21:34:14 INFO]: []
     
  2. Has notch ever played on your server? Nope.
     
    • Agree Agree x 1
  3. FrostedSnowman

    Resource Staff

    thats not what i am asking, essentially. im asking how i would be able to get an offline player's game profile with the filled properties
     
  4. Like this?
    Code (Text):
    Bukkit.getOfflinePlayer(name);
    I assume you're too intelligent to not have figured that out. But, just seeing :)
    Edit: Oh, there was a scroll to you're code, sorry, didn't see it
     
    • Friendly Friendly x 1
  5. FrostedSnowman

    Resource Staff

    yeah, thats basically what i've tried.

    im seeing how i could get a user's game profile in general (hasn't joined before in this case).
     
  6. Oh I see, like fetching their data? What is it you're trying to get? UUIDs? IPs?
    On second thought, don't think you could get IPs if they haven't logged in lol
     
  7. FrostedSnowman

    Resource Staff

    im trying to get the texture value in their game profile. such as getting the game profile / skin data from a user such as Notch.

    im trying to fetch skin data, not get data from a player that possibly hasn't joined before.
     
  8. Simply use mojang's API.

    https://sessionserver.mojang.com/session/minecraft/profile/

    Code (Text):
     
    static private JsonParser parser = new JsonParser();
    static private String API_PROFILE_LINK = "https://sessionserver.mojang.com/session/minecraft/profile/";

    public static String getSkinUrl(String uuid){
            String json = getContent(API_PROFILE_LINK + uuid);
            JsonObject o = parser.parse(json).getAsJsonObject();
            String jsonBase64 = o.get("properties").getAsJsonArray().get(0).getAsJsonObject().get("value").getAsString();
       
            o = parser.parse(new String(Base64.decodeBase64(jsonBase64))).getAsJsonObject();
            String skinUrl = o.get("textures").getAsJsonObject().get("SKIN").getAsJsonObject().get("url").getAsString();
            return skinUrl;
    }

    public static String getContent(String link){
            try {
                URL url = new URL(link);
                HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

                BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));

                String inputLine;
                while ((inputLine = br.readLine()) != null) {
                        return inputLine;
                }
                br.close();
           
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
    }
     
    • Like Like x 1
  9. FrostedSnowman

    Resource Staff

    great! i will try it out, now.
     
  10. You're trying to get a offlinePlayer's data. This won't exist if the player has never joined the server. If you said what you wanted instead of his "game profile" you would have it solved earlier :)
     
  11. FrostedSnowman

    Resource Staff