use of no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery 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;
}
use of no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery in project L4J8 by stelar7.
the class ChampionMasteryTest method testChampionMastery.
@Test
public void testChampionMastery() {
ChampionMastery mastery;
ChampionMasteryBuilder bu = new ChampionMasteryBuilder().withPlatform(Constants.TEST_PLATFORM[0]).withSummonerId(Constants.TEST_SUMMONER_IDS[0]);
mastery = bu.withChampionId(Constants.TEST_CHAMPION_IDS[0]).getChampionMastery();
assert mastery != null;
mastery = bu.withChampionId(Constants.TEST_CHAMPION_IDS[1]).getChampionMastery();
assert mastery != null;
}
use of no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery in project L4J8 by stelar7.
the class UseageTest method testUseage.
@Test
public void testUseage() {
R4J api = new R4J(SecretFile.CREDS);
DataCall.setCacheProvider(new FileSystemCacheProvider());
Map<Integer, StaticRune> runeData = api.getDDragonAPI().getRunes();
Map<Integer, StaticMastery> masteriesData = api.getDDragonAPI().getMasteries();
Map<Integer, StaticChampion> championData = api.getDDragonAPI().getChampions();
Map<Integer, StaticPerk> perkData = api.getDDragonAPI().getPerks();
Summoner summoner = Summoner.byName(LeagueShard.EUW1, "stelar7");
List<String> some = summoner.getLeagueGames().get();
LOLMatch match = LOLMatch.get(summoner.getPlatform(), some.get(0));
MatchParticipant self = match.getParticipants().stream().filter(p -> p.getPuuid().equals(summoner.getPUUID())).findFirst().get();
StaticChampion champion = championData.get(self.getChampionId());
ChampionMastery mastery = summoner.getChampionMastery(champion.getId());
boolean didWin = self.didWin();
System.out.format("Player '%s' played their latest game as '%s'%n", summoner.getName(), champion.getName());
System.out.format("They have a masteryscore of %s on that champion%n", mastery.getChampionPoints());
System.out.format("They played in %s, their role was: %s%n", self.getChampionSelectLane(), self.getRole());
System.out.format("They %s that game%n", didWin ? "won" : "lost");
System.out.format("%nThey used the following perks:%n");
List<PerkSelection> perks = self.getPerks().getPerkStyles().stream().flatMap(s -> s.getSelections().stream()).collect(Collectors.toList());
for (PerkSelection perk : perks) {
StaticPerk perkInfo = perkData.get(perk.getPerk());
String name = perkInfo.getName();
System.out.format("Name: '%-20s' variables: %-5s, %-5s, %-5s%n", name, perk.getVar1(), perk.getVar2(), perk.getVar3());
}
}
use of no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery 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(LeagueShard server, String summonerId, int championId) {
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, summonerId).withURLParameter(Constants.CHAMPION_ID_PLACEHOLDER, String.valueOf(championId)).withEndpoint(URLEndpoint.V4_MASTERY_BY_CHAMPION).withPlatform(server);
Map<String, Object> data = new TreeMap<>();
data.put("platform", server);
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 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);
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", masteryObj);
DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
return (ChampionMastery) masteryObj;
}
use of no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery in project L4J8 by stelar7.
the class UseageTest method testUseage.
@Test
public void testUseage() {
L4J8 api = new L4J8(SecretFile.CREDS);
DataCall.setLogLevel(LogLevel.DEBUG);
DataCall.setCacheProvider(new FileSystemCacheProvider());
Map<Integer, StaticRune> runeData = api.getStaticAPI().getRunes(Platform.EUW1, null, null, null);
Map<Integer, StaticMastery> masteriesData = api.getStaticAPI().getMasteries(Platform.EUW1, null, null, null);
Map<Integer, StaticChampion> championData = api.getStaticAPI().getChampions(Platform.EUW1, null, null, null);
Summoner stelar7 = new SummonerBuilder().withPlatform(Platform.EUW1).withName("stelar7").get();
List<MatchReference> some = stelar7.getGames().get();
MatchReference mostRecentGame = some.stream().max(Comparator.comparing(MatchReference::getTimestamp)).get();
Match match = mostRecentGame.getFullMatch();
Participant self = match.getParticipantFromSummonerId(stelar7.getSummonerId());
List<MatchRune> runes = self.getRunes();
List<MatchMastery> masteries = self.getMasteries();
StaticChampion champion = championData.get(mostRecentGame.getChampionId());
ChampionMastery mastery = stelar7.getChampionMastery(champion.getId());
boolean didWin = match.didWin(self);
ParticipantIdentity opponentIdentity = match.getLaneOpponentIdentity(self);
Participant opponent = match.getParticipantFromParticipantId(opponentIdentity.getParticipantId());
StaticChampion opponentChampion = championData.get(opponent.getChampionId());
System.out.format("Player '%s' played their latest game as '%s'%n", stelar7.getName(), champion.getName());
System.out.format("They have a masteryscore of %s on that champion%n", mastery.getChampionPoints());
System.out.format("They played in %s, their role was: %s%n", self.getTimeline().getLane(), self.getTimeline().getRole());
System.out.format("They %s that game%n", didWin ? "won" : "lost");
System.out.format("They laned against '%s' as '%s'%n", opponentIdentity.getPlayer().getSummonerName(), opponentChampion.getName());
System.out.format("%nThey used the following runes:%n");
for (MatchRune rune : runes) {
String name = runeData.get(rune.getRuneId()).getName();
System.out.format("Name: '%-45s' Count: %s%n", name, rune.getRank());
}
System.out.format("%nThey used the following masteries:%n");
for (MatchMastery matchMastery : masteries) {
String name = masteriesData.get(matchMastery.getMasteryId()).getName();
System.out.format("Name: '%-45s' Level: %s%n", name, matchMastery.getRank());
}
}
Aggregations