Package me.axieum.mcmod.authme.api.util
Class SessionUtils
java.lang.Object
me.axieum.mcmod.authme.api.util.SessionUtils
Utility methods for interacting with the Microsoft game session.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe status of a Minecraft session. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe access token used for offline sessions.static final longThe number of milliseconds that a session status is cached for. -
Method Summary
Modifier and TypeMethodDescriptionstatic com.mojang.authlib.yggdrasil.YggdrasilAuthenticationServiceReturns the Yggdrasil Authentication Service.static com.mojang.authlib.minecraft.MinecraftSessionServiceReturns the Yggdrasil Minecraft Session Service.Checks and returns the current Minecraft session status.static net.minecraft.client.UsergetUser()Returns the current Minecraft user.static net.minecraft.client.UserBuilds and returns a new offline Minecraft session.static voidsetUser(net.minecraft.client.User user) Replaces the Minecraft user instance.
-
Field Details
-
OFFLINE_TOKEN
The access token used for offline sessions.- See Also:
-
STATUS_TTL
public static final long STATUS_TTLThe number of milliseconds that a session status is cached for.- See Also:
-
-
Method Details
-
getUser
public static net.minecraft.client.User getUser()Returns the current Minecraft user.- Returns:
- current Minecraft user instance
-
setUser
public static void setUser(net.minecraft.client.User user) Replaces the Minecraft user instance.- Parameters:
user- new Minecraft user
-
offline
Builds and returns a new offline Minecraft session.- Parameters:
username- custom username- Returns:
- a new offline Minecraft session
- See Also:
-
getStatus
Checks and returns the current Minecraft session status.NB: This is an expensive task as it involves connecting to servers to validate any access tokens, and hence is executed on a separate thread.
The session status is cached for about 1 minute for subsequent calls.
- Returns:
- a completable future for the Minecraft session status
-
getSessionService
public static com.mojang.authlib.minecraft.MinecraftSessionService getSessionService()Returns the Yggdrasil Minecraft Session Service.- Returns:
- Yggdrasil Minecraft Session Service instance
-
getAuthService
public static com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService getAuthService()Returns the Yggdrasil Authentication Service.- Returns:
- Yggdrasil Authentication Service instance
-