alts

A Minecraft Java Edition account library for sign-in, account management, an encrypted store and a shared vault.

Examples

Illustrative, dependency-free samples. They are compiled by the examples Gradle source set (so they cannot drift from the library API) but are not part of the published jar.

GettingStartedExample

The compiled companion to ../docs/GETTING_STARTED.md. Every snippet that guide shows is a method here, one per section:

The file is compiled with -Xlint:deprecation -Werror, so it cannot use deprecated API.

SharedVaultExample

The AVP 0.5 shared vault end to end: createRepository (a first contact whose host key the user confirms out of band before anything is created, the owner key kept as its entropy, the snapshot in the host secrets), requestInvite and join on the joiner’s side, invite on the owner’s after comparing fingerprints, resumeOwner (the owner key and the snapshot back out of the host secrets), and shareAndSync, which resumes from the snapshot, shares an account, renews another with update (which never reverts a field another member changed), syncs and acts on the report. Compiled the same way, and inlined into the guide’s “Shared vault” section.

Both files are the authoritative copy; the guide inlines from them. Change the library API and the build breaks here, which is the point: markdown alone rots silently. Keep the two in step when either moves. Spotless formats this directory too, so a snippet pasted into the guide is already house-styled.

ExampleNetGameStatsSource

A minimal GameStatsSource for a fictional example.net server. It shows the whole shape of the feature: a source reports a serverId and returns ready-to-render GameStats.Stat chips; the library only caches them.

Wire it and read it back:

AltsRuntime<MyHandle> alts = new AltsRuntime.Builder<MyHandle>()
        .sessionInjector(...)
        .vaultDirectory(...)
        .mainThread(...)
        .toastSink(...)
        .gameStatsSource(new ExampleNetGameStatsSource())   // one per server; call again for more
        .build();

// uuid -> stats for example.net (null on the first call while the background fetch runs,
// then the chips on a later call; unknown server ids return null forever).
GameStats stats = alts.gameStats("example.net").get(playerUuid);
if (stats != null) {
    for (GameStats.Stat chip : stats.stats()) {
        render(chip.label(), chip.value());   // e.g. "rank Veteran", "wins 128"
    }
}

For a static, in-memory source (handy for tests and demos), use the shipped StaticGameStatsSource:

var source = new StaticGameStatsSource(
        "example.net",
        Map.of(playerUuid, List.of(new GameStats.Stat("rank", "Veteran"))));