Skip to content

stirante/lol-client-java-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lol-client-java-api

Build Status lol-client-java-api

Simple library which provides access to internal League of Legends Client API.

Disclaimer

This product is not endorsed, certified or otherwise approved in any way by Riot Games, Inc. or any of its affiliates.

Requirements

lol-client-java-api requires at least Java 8 and works only on Windows.

Setup

This project is available on Jitpack

Gradle

Add Jitpack to your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Add the project as a dependency:

dependencies {
	compile 'com.github.stirante:lol-client-java-api:1.2.3'
}

Maven

Add Jitpack as a repository:

<repositories>
	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>
</repositories>

Add the project as a dependency:

<dependency>
    <groupId>com.github.stirante</groupId>
    <artifactId>lol-client-java-api</artifactId>
    <version>1.2.3</version>
</dependency>

Snapshots

Snapshots of all the latest changes are available in my personal nexus repository.

<repositories>
    <repository>
        <id>stirante-nexus-snapshots</id>
        <url>https://nexus.stirante.com/repository/maven-snapshots/</url>
    </repository>
</repositories>
<!-- https://github.com/stirante/lol-client-java-api -->
<dependency>
    <groupId>com.stirante</groupId>
    <artifactId>lol-client-java-api</artifactId>
    <version>1.2.11-SNAPSHOT</version>
</dependency>

Usage

This library depends on League of Legends client and requires it to be open while using this API.

package examples;

import com.stirante.lolclient.ClientApi;
import com.stirante.lolclient.ClientConnectionListener;
import generated.LolChampionsCollectionsChampion;
import generated.LolChampionsCollectionsChampionSkin;
import generated.LolSummonerSummoner;

import java.text.SimpleDateFormat;
import java.util.Date;

public class SkinListExample {

    private static final SimpleDateFormat FORMATTER = new SimpleDateFormat("dd-MM-yyyy");

    /**
     * Simple example, which show all owned champions and skins (with purchase date)
     */
    public static void main(String[] args) {
        //Initialize API
        ClientApi api = new ClientApi();
        api.addClientConnectionListener(new ClientConnectionListener() {
            @Override
            public void onClientConnected() {
                try {
                    //Check if user is logged in
                    if (!api.isAuthorized()) {
                        System.out.println("Not logged in!");
                        return;
                    }
                    //Get current summoner
                    LolSummonerSummoner summoner = api.executeGet("/lol-summoner/v1/current-summoner", LolSummonerSummoner.class).getResponseObject();
                    //Get champion collection of summoner
                    LolChampionsCollectionsChampion[] champions = api.executeGet(
                            "/lol-champions/v1/inventories/" + summoner.summonerId + "/champions",
                            LolChampionsCollectionsChampion[].class).getResponseObject();
                    for (LolChampionsCollectionsChampion champion : champions) {
                        if (champion.ownership.owned) {
                            System.out.println(champion.name + " purchased on " +
                                    FORMATTER.format(new Date(champion.ownership.rental.purchaseDate)));
                            for (LolChampionsCollectionsChampionSkin skin : champion.skins) {
                                if (!skin.isBase && skin.ownership.owned) {
                                    System.out.println("\t" + skin.name + " purchased on " +
                                            FORMATTER.format(new Date(skin.ownership.rental.purchaseDate)));
                                }
                            }
                        }
                    }
                    api.stop();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onClientDisconnected() {

            }
        });
    }
}

This library is still under development and lacks many features. Right now to access them, use these methods.

package examples;

import com.stirante.lolclient.ClientApi;
import com.stirante.lolclient.ClientConnectionListener;
import generated.LolChatUserResource;

import java.io.IOException;

public class DirectAccessExample {

    /**
     * Simple example, which shows how to access API directly
     */
    public static void main(String[] args) {
        //Initialize API
        ClientApi api = new ClientApi();
        //Add listener, which will notify us about client connection available
        api.addClientConnectionListener(new ClientConnectionListener() {
            @Override
            public void onClientConnected() {
                try {
                    //Get current user chat info
                    ApiResponse<LolChatUserResource> user =
                            api.executeGet("/lol-chat/v1/me", LolChatUserResource.class);
                    //Print status message
                    System.out.println(user.getRawResponse());
                    api.stop();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onClientDisconnected() {

            }
        });
    }
}

All possible paths can be found in api.getSwaggerJson() or api.getOpenapiJson(). (In order to enable this, you need to add enable_swagger: true to Riot Games\League of Legends\RADS\projects\league_client\releases\<latest version>\deploy\system.yaml)

All classes in generated package were generated from OpenAPI JSON. To regenerate all classes, run League of Legends client with access to swagger and run

mvn clean compile exec:java

All examples are in examples package.

Library contains very simple command line interface which can be used like this

java -jar lol-client-java-api.jar -p PATH -m METHOD

Example:

java -jar lol-client-java-api.jar -p rso-auth/v1/authorization -m GET

Library also allows for listening to events from League of Legends client

package examples;

import com.stirante.lolclient.ClientApi;
import com.stirante.lolclient.ClientConnectionListener;
import com.stirante.lolclient.ClientWebSocket;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class WebSocketExample {

    private static ClientWebSocket socket;

    /**
     * Simple example showing how to receive websocket events from client
     */
    public static void main(String[] args) throws Exception {
        //Initialize API
        ClientApi api = new ClientApi();
        api.addClientConnectionListener(new ClientConnectionListener() {
            @Override
            public void onClientConnected() {
                System.out.println("Client connected");
                try {
                    //open web socket
                    socket = api.openWebSocket();
                    //add event handler, which prints every received event
                    socket.setSocketListener(new ClientWebSocket.SocketListener() {
                        @Override
                        public void onEvent(ClientWebSocket.Event event) {
                            System.out.println(event);
                        }

                        @Override
                        public void onClose(int code, String reason) {
                            System.out.println("Socket closed, reason: " + reason);
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onClientDisconnected() {
                System.out.println("Client disconnected");
                socket.close();
            }
        });
        //close socket when user enters something into console
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        reader.readLine();
        api.stop();
        socket.close();
    }

}

Live game API

Since version 1.2.0, this api allows for requesting live game data. The example is in src/main/java/examples/IngameApiExample.java. To check how it's working, run this example while in game.

A generated documentation can be found here (not generated by me).

Generated models for live game API are in generated.live package (It's not very useful right now, because the schema in the documentation is lacking. I hope it will be added in the future).

Contributing

All contributions are appreciated. If you would like to contribute to this project, please send a pull request.

Contact

Have a suggestion, complaint, or question? Open an issue.