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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations