Search in sources :

Example 1 with Platform

use of no.stelar7.api.l4j8.basic.constants.api.Platform in project L4J8 by stelar7.

the class MatchHistoryCrawler method getGamesFromDatabase.

private List<Pair<Long, Platform>> getGamesFromDatabase(Long accountid, Platform platformid) throws SQLException {
    List<Pair<Long, Platform>> data = new ArrayList<>();
    matchCheck.setLong(1, accountid);
    matchCheck.setString(2, platformid.name());
    try (ResultSet rs = matchCheck.executeQuery()) {
        while (rs.next()) {
            data.add(new Pair(rs.getLong("gameid"), Platform.getFromCode(rs.getString("platformid")).get()));
        }
        return data;
    }
}
Also used : Pair(no.stelar7.api.l4j8.basic.utils.Pair)

Example 2 with Platform

use of no.stelar7.api.l4j8.basic.constants.api.Platform in project L4J8 by stelar7.

the class MasteryAPI method getChampionMastery.

/**
 * The response object contains the summoners mastery of a champion.
 * Only championid and summonerid is present if the level == 0
 *
 * @param server     the region to execute against
 * @param summonerId the summonerId
 * @param championId the championId
 * @return Optional ChampionMastery
 */
public ChampionMastery getChampionMastery(Platform server, long summonerId, int championId) {
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, String.valueOf(summonerId)).withURLParameter(Constants.CHAMPION_ID_PLACEHOLDER, String.valueOf(championId)).withEndpoint(URLEndpoint.V3_MASTERY_BY_CHAMPION).withPlatform(server);
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_MASTERY_BY_CHAMPION, server, summonerId, championId);
    if (chl.isPresent()) {
        return (ChampionMastery) chl.get();
    }
    Object masteryObj = builder.build();
    if (masteryObj instanceof Pair) {
        try {
            ChampionMastery mastery = new ChampionMastery();
            Field player = mastery.getClass().getDeclaredField("playerId");
            player.setAccessible(true);
            player.set(mastery, summonerId);
            Field champ = mastery.getClass().getDeclaredField("championId");
            champ.setAccessible(true);
            champ.set(mastery, championId);
            Field level = mastery.getClass().getDeclaredField("championLevel");
            level.setAccessible(true);
            level.set(mastery, 0);
            DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_BY_CHAMPION, mastery, server, summonerId, championId);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            Logger.getGlobal().warning("Class has changed, please fix me");
        }
    }
    DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_BY_CHAMPION, masteryObj, server, summonerId, championId);
    return (ChampionMastery) masteryObj;
}
Also used : Field(java.lang.reflect.Field) ChampionMastery(no.stelar7.api.l4j8.pojo.championmastery.ChampionMastery) Pair(no.stelar7.api.l4j8.basic.utils.Pair)

Example 3 with Platform

use of no.stelar7.api.l4j8.basic.constants.api.Platform in project L4J8 by stelar7.

the class StaticAPI method getLanguageStrings.

public Map<String, String> getLanguageStrings(Platform server, @Nullable String version, @Nullable String locale) {
    DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V3_STATIC_LANGUAGE_STRINGS).withURLData(Constants.URL_PARAM_DATA_BY_ID, String.valueOf(true)).withPlatform(server);
    if (version != null) {
        builder.withURLData(Constants.VERSION_PLACEHOLDER_DATA, version);
    }
    if (locale != null) {
        builder.withURLData(Constants.LOCALE_PLACEHOLDER_DATA, locale);
    }
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_STATIC_LANGUAGE_STRINGS, server, version, locale);
    if (chl.isPresent()) {
        return ((LanguageStrings) chl.get()).getData();
    }
    try {
        LanguageStrings list = (LanguageStrings) builder.build();
        DataCall.getCacheProvider().store(URLEndpoint.V3_STATIC_LANGUAGE_STRINGS, list, server, version, locale);
        return list.getData();
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : LanguageStrings(no.stelar7.api.l4j8.pojo.staticdata.language.LanguageStrings)

Example 4 with Platform

use of no.stelar7.api.l4j8.basic.constants.api.Platform in project L4J8 by stelar7.

the class StaticAPI method getRealm.

public Realm getRealm(Platform server) {
    DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V3_STATIC_REALMS).withURLData(Constants.URL_PARAM_DATA_BY_ID, String.valueOf(true)).withPlatform(server);
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_STATIC_REALMS, server);
    if (chl.isPresent()) {
        return (Realm) chl.get();
    }
    try {
        Realm list = (Realm) builder.build();
        DataCall.getCacheProvider().store(URLEndpoint.V3_STATIC_REALMS, list, server);
        return list;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : Realm(no.stelar7.api.l4j8.pojo.staticdata.realm.Realm)

Example 5 with Platform

use of no.stelar7.api.l4j8.basic.constants.api.Platform in project L4J8 by stelar7.

the class StatusAPI method getShardStatus.

public ShardStatus getShardStatus(Platform server) {
    DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V3_SHARD_STATUS).withPlatform(server);
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_SHARD_STATUS, server);
    if (chl.isPresent()) {
        return (ShardStatus) chl.get();
    }
    try {
        ShardStatus list = (ShardStatus) builder.build();
        DataCall.getCacheProvider().store(URLEndpoint.V3_SHARD_STATUS, list, server);
        return list;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : ShardStatus(no.stelar7.api.l4j8.pojo.status.ShardStatus) Optional(java.util.Optional)

Aggregations

Optional (java.util.Optional)4 Summoner (no.stelar7.api.l4j8.pojo.summoner.Summoner)3 Pair (no.stelar7.api.l4j8.basic.utils.Pair)2 Realm (no.stelar7.api.l4j8.pojo.staticdata.realm.Realm)2 Field (java.lang.reflect.Field)1 ChampionMastery (no.stelar7.api.l4j8.pojo.championmastery.ChampionMastery)1 LanguageStrings (no.stelar7.api.l4j8.pojo.staticdata.language.LanguageStrings)1 ShardStatus (no.stelar7.api.l4j8.pojo.status.ShardStatus)1