Search in sources :

Example 6 with ChampionMastery

use of no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery in project L4J8 by stelar7.

the class ChampionMasteryBuilder method getChampionMastery.

public ChampionMastery getChampionMastery() {
    if (this.championId == null || this.summonerId == null || this.platform == Platform.UNKNOWN) {
        return null;
    }
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, String.valueOf(this.summonerId)).withURLParameter(Constants.CHAMPION_ID_PLACEHOLDER, String.valueOf(this.championId)).withEndpoint(URLEndpoint.V3_MASTERY_BY_CHAMPION).withPlatform(this.platform);
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_MASTERY_BY_CHAMPION, this.platform, this.summonerId, this.championId);
    if (chl.isPresent()) {
        return (ChampionMastery) chl.get();
    }
    Object masterObj = builder.build();
    if (masterObj instanceof Pair) {
        try {
            ChampionMastery mastery = new ChampionMastery();
            Field player = mastery.getClass().getDeclaredField("playerId");
            player.setAccessible(true);
            player.set(mastery, this.summonerId);
            Field champ = mastery.getClass().getDeclaredField("championId");
            champ.setAccessible(true);
            champ.set(mastery, this.championId);
            Field level = mastery.getClass().getDeclaredField("championLevel");
            level.setAccessible(true);
            level.set(mastery, 0);
            DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_BY_CHAMPION, mastery, this.platform, this.summonerId, this.championId);
            return mastery;
        } catch (NoSuchFieldException | IllegalAccessException e) {
            Logger.getGlobal().warning("Class has changed, please fix me");
        }
    }
    DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_BY_CHAMPION, masterObj, this.platform, this.summonerId, this.championId);
    return (ChampionMastery) masterObj;
}
Also used : Field(java.lang.reflect.Field) ChampionMastery(no.stelar7.api.l4j8.pojo.championmastery.ChampionMastery) Pair(no.stelar7.api.l4j8.basic.utils.Pair)

Example 7 with ChampionMastery

use of no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery in project L4J8 by stelar7.

the class ChampionMasteryBuilder method getChampionMastery.

public ChampionMastery getChampionMastery() {
    if (this.championId == null || this.summonerId == null || this.platform == LeagueShard.UNKNOWN) {
        return null;
    }
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, this.summonerId).withURLParameter(Constants.CHAMPION_ID_PLACEHOLDER, String.valueOf(this.championId)).withEndpoint(URLEndpoint.V4_MASTERY_BY_CHAMPION).withPlatform(this.platform);
    Map<String, Object> data = new TreeMap<>();
    data.put("platform", platform);
    data.put("id", summonerId);
    data.put("champion", championId);
    Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
    if (chl.isPresent()) {
        return (ChampionMastery) chl.get();
    }
    Object masterObj = builder.build();
    if (masterObj instanceof Pair) {
        try {
            ChampionMastery mastery = new ChampionMastery();
            Field player = mastery.getClass().getDeclaredField("playerId");
            player.setAccessible(true);
            player.set(mastery, this.summonerId);
            Field champ = mastery.getClass().getDeclaredField("championId");
            champ.setAccessible(true);
            champ.set(mastery, this.championId);
            Field level = mastery.getClass().getDeclaredField("championLevel");
            level.setAccessible(true);
            level.set(mastery, 0);
            data.put("value", mastery);
            DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
            return mastery;
        } catch (NoSuchFieldException | IllegalAccessException e) {
            Logger.getGlobal().warning("Class has changed, please fix me");
        }
    }
    data.put("value", masterObj);
    DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
    return (ChampionMastery) masterObj;
}
Also used : Field(java.lang.reflect.Field) ChampionMastery(no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery) Pair(no.stelar7.api.r4j.basic.utils.Pair)

Example 8 with ChampionMastery

use of no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery in project L4J8 by stelar7.

the class ChampionMasteryTest method testChampionMasteryAll.

