Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/EngineHub/SquirrelID

Mojang profile / UUID lookup and last known UUID -> name cache Java library
https://github.com/EngineHub/SquirrelID

Last synced: 4 months ago
JSON representation

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

Awesome Lists containing this project

README

        

![SquirrelID](squirrelid-header.png)
==========

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

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

Or in bulk:

```java
ImmutableList profiles = resolver.findAllByName(Arrays.asList("Notch", "jeb_"));
```

And in parallel:

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

#### UUID -> Profile Cache

Choose a cache implementation:

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

Store entries:

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

Get the last known profile:

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

Bulk get last known profile:

```java
ImmutableMap results = cache.getAllPresent(Arrays.asList(uuid));
Profile profile = results.get(uuid); // May be null
```

#### Combined Resolver + Cache

Cache all resolved names:

```java
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

```xml


enginehub-repo
https://maven.enginehub.org/repo/

```

```xml


org.enginehub
squirrelid
0.3.0
compile
jar

```

#### Gradle

```groovy
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
-----

* [Visit our website](https://enginehub.org/)
* [Discord Guild](https://discord.gg/enginehub)