[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / playerIdentity

# playerIdentity

## Interfaces

### PlayerIdentity

Defined in: [packages/prismarine/src/playerIdentity.ts:26](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/playerIdentity.ts#L26)

The three names a login gives a player.

#### Properties

##### linkedFrom?

> `readonly` `optional` **linkedFrom?**: [`Subject`](https://jsprismarine.dev/api/@jsprismarine/prismarine/identity/Subject/index.md#subject)

Defined in: [packages/prismarine/src/playerIdentity.ts:39](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/playerIdentity.ts#L39)

The account the player logged in with, when a link made them play as another: see
`AccountLinks`. The other fields are then the primary account's.

##### name

> `readonly` **name**: `string`

Defined in: [packages/prismarine/src/playerIdentity.ts:28](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/playerIdentity.ts#L28)

The display name.

##### subject

> `readonly` **subject**: [`Subject`](https://jsprismarine.dev/api/@jsprismarine/prismarine/identity/Subject/index.md#subject)

Defined in: [packages/prismarine/src/playerIdentity.ts:34](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/playerIdentity.ts#L34)

Who the player is to the permission files: see [Subject](https://jsprismarine.dev/api/@jsprismarine/prismarine/identity/Subject/index.md#subject).

##### uuid

> `readonly` **uuid**: `string`

Defined in: [packages/prismarine/src/playerIdentity.ts:32](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/playerIdentity.ts#L32)

The protocol identity, as a UUID string.

##### xuid

> `readonly` **xuid**: `string`

Defined in: [packages/prismarine/src/playerIdentity.ts:30](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/playerIdentity.ts#L30)

The Xbox Live id, or an empty string when the login carried none.

## Functions

### isJavaLogin()

> **isJavaLogin**(`__namedParameters`): `boolean`

Defined in: [packages/prismarine/src/playerIdentity.ts:74](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/playerIdentity.ts#L74)

Whether the login came from a Java Edition client, as its subject records.

#### Parameters

##### \_\_namedParameters

`Pick`\<[`PlayerIdentity`](#playeridentity), `"subject"`\>

#### Returns

`boolean`

***

### keyOfPlayer()

> **keyOfPlayer**(`player`): `string`

Defined in: [packages/prismarine/src/playerIdentity.ts:117](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/playerIdentity.ts#L117)

[playerKeyOf](#playerkeyof) for a player object, whose `getXUID` answers null for no XUID.

#### Parameters

##### player

The player.

###### getName

() => `string`

###### getSubject?

() => [`Subject`](https://jsprismarine.dev/api/@jsprismarine/prismarine/identity/Subject/index.md#subject)

###### getXUID

() => `string` \| `null`

#### Returns

`string`

The player's key.

***

### playerKeyOf()

> **playerKeyOf**(`identity`): `string`

Defined in: [packages/prismarine/src/playerIdentity.ts:62](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/playerIdentity.ts#L62)

The key per-player services and the saved player record use: the XUID, or the name when there
is no XUID.

Not the UUID. On an offline-mode server the UUID is drawn per client install, so a returning
player on another device would not find their own record, while the name is what they type
each time. On an online-mode server the XUID is the verified account and survives a gamertag
change, and the UUID is derived from it, so the two give the same answer. The record has been
filed under this key since before services existed, and keeping one key for both means a
service and the record can never disagree about whose state they hold.

A Java Edition account has no XUID, and its name may be a Bedrock player's too, so it is keyed
by its profile UUID, under a `java:` prefix no name can carry. On an offline-mode server that
UUID is the one vanilla derives from the name, so a returning Java player finds their record.

Unique among live players because [sameAccount](#sameaccount) matches on the key as well as the name and
the XUID.

#### Parameters

##### identity

`Pick`\<[`PlayerIdentity`](#playeridentity), `"name"` \| `"xuid"`\> & `Partial`\<`Pick`\<[`PlayerIdentity`](#playeridentity), `"subject"`\>\>

The player's name, XUID and, where known, subject.

#### Returns

`string`

The XUID when there is one, a Java account's UUID, otherwise the name.

***

### sameAccount()

> **sameAccount**(`a`, `b`): `boolean`

Defined in: [packages/prismarine/src/playerIdentity.ts:93](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/playerIdentity.ts#L93)

Whether two identities belong to the same account, for the purpose of letting only one of them
be live at a time.

Any one of the three is enough. The name and XUID cover [playerKeyOf](#playerkeyof) for most logins, and
the key itself is compared too: an offline login named `123` with no XUID has the key of a
player whose XUID is `123`, and the two would read and write one saved record. The UUID is what
the player list and the operator list are keyed by, so two live players sharing one would
collide there. An empty XUID matches nothing: every player on an offline-mode server has one.

A Java login and a Bedrock login are different accounts even when they share a name, unless a
link made them one, so the name and XUID are compared only within one edition.

#### Parameters

##### a

[`PlayerIdentity`](#playeridentity)

One identity.

##### b

[`PlayerIdentity`](#playeridentity)

The other.

#### Returns

`boolean`

True when the two share a name, a non-empty XUID, a UUID or a [playerKeyOf](#playerkeyof) key.
