use of com.github.games647.craftapi.model.Profile in project CraftAPI by games647.
the class MojangResolver method findProfile.
@Override
public Optional<Profile> findProfile(String name) throws IOException, RateLimitException {
Optional<Profile> optProfile = cache.getByName(name);
if (optProfile.isPresent() || !validNamePredicate.test(name)) {
return optProfile;
}
String url = UUID_URL + name;
HttpURLConnection conn = getConnection(url);
int responseCode = conn.getResponseCode();
if (responseCode == RateLimitException.RATE_LIMIT_RESPONSE_CODE) {
if (conn.usingProxy()) {
throw new RateLimitException();
}
conn = getProxyConnection(url);
responseCode = conn.getResponseCode();
}
if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
return Optional.empty();
}
// todo: print errorstream on IOException
Profile profile = readJson(conn.getInputStream(), Profile.class);
cache.add(profile);
return Optional.of(profile);
}
use of com.github.games647.craftapi.model.Profile in project CraftAPI by games647.
the class MemoryCacheTest method removeProfile.
@Test
public void removeProfile() throws Exception {
Profile testProfile = new Profile(UUID.randomUUID(), "123ABC_abc");
cache.add(testProfile);
cache.remove(new Profile(UUID.randomUUID(), "123"));
assertThat(cache.getById(testProfile.getId()).isPresent(), is(true));
assertThat(cache.getByName(testProfile.getName()).isPresent(), is(true));
cache.remove(testProfile);
assertThat(cache.getById(testProfile.getId()).isPresent(), is(false));
assertThat(cache.getByName(testProfile.getName()).isPresent(), is(false));
}
use of com.github.games647.craftapi.model.Profile in project CraftAPI by games647.
the class MemoryCacheTest method profileCaseInsensitive.
@Test
public void profileCaseInsensitive() throws Exception {
Profile profile = new Profile(UUID.randomUUID(), "123ABC_abc");
cache.add(profile);
// all lower case + all upper case + mixed
assertThat(cache.getByName("123abc_abc").orElse(null), is(profile));
assertThat(cache.getByName("123ABC_ABC").orElse(null), is(profile));
assertThat(cache.getByName("123abc_ABC").orElse(null), is(profile));
}
Aggregations