Search in sources :

Example 26 with Profile

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);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Profile(com.github.games647.craftapi.model.Profile)

Example 27 with 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));
}
Also used : Profile(com.github.games647.craftapi.model.Profile) SkinPropertyTest(com.github.games647.craftapi.model.skin.SkinPropertyTest) Test(org.junit.Test)

Example 28 with Profile

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));
}
Also used : Profile(com.github.games647.craftapi.model.Profile) SkinPropertyTest(com.github.games647.craftapi.model.skin.SkinPropertyTest) Test(org.junit.Test)

Aggregations

Profile (com.github.games647.craftapi.model.Profile)8 StoredProfile (com.github.games647.fastlogin.core.StoredProfile)7 SkinPropertyTest (com.github.games647.craftapi.model.skin.SkinPropertyTest)5 BukkitLoginSession (com.github.games647.fastlogin.bukkit.BukkitLoginSession)5 Test (org.junit.Test)5 BukkitFastLoginPremiumToggleEvent (com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPremiumToggleEvent)4 UUID (java.util.UUID)3 SkinModel (com.github.games647.changeskin.core.model.skin.SkinModel)2 SkinProperty (com.github.games647.craftapi.model.skin.SkinProperty)2 RateLimitException (com.github.games647.craftapi.resolver.RateLimitException)2 BukkitFastLoginPreLoginEvent (com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent)2 BungeeLoginSession (com.github.games647.fastlogin.bungee.BungeeLoginSession)2 IOException (java.io.IOException)2 ChangeSkinCore (com.github.games647.changeskin.core.ChangeSkinCore)1 SkinStorage (com.github.games647.changeskin.core.SkinStorage)1 GameProfile (com.github.games647.changeskin.core.model.GameProfile)1 UserPreference (com.github.games647.changeskin.core.model.UserPreference)1 Account (com.github.games647.changeskin.core.model.auth.Account)1 TextureType (com.github.games647.changeskin.core.model.skin.TextureType)1 SharedListener (com.github.games647.changeskin.core.shared.SharedListener)1