PlayerUtils
Table of Contentsโ
Class Definitionโ
export abstract class PlayerUtils {}
PlayerUtils is an abstract utility class. All members are static โ it cannot be instantiated directly.
Methodsโ
getGuildDir()โ
static getGuildDir(guildId: string): stringReturns the absolute path to the JSON storage directory for the given guild. Equivalent to
{playersBaseDir}/{guildId}.Parametersโ
Parameter Type Description Optional guildIdstring The guild ID. Returnsโ
Type Description string Absolute path to the guild's data directory.
getPlayerCurrentPath()โ
static getPlayerCurrentPath(guildId: string): stringReturns the absolute path to
current.jsonfor the given guild.Parametersโ
Parameter Type Description Optional guildIdstring The guild ID. Returnsโ
Type Description string Absolute path to current.json.
getPlayerPreviousPath()โ
static getPlayerPreviousPath(guildId: string): stringReturns the absolute path to
previous.jsonfor the given guild.Parametersโ
Parameter Type Description Optional guildIdstring The guild ID. Returnsโ
Type Description string Absolute path to previous.json.
getPlayerQueuePath()โ
static getPlayerQueuePath(guildId: string): stringReturns the absolute path to
queue.jsonfor the given guild.Parametersโ
Parameter Type Description Optional guildIdstring The guild ID. Returnsโ
Type Description string Absolute path to queue.json.
getPlayerStatePath()โ
static getPlayerStatePath(guildId: string): stringReturns the absolute path to
state.jsonfor the given guild.Parametersโ
Parameter Type Description Optional guildIdstring The guild ID. Returnsโ
Type Description string Absolute path to state.json.
getPlayersBaseDir()โ
static getPlayersBaseDir(): stringReturns the absolute path to the root directory used by the JSON storage backend:
{cwd}/magmastream/sessionData/players.Returnsโ
Type Description string The base directory for all player data files.
getRedisKey()โ
static getRedisKey(): stringReturns the Redis key prefix used for player storage, derived from
stateStorage.redisConfig.prefix. Trailing colons are normalised and a single trailing colon is always appended (e.g."magmastream:").Returnsโ
Type Description string The normalised Redis key prefix.
init()โ
static init(manager: Manager): voidInitializes the static
Managerreference used byPlayerUtils. Called internally by the manager.Parametersโ
Parameter Type Description Optional managerManagerThe Manager instance.
serializePlayer()โ
static async serializePlayer(player: Player): Promise<SerializedPlayerState | null>Serializes a
Playerinstance into a JSON-safe snapshot, stripping non-serializable values (functions, symbols,Map,Set, sockets, timers, etc.). Returnsnullif serialization fails.Parametersโ
Parameter Type Description Optional playerPlayerThe player to serialize. Returnsโ
Type Description Promise< SerializedPlayerState| null>The serialized snapshot, or nullon failure.