Search in sources :

Example 26 with Summoner

use of no.stelar7.api.r4j.pojo.lol.summoner.Summoner in project L4J8 by stelar7.

the class SummonerBuilder method get.

/**
 * gets a summoner based on the parameters passed to the builder
 *
 * @return Summoner
 */
public Summoner get() {
    DataCallBuilder builder = new DataCallBuilder().withPlatform(this.platform);
    URLEndpoint endpoint = null;
    if (accId > 0) {
        builder.withURLParameter(Constants.ACCOUNT_ID_PLACEHOLDER, String.valueOf(this.accId));
        endpoint = URLEndpoint.V3_SUMMONER_BY_ACCOUNT;
    }
    if (sumId > 0) {
        builder.withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, String.valueOf(this.sumId));
        endpoint = URLEndpoint.V3_SUMMONER_BY_ID;
    }
    if (name.length() > 0) {
        builder.withURLParameter(Constants.SUMMONER_NAME_PLACEHOLDER, Utils.normalizeSummonerName(this.name));
        endpoint = URLEndpoint.V3_SUMMONER_BY_NAME;
    }
    builder.withEndpoint(endpoint);
    Optional chl = DataCall.getCacheProvider().get(endpoint, this.platform, this.accId, this.sumId, this.name);
    if (chl.isPresent()) {
        return (Summoner) chl.get();
    }
    Object sob = builder.build();
    if (sob instanceof Pair) {
        return null;
    }
    DataCall.getCacheProvider().store(endpoint, sob, this.platform, this.accId, this.sumId, this.name);
    return (Summoner) sob;
}
Also used : Summoner(no.stelar7.api.l4j8.pojo.summoner.Summoner) Optional(java.util.Optional)

Example 27 with Summoner

use of no.stelar7.api.r4j.pojo.lol.summoner.Summoner 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 28 with Summoner

use of no.stelar7.api.r4j.pojo.lol.summoner.Summoner in project L4J8 by stelar7.

the class CurrentGameTest method testCurrentGameFame.

@Test
public void testCurrentGameFame() {
    final R4J r4J = new R4J(SecretFile.CREDS);
    Summoner s = Summoner.byName(LeagueShard.EUW1, "Klospülautomat");
    SpectatorGameInfo game = s.getCurrentGame();
    System.out.format("%s is %sin game%n", s.getName(), game != null ? "" : "not ");
}
Also used : Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) SpectatorGameInfo(no.stelar7.api.r4j.pojo.lol.spectator.SpectatorGameInfo) R4J(no.stelar7.api.r4j.impl.R4J)

Example 29 with Summoner

use of no.stelar7.api.r4j.pojo.lol.summoner.Summoner in project L4J8 by stelar7.

the class CurrentGameTest method testCurrentGame.

@Test
public void testCurrentGame() {
    final R4J r4J = new R4J(SecretFile.CREDS);
    SpectatorBuilder sb = new SpectatorBuilder().withPlatform(LeagueShard.EUW1);
    // Get a game in progess
    final List<SpectatorGameInfo> game = sb.getFeaturedGames();
    // Get a summoner from that game
    final String name = game.get(0).getParticipants().get(0).getSummonerName();
    final Summoner sum = new SummonerBuilder().withPlatform(game.get(0).getPlatform()).withName(name).get();
    // Get game info
    final SpectatorGameInfo currentGame = sb.withSummonerId(sum.getSummonerId()).getCurrentGame();
    if (currentGame != null) {
        doAssertions.accept(currentGame);
    }
}
Also used : Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) SpectatorGameInfo(no.stelar7.api.r4j.pojo.lol.spectator.SpectatorGameInfo) SummonerBuilder(no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder) R4J(no.stelar7.api.r4j.impl.R4J) SpectatorBuilder(no.stelar7.api.r4j.impl.lol.builders.spectator.SpectatorBuilder)

Example 30 with Summoner

use of no.stelar7.api.r4j.pojo.lol.summoner.Summoner in project L4J8 by stelar7.

the class SummonerTest method testByPUUID.

@Test
public void testByPUUID() {
    String id = new SpectatorBuilder().withPlatform(LeagueShard.EUW1).getFeaturedGames().get(0).getParticipants().get(0).getSummonerName();
    Summoner s = new SummonerBuilder().withPlatform(LeagueShard.EUW1).withName(id).get();
    Summoner optional = new SummonerBuilder().withPlatform(s.getPlatform()).withPUUID(s.getPUUID()).get();
    doAssertions.accept(optional);
}
Also used : Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) SummonerBuilder(no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder) SpectatorBuilder(no.stelar7.api.r4j.impl.lol.builders.spectator.SpectatorBuilder)

Aggregations

Summoner (no.stelar7.api.r4j.pojo.lol.summoner.Summoner)33 SummonerBuilder (no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder)19 SpectatorBuilder (no.stelar7.api.r4j.impl.lol.builders.spectator.SpectatorBuilder)15 Summoner (no.stelar7.api.l4j8.pojo.summoner.Summoner)13 SummonerBuilder (no.stelar7.api.l4j8.impl.builders.summoner.SummonerBuilder)9 R4J (no.stelar7.api.r4j.impl.R4J)7 FileSystemCacheProvider (no.stelar7.api.r4j.basic.cache.impl.FileSystemCacheProvider)5 Optional (java.util.Optional)4 ChampionMasteryBuilder (no.stelar7.api.r4j.impl.lol.builders.championmastery.ChampionMasteryBuilder)4 ChampionMastery (no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery)4 java.util (java.util)3 FileSystemCacheProvider (no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider)3 L4J8 (no.stelar7.api.l4j8.impl.L4J8)3 MatchListBuilder (no.stelar7.api.l4j8.impl.builders.match.MatchListBuilder)3 JsonWriter (com.google.gson.stream.JsonWriter)2 java.awt (java.awt)2 AffineTransform (java.awt.geom.AffineTransform)2 java.awt.image (java.awt.image)2 java.io (java.io)2 URL (java.net.URL)2