Class SessionUtils

java.lang.Object
me.axieum.mcmod.authme.api.util.SessionUtils

public final class SessionUtils extends Object
Utility methods for interacting with the Microsoft game session.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    The status of a Minecraft session.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The access token used for offline sessions.
    static final long
    The number of milliseconds that a session status is cached for.
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService
    Returns the Yggdrasil Authentication Service.
    static com.mojang.authlib.minecraft.MinecraftSessionService
    Returns the Yggdrasil Minecraft Session Service.
    Checks and returns the current Minecraft session status.
    static net.minecraft.client.User
    Returns the current Minecraft user.
    static net.minecraft.client.User
    offline(String username)
    Builds and returns a new offline Minecraft session.
    static void
    setUser(net.minecraft.client.User user)
    Replaces the Minecraft user instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • OFFLINE_TOKEN

      public static final String OFFLINE_TOKEN
      The access token used for offline sessions.
      See Also:
    • STATUS_TTL

      public static final long STATUS_TTL
      The 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

      public static net.minecraft.client.User offline(String username)
      Builds and returns a new offline Minecraft session.
      Parameters:
      username - custom username
      Returns:
      a new offline Minecraft session
      See Also:
    • getStatus

      public static CompletableFuture<SessionUtils.SessionStatus> 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