Search in sources :

Example 16 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class MatchBuilder method get.

/**
 * Gets a match based on the parameters passed to the builder.
 * Matches older than 3 years will return null
 *
 * @return Match
 */
public Match get() {
    if (this.id < 0 || this.platform == Platform.UNKNOWN) {
        return null;
    }
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.MATCH_ID_PLACEHOLDER, String.valueOf(this.id)).withEndpoint(URLEndpoint.V3_MATCH).withPlatform(this.platform);
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_MATCH, this.platform, this.id);
    if (chl.isPresent()) {
        return (Match) chl.get();
    }
    Object matchObj = builder.build();
    if (matchObj instanceof Pair) {
        return null;
    }
    Match match = (Match) matchObj;
    DataCall.getCacheProvider().store(URLEndpoint.V3_MATCH, match, this.platform, this.id);
    return match;
}
Also used : Optional(java.util.Optional) Match(no.stelar7.api.l4j8.pojo.match.Match) Pair(no.stelar7.api.l4j8.basic.utils.Pair)

Example 17 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class TimelineBuilder method get.

/**
 * Returns the timeline relating to a match.
 * Not avaliable for matches older than a year
 *
 * @return MatchTimeline if avaliable
 */
public MatchTimeline get() {
    if (this.id == -1 || this.platform == Platform.UNKNOWN) {
        return null;
    }
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.MATCH_ID_PLACEHOLDER, String.valueOf(this.id)).withEndpoint(URLEndpoint.V3_TIMELINE).withPlatform(this.platform);
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_TIMELINE, this.platform, this.id);
    if (chl.isPresent()) {
        return (MatchTimeline) chl.get();
    }
    try {
        MatchTimeline timeline = (MatchTimeline) builder.build();
        DataCall.getCacheProvider().store(URLEndpoint.V3_TIMELINE, timeline, this.platform, this.id);
        return timeline;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : Optional(java.util.Optional) MatchTimeline(no.stelar7.api.l4j8.pojo.match.MatchTimeline)

Example 18 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class DivTests method test.

@Test
public void test() {
    R4J api = new R4J(SecretFile.CREDS);
    String user = "stelar7";
    LeagueShard region = LeagueShard.EUW1;
    Summoner summoner = new SummonerBuilder().withPlatform(region).withName(user).get();
    Map<Integer, StaticChampion> champData = api.getDDragonAPI().getChampions();
    // pfp
    String pfp = ImageAPI.getInstance().getProfileIcon(region, user);
    // name and lv
    int level = summoner.getSummonerLevel();
    String name = summoner.getName();
    // most recent game
    List<String> matches = summoner.getLeagueGames().get();
    LOLMatch match = LOLMatch.get(region, matches.get(0));
    MatchParticipant self = match.getParticipants().stream().filter(p -> p.getPuuid().equals(summoner.getPUUID())).findFirst().get();
    StaticChampion champion = champData.get(self.getChampionId());
    MatchPerks summs = self.getPerks();
    boolean won = self.didWin();
    System.out.println("Profile icon: " + pfp);
    System.out.println(name + ", Level " + level);
    System.out.println();
    System.out.format(name + " %s their most recent game.", won ? "won" : "lost");
    System.out.println();
    System.out.println("They were playing " + self.getChampionSelectLane() + " " + champion.getName());
}
Also used : Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) SummonerBuilder(no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder) StaticChampion(no.stelar7.api.r4j.pojo.lol.staticdata.champion.StaticChampion) R4J(no.stelar7.api.r4j.impl.R4J) LeagueShard(no.stelar7.api.r4j.basic.constants.api.regions.LeagueShard) Test(org.junit.jupiter.api.Test)

Example 19 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class CheckNormalGameForWinTest method testFindSelfInNormalGame.

@Test
@Disabled
public void testFindSelfInNormalGame() {
    Summoner summoner = new SummonerBuilder().withPlatform(LeagueShard.NA1).withName("devitgg").get();
    List<String> refs = new MatchListBuilder().withPlatform(LeagueShard.NA1).withPuuid(summoner.getPUUID()).get();
    for (String current : refs) {
        LOLMatch match = LOLMatch.get(LeagueShard.NA1, current);
        MatchParticipant self = match.getParticipants().stream().filter(p -> p.getPuuid().equals(summoner.getPUUID())).findFirst().get();
        System.out.println("I " + (self.didWin() ? "won!" : "lost :("));
    }
}
Also used : Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) SummonerBuilder(no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder) MatchListBuilder(no.stelar7.api.r4j.impl.lol.builders.matchv5.match.MatchListBuilder)

Example 20 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class MatchListV5Test method testForMissingAttributes.

@Test
public void testForMissingAttributes() {
    LeagueAPI leagueAPI = r4J.getLoLAPI().getLeagueAPI();
    List<LeagueEntry> divis = leagueAPI.getLeagueByTierDivision(LeagueShard.EUW1, GameQueueType.RANKED_SOLO_5X5, TierDivisionType.GOLD_I, 1);
    for (LeagueEntry entry : divis) {
        Summoner summoner = Summoner.bySummonerId(LeagueShard.EUW1, entry.getSummonerId());
        List<String> lazy = summoner.getLeagueGames().get();
        for (int i = 0; i < lazy.size() && i < 5; i++) {
            String match = lazy.get(i);
            LOLMatch lolMatch = LOLMatch.get(LeagueShard.EUW1, match);
            lolMatch.getTimeline();
        }
    }
}
Also used : Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) LeagueEntry(no.stelar7.api.r4j.pojo.lol.league.LeagueEntry) LeagueAPI(no.stelar7.api.r4j.impl.lol.raw.LeagueAPI)

Aggregations

Summoner (no.stelar7.api.r4j.pojo.lol.summoner.Summoner)8 R4J (no.stelar7.api.r4j.impl.R4J)7 SummonerBuilder (no.stelar7.api.l4j8.impl.builders.summoner.SummonerBuilder)6 Summoner (no.stelar7.api.l4j8.pojo.summoner.Summoner)6 MatchListBuilder (no.stelar7.api.l4j8.impl.builders.match.MatchListBuilder)5 java.util (java.util)4 FileSystemCacheProvider (no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider)4 FileSystemCacheProvider (no.stelar7.api.r4j.basic.cache.impl.FileSystemCacheProvider)4 SummonerBuilder (no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder)4 VALMatchAPI (no.stelar7.api.r4j.impl.val.VALMatchAPI)4 java.awt (java.awt)3 AffineTransform (java.awt.geom.AffineTransform)3 java.awt.image (java.awt.image)3 java.io (java.io)3 URL (java.net.URL)3 List (java.util.List)3 Predicate (java.util.function.Predicate)3 IntStream (java.util.stream.IntStream)3 ImageIO (javax.imageio.ImageIO)3 L4J8 (no.stelar7.api.l4j8.impl.L4J8)3