@Test
public void testChampionMasteryAll() {
    String id = new SpectatorBuilder().withPlatform(LeagueShard.EUW1).getFeaturedGames().get(0).getParticipants().get(0).getSummonerName();
    Summoner s = new SummonerBuilder().withPlatform(LeagueShard.EUW1).withName(id).get();
    List<ChampionMastery> all = new ChampionMasteryBuilder().withPlatform(s.getPlatform()).withSummonerId(s.getSummonerId()).getChampionMasteries();
    assert all != null;
}
Also used : Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) ChampionMasteryBuilder(no.stelar7.api.r4j.impl.lol.builders.championmastery.ChampionMasteryBuilder) SummonerBuilder(no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder) ChampionMastery(no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery) SpectatorBuilder(no.stelar7.api.r4j.impl.lol.builders.spectator.SpectatorBuilder)

Example 9 with ChampionMastery

use of no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery in project L4J8 by stelar7.

the class ChampionMasteryTest method testChampionMasteryTop.

@Test
public void testChampionMasteryTop() {
    String id = new SpectatorBuilder().withPlatform(LeagueShard.EUW1).getFeaturedGames().get(0).getParticipants().get(0).getSummonerName();
    Summoner s = new SummonerBuilder().withPlatform(LeagueShard.EUW1).withName(id).get();
    List<ChampionMastery> all = new ChampionMasteryBuilder().withPlatform(s.getPlatform()).withSummonerId(s.getSummonerId()).getTopChampions(null);
    assert all != null;
}
Also used : Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) ChampionMasteryBuilder(no.stelar7.api.r4j.impl.lol.builders.championmastery.ChampionMasteryBuilder) SummonerBuilder(no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder) ChampionMastery(no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery) SpectatorBuilder(no.stelar7.api.r4j.impl.lol.builders.spectator.SpectatorBuilder)

Example 10 with ChampionMastery

use of no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery in project L4J8 by stelar7.

the class ChampionMasteryTest method testChampionMastery.

@Test
public void testChampionMastery() {
    String id = new SpectatorBuilder().withPlatform(LeagueShard.EUW1).getFeaturedGames().get(0).getParticipants().get(0).getSummonerName();
    Summoner s = new SummonerBuilder().withPlatform(LeagueShard.EUW1).withName(id).get();
    ChampionMastery mastery;
    ChampionMasteryBuilder bu = new ChampionMasteryBuilder().withPlatform(s.getPlatform()).withSummonerId(s.getSummonerId());
    mastery = bu.withChampionId(1).getChampionMastery();
    assert mastery != null;
    mastery = bu.withChampionId(2).getChampionMastery();
    assert mastery != null;
}
Also used : Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) ChampionMasteryBuilder(no.stelar7.api.r4j.impl.lol.builders.championmastery.ChampionMasteryBuilder) SummonerBuilder(no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder) ChampionMastery(no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery) SpectatorBuilder(no.stelar7.api.r4j.impl.lol.builders.spectator.SpectatorBuilder)

Aggregations

ChampionMastery (no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery)6 Field (java.lang.reflect.Field)4 ChampionMastery (no.stelar7.api.l4j8.pojo.championmastery.ChampionMastery)4 Summoner (no.stelar7.api.r4j.pojo.lol.summoner.Summoner)4 ChampionMasteryBuilder (no.stelar7.api.r4j.impl.lol.builders.championmastery.ChampionMasteryBuilder)3 SpectatorBuilder (no.stelar7.api.r4j.impl.lol.builders.spectator.SpectatorBuilder)3 SummonerBuilder (no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder)3 Pair (no.stelar7.api.l4j8.basic.utils.Pair)2 Pair (no.stelar7.api.r4j.basic.utils.Pair)2 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 FileSystemCacheProvider (no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider)1 L4J8 (no.stelar7.api.l4j8.impl.L4J8)1 ChampionMasteryBuilder (no.stelar7.api.l4j8.impl.builders.championmastery.ChampionMasteryBuilder)1 SummonerBuilder (no.stelar7.api.l4j8.impl.builders.summoner.SummonerBuilder)1 StaticChampion (no.stelar7.api.l4j8.pojo.staticdata.champion.StaticChampion)1 StaticMastery (no.stelar7.api.l4j8.pojo.staticdata.mastery.StaticMastery)1 StaticRune (no.stelar7.api.l4j8.pojo.staticdata.rune.StaticRune)1 Summoner (no.stelar7.api.l4j8.pojo.summoner.Summoner)1 FileSystemCacheProvider (no.stelar7.api.r4j.basic.cache.impl.FileSystemCacheProvider)1