Launcher/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java

53 lines
2.2 KiB
Java
Raw Normal View History

2018-09-17 10:07:32 +03:00
package com.mojang.authlib.yggdrasil;
import pro.gravit.launcher.profiles.PlayerProfile;
import pro.gravit.launcher.request.auth.CheckServerRequest;
import pro.gravit.launcher.request.auth.JoinServerRequest;
import pro.gravit.launcher.request.uuid.BatchProfileByUsernameRequest;
import pro.gravit.launcher.request.uuid.ProfileByUUIDRequest;
import pro.gravit.launcher.request.uuid.ProfileByUsernameRequest;
import pro.gravit.utils.helper.LogHelper;
2018-09-17 10:07:32 +03:00
2019-10-19 19:46:04 +03:00
import java.util.UUID;
2018-09-17 10:07:32 +03:00
// Used to bypass Launcher's class name obfuscation and access API
public class CompatBridge {
public static final int PROFILES_MAX_BATCH_SIZE = 128;
2018-09-17 10:07:32 +03:00
2020-04-05 10:27:04 +03:00
private CompatBridge() {
}
2018-09-17 10:07:32 +03:00
public static CompatProfile checkServer(String username, String serverID) throws Exception {
LogHelper.debug("CompatBridge.checkServer, Username: '%s', Server ID: %s", username, serverID);
2019-02-10 11:38:48 +03:00
return CompatProfile.fromPlayerProfile(new CheckServerRequest(username, serverID).request().playerProfile);
2018-09-17 10:07:32 +03:00
}
public static boolean joinServer(String username, String accessToken, String serverID) throws Exception {
// Join server
LogHelper.debug("LegacyBridge.joinServer, Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID);
2019-02-10 11:38:48 +03:00
return new JoinServerRequest(username, accessToken, serverID).request().allow;
2018-09-17 10:07:32 +03:00
}
public static CompatProfile profileByUsername(String username) throws Exception {
2019-02-10 11:38:48 +03:00
return CompatProfile.fromPlayerProfile(new ProfileByUsernameRequest(username).request().playerProfile);
2018-09-17 10:07:32 +03:00
}
public static CompatProfile profileByUUID(UUID uuid) throws Exception {
2019-02-10 11:38:48 +03:00
return CompatProfile.fromPlayerProfile(new ProfileByUUIDRequest(uuid).request().playerProfile);
2018-09-17 10:07:32 +03:00
}
public static CompatProfile[] profilesByUsername(String... usernames) throws Exception {
2019-02-10 11:38:48 +03:00
PlayerProfile[] profiles = new BatchProfileByUsernameRequest(usernames).request().playerProfiles;
2018-09-17 10:07:32 +03:00
// Convert profiles
CompatProfile[] resultProfiles = new CompatProfile[profiles.length];
for (int i = 0; i < profiles.length; i++)
2018-09-22 17:33:00 +03:00
resultProfiles[i] = CompatProfile.fromPlayerProfile(profiles[i]);
2018-09-17 10:07:32 +03:00
// We're dones
return resultProfiles;
}
}