Class AltAccount

java.lang.Object
lol.trq.alts.model.AltAccount

public final class AltAccount extends Object
An immutable Minecraft account stored locally within a client. Holds the credentials and metadata required to reconstruct a game session. Every field carries a SerializedName, which names the store file's format; only the library's own stores serialize an account, through an internal record of the same shape, so the store file keeps the shape it had when this was a record. A host's own Gson cannot read or write this class on the module path, and on the class path only by setting final fields through reflection: a host that persists accounts itself goes through the accessors and builder(String, String, String, AccountType).

A final class rather than a record since 1.0.0, so a later field is an addition and not a break: build one with of(String, String, String, AccountType), builder(String, String, String, AccountType) or toBuilder(), and derive copies with the withX methods. Two accounts are equal when every field is.

When this account lives in a shared repository, lastUsed/lastUsedBy and bans are shared state so members coordinate (who used it last, where it got banned). For a purely local account the attribution fields are null.

bans maps a serverId to a BanInfo — bans are per-server, because an account banned on one server may be fine on another. The serverId is an opaque, host-supplied string (the same namespace a host uses for game stats); the library never inspects a connection or detects a server. A null/empty map means "not known to be banned anywhere".

sourceClient/sourceUser record provenance for cross-client sharing: which client (mod) the alt was added from and the user within that client, so members of a shared repo can tell a given alt came from, say, one client's user versus another's. They are plain, opaque, implementer-set strings — the standard defines only the field names, never their values. Both are null for a purely local or unattributed account, and they ride inside the encrypted repo payload only (the sync server never sees them), preserving the zero-knowledge guarantee.

refreshToken and expiresAt back silent session renewal. The refresh token is a durable credential — far longer-lived than the access token — so it is stripped from a shared repository payload unless that repository has explicitly opted in. expiresAt is epoch millis and 0 means "unknown", which callers read as "assume expired and renew".

