> For the complete documentation index, see [llms.txt](https://impoo.gitbook.io/authenticationsystem/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://impoo.gitbook.io/authenticationsystem/developers/playerdata.md).

# PlayerData

`PlayerData` is a Java `record` that represents a player's authentication data. It is immutable and carries all the fields stored in the `auth_players` database table.

## Definition

```java
public record PlayerData(
    String username,
    UUID uuid,
    String hashedPassword,
    String lastIp,
    Timestamp registeredAt,
    boolean premium
) {}
```

## Fields

| Field            | Type        | Description                                      |
| ---------------- | ----------- | ------------------------------------------------ |
| `username`       | `String`    | The player's username (VARCHAR(16))              |
| `uuid`           | `UUID`      | The player's unique identifier (VARCHAR(36))     |
| `hashedPassword` | `String`    | The BCrypt password hash (VARCHAR(60))           |
| `lastIp`         | `String`    | The player's last known IP address (VARCHAR(45)) |
| `registeredAt`   | `Timestamp` | The registration timestamp                       |
| `premium`        | `boolean`   | Whether the player is premium (TINYINT(1))       |

## Database mapping

| PlayerData field | `auth_players` column | Type        |
| ---------------- | --------------------- | ----------- |
| `username`       | `username`            | VARCHAR(16) |
| `uuid`           | `uuid`                | VARCHAR(36) |
| `hashedPassword` | `password_hash`       | VARCHAR(60) |
| `lastIp`         | `last_ip`             | VARCHAR(45) |
| `registeredAt`   | `registered_at`       | TIMESTAMP   |
| `premium`        | `premium`             | TINYINT(1)  |

## Example usage

```java
// Creating a PlayerData record
PlayerData data = new PlayerData(
    "Notch",
    player.getUniqueId(),
    "$2a$12$...", // BCrypt hash
    "192.168.1.1",
    new Timestamp(System.currentTimeMillis()),
    false
);

// Accessing fields
String username = data.username();
UUID uuid = data.uuid();
boolean isPremium = data.preamium();
```

## Using with AuthTable

```java
authTable.registerPlayer(playerData)
    .thenAccept(success -> {
        if (success) {
            getLogger().info("Player registered: " + playerData.username());
        }
    });
```

***

> :bulb: **Tip**: `PlayerData` is a record, so it is immutable. Use the accessor methods (`username()`, `uuid()`, etc.) to read fields.
