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;
}
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;
}
}
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());
}
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 :("));
}
}
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();
}
}
}
Aggregations