Since:
0.1.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Builds an AltAccount field by field.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the sensitive authentication token (OAuth, session, or cookie derived).
    boolean
    Returns whether this account is considered banned on any server.
    boolean
    banned(String serverId)
    Returns whether this account is considered banned on the given server.
    Returns the set of server ids on which this account is considered banned.
    Returns the locally-observed ban records keyed by server id, unmodifiable.
    builder(String uuid, String username, String accessToken, AccountType type)
    Starts an account with every other field empty: never used (lastUsed 0), unattributed, no bans, no refresh token, expiry unknown.
    boolean
    Returns whether o is an account with every field equal to this one's, the bans compared as maps.
    long
    Returns the epoch-millis expiry of accessToken().
    int
    Returns a hash over every field, consistent with equals(Object).
    boolean
    Returns whether this account carries a usable refresh token.
    long
    Returns the epoch-millis timestamp of the last successful login with this account.
    Returns the member id (Ed25519 identity) that last used this account in a shared repo.
    Returns this account's identity and credentials applied onto a record the store already holds, so re-authenticating an alt refreshes what it logs in with without discarding what the store learned about it.
    static AltAccount
    of(String uuid, String username, String accessToken, AccountType type)
    Creates a freshly authenticated account stamped as used at the current system time, unattributed.
    Returns the OAuth refresh token used to renew the session.
    Returns the client (mod) the alt was added from.
    Returns the user within sourceClient() that added the alt.
    Returns a builder holding every field of this account, to change several at once.
    Returns a description of this account with both credentials redacted.
    Returns the protocol used to authenticate this account.
    Returns a copy of this account with lastUsed refreshed to now, preserving any existing attribution.
    usedNow(String byMember)
    Returns a copy of this account stamped as used now by the given member — for attributing activity inside a shared repository.
    Returns the last known display name of the account.
    Returns the unique identifier of the Minecraft player.
    withBan(String serverId, BanInfo ban)
    Returns a copy of this account with the ban record for serverId set (or cleared).
    withSource(String sourceClient, String sourceUser)
    Returns a copy of this account stamped with its provenance — the client it was added from and the user within that client — for cross-client shared repositories.
    withTokens(String accessToken, String refreshToken, long expiresAt)
    Returns a copy of this account carrying freshly issued credentials, preserving attribution, bans, and provenance.
    withUsername(String username)
    Returns a copy of this account with its username replaced.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • of

      public static AltAccount of(String uuid, String username, String accessToken, AccountType type)
      Creates a freshly authenticated account stamped as used at the current system time, unattributed.
      Parameters:
      uuid - the player's UUID
      username - the player's username
      accessToken - the authentication token
      type - the authentication protocol used
      Returns:
      a new account with lastUsed set to now
      Since:
      0.1.0
    • builder

      public static AltAccount.Builder builder(String uuid, String username, String accessToken, AccountType type)
      Starts an account with every other field empty: never used (lastUsed 0), unattributed, no bans, no refresh token, expiry unknown. This is what the record's canonical constructor was for: an account rebuilt field by field, from a host's own storage, say.
      Parameters:
      uuid - the player's UUID
      username - the player's username
      accessToken - the authentication token
      type - the authentication protocol used
      Returns:
      a builder holding those four
      Since:
      1.0.0
    • toBuilder

      public AltAccount.Builder toBuilder()
      Returns a builder holding every field of this account, to change several at once.
      Returns:
      a builder that builds an account equal to this one until a field is changed
      Since:
      1.0.0
    • uuid

      public String uuid()
      Returns the unique identifier of the Minecraft player.
      Returns:
      the dashed UUID
      Since:
      0.1.0
    • username

      public String username()
      Returns the last known display name of the account.
      Returns:
      the username
      Since:
      0.1.0
    • accessToken

      public String accessToken()
      Returns the sensitive authentication token (OAuth, session, or cookie derived).
      Returns:
      the access token
      Since:
      0.1.0
    • type

      public AccountType type()
      Returns the protocol used to authenticate this account.
      Returns:
      the account type
      Since:
      0.1.0
    • lastUsed

      public long lastUsed()
      Returns the epoch-millis timestamp of the last successful login with this account.
      Returns:
      the last-used time, or 0 when never used
      Since:
      0.1.0
    • lastUsedBy

      public String lastUsedBy()
      Returns the member id (Ed25519 identity) that last used this account in a shared repo.
      Returns:
      the member id, or null when used locally / unattributed
      Since:
      0.1.0
    • bans

      public Map<String,BanInfo> bans()
      Returns the locally-observed ban records keyed by server id, unmodifiable.
      Returns:
      the bans, or null if never observed banned
      Since:
      0.5.0
    • sourceClient

      public String sourceClient()
      Returns the client (mod) the alt was added from.
      Returns:
      the source client, or null when unattributed
      Since:
      0.2.0
    • sourceUser

      public String sourceUser()
      Returns the user within sourceClient() that added the alt.
      Returns:
      the source user, or null
      Since:
      0.2.0
    • refreshToken

      public String refreshToken()
      Returns the OAuth refresh token used to renew the session.
      Returns:
      the refresh token, or null when the account has none (cookie, session, and offline accounts never do)
      Since:
      0.6.0
    • expiresAt

      public long expiresAt()
      Returns the epoch-millis expiry of accessToken().
      Returns:
      the expiry, or 0 when unknown
      Since:
      0.6.0
    • usedNow

      public AltAccount usedNow()
      Returns a copy of this account with lastUsed refreshed to now, preserving any existing attribution.
      Returns:
      a copy stamped as used now
      Since:
      0.1.0
    • usedNow

      public AltAccount usedNow(String byMember)
      Returns a copy of this account stamped as used now by the given member — for attributing activity inside a shared repository.
      Parameters:
      byMember - the member id (Ed25519 identity) that used the account, or null
      Returns:
      a copy stamped as used now by byMember
      Since:
      0.1.0
    • withBan

      public AltAccount withBan(String serverId, BanInfo ban)
      Returns a copy of this account with the ban record for serverId set (or cleared). Other servers' entries are preserved.
      Parameters:
      serverId - the server the ban applies to
      ban - the ban record, or null to clear this server's entry
      Returns:
      a copy with serverId's ban entry replaced
      Since:
      0.5.0
    • withUsername

      public AltAccount withUsername(String username)
      Returns a copy of this account with its username replaced. A username is mutable — a player can rename — so a validation that resolves the current one updates the stored record through this rather than leaving a stale display name behind.
      Parameters:
      username - the current username
      Returns:
      a copy carrying the given username
      Since:
      0.10.0
    • withSource

      public AltAccount withSource(String sourceClient, String sourceUser)
      Returns a copy of this account stamped with its provenance — the client it was added from and the user within that client — for cross-client shared repositories.
      Parameters:
      sourceClient - the client (mod) the alt was added from, or null to clear
      sourceUser - the user within sourceClient that added it, or null
      Returns:
      a copy carrying the given provenance
      Since:
      0.2.0
    • withTokens

      public AltAccount withTokens(String accessToken, String refreshToken, long expiresAt)
      Returns a copy of this account carrying freshly issued credentials, preserving attribution, bans, and provenance. Used by the renewal path, which must persist the rotated refresh token.
      Parameters:
      accessToken - the newly issued access token
      refreshToken - the newly issued refresh token, or null to clear it
      expiresAt - the epoch-millis expiry of accessToken, or 0 when unknown
      Returns:
      a copy carrying the given credentials
      Since:
      0.6.0
    • mergedOnto

      public AltAccount mergedOnto(AltAccount existing)
      Returns this account's identity and credentials applied onto a record the store already holds, so re-authenticating an alt refreshes what it logs in with without discarding what the store learned about it. Bans, provenance, and shared attribution come from existing unless this account carries its own, and a route that issues no refresh token leaves the stored one in place rather than clearing it. expiresAt is always this account's, because it describes this account's access token.
      Parameters:
      existing - the stored record for the same UUID, or null when the store holds none
      Returns:
      this account merged onto existing, or this account unchanged when there is none
      Since:
      0.6.0
    • hasRefreshToken

      public boolean hasRefreshToken()
      Returns whether this account carries a usable refresh token.
      Returns:
      true if a non-blank refresh token is present
      Since:
      0.6.0
    • banned

      public boolean banned(String serverId)
      Returns whether this account is considered banned on the given server.
      Parameters:
      serverId - the server to check
      Returns:
      true if a ban record for serverId is present and flags the account banned
      Since:
      0.5.0
    • banned

      public boolean banned()
      Returns whether this account is considered banned on any server.
      Returns:
      true if any server's ban record flags the account banned
      Since:
      0.1.0
    • bannedServers

      public Set<String> bannedServers()
      Returns the set of server ids on which this account is considered banned.
      Returns:
      an unmodifiable set of banned server ids (empty if none)
      Since:
      0.5.0
    • equals

      public boolean equals(Object o)
      Returns whether o is an account with every field equal to this one's, the bans compared as maps.
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare
      Returns:
      true when every field is equal
      Since:
      0.1.0
    • hashCode

      public int hashCode()
      Returns a hash over every field, consistent with equals(Object).
      Overrides:
      hashCode in class Object
      Returns:
      the hash
      Since:
      0.1.0
    • toString

      public String toString()
      Returns a description of this account with both credentials redacted. Printing the access and refresh tokens verbatim would let a host that logs an account — or anything embedding one, such as a login result — write a durable credential to disk. Identity and state stay readable, because that is what a log is for.
      Overrides:
      toString in class Object
      Returns:
      a loggable description carrying no credential
      Since:
      0.6.0