/SquirrelID

Mojang profile / UUID lookup and last known UUID -> name cache Java library

Primary LanguageJavaGNU Lesser General Public License v3.0LGPL-3.0

SquirrelID

SquirrelID is a Java library for working with Mojang profiles.

  • The resolution of UUIDs from player names in bulk.
  • The Resolution of player names from UUIDs in bulk.
  • "Last seen" UUID -> name cache implementations.
    • Available as SQLite-backed, MySQL-backed, or in-memory.
  • Thread-safe implementations.
  • Optional parallel fetching of UUIDs from player names.

Usage

Resolver

ProfileService resolver = HttpRepositoryService.forMinecraft();
Profile profile = resolver.findByName("Notch"); // May be null

Or in bulk:

ImmutableList<Profile> profiles = resolver.findAllByName(Arrays.asList("Notch", "jeb_"));

And in parallel:

int nThreads = 2; // Be kind
ProfileService resolver = HttpRepositoryService.forMinecraft();
ParallelProfileService service = new ParallelProfileService(resolver, nThreads);
service.findAllByName(Arrays.asList("Notch", "jeb_"), new Predicate<Profile>() {
    @Override
    public boolean apply(Profile input) {
        // Do something with the input
        return false;
    }
});

UUID -> Profile Cache

Choose a cache implementation:

File file = new File("cache.sqlite");
SQLiteCache cache = new SQLiteCache(file);

Store entries:

UUID uuid = UUID.fromString("069a79f4-44e9-4726-a5be-fca90e38aaf5");
cache.put(new Profile(uuid, "Notch"));

Get the last known profile:

Profile profile = cache.getIfPresent(uuid); // May be null

Bulk get last known profile:

ImmutableMap<UUID, Profile> results = cache.getAllPresent(Arrays.asList(uuid));
Profile profile = results.get(uuid); // May be null

Combined Resolver + Cache

Cache all resolved names:

ProfileCache cache = new HashMapCache(); // Memory cache

CacheForwardingService resolver = new CacheForwardingService(
        HttpRepositoryService.forMinecraft(),
        cache);

Profile profile = resolver.findByName("Notch");
Profile cachedProfile = cache.getIfPresent(profile.getUniqueId());

As a dependency

Note: We recommend shading or shadowing in SquirrelID for distribution, relocating the org.enginehub.squirrelid package to an internal package without your project.

Maven

<repositories>
    <repository>
        <id>enginehub-repo</id>
        <url>https://maven.enginehub.org/repo/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>org.enginehub</groupId>
        <artifactId>squirrelid</artifactId>
        <version>0.3.0</version>
        <scope>compile</scope>
        <type>jar</type>
    </dependency>
</dependencies>

Gradle

repositories {
    maven { url "https://maven.enginehub.org/repo/" }
}

dependencies {
    compile 'org.enginehub:squirrelid:0.3.0'
}

Compiling

Use Gradle to compile SquirrelID.

gradlew build

Some of the unit tests are actually integration tests and therefore make contact with Mojang's servers. That means that the tests may take a non-trivial amount of time to complete and may even fail if the Mojang profile servers are unreachable. In the future, these tests may be moved so that this becomes no longer an issue.

You can disable tests with:

gradlew -x test build

Contributing

SquirrelID is available under the GNU Lesser General Public License.

We happily accept contributions, especially through pull requests on GitHub.

Links