<commit_before>package no.stelar7.api.r4j.impl.lol.liveclient;

import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import no.stelar7.api.r4j.basic.calling.DataCallBuilder;
import no.stelar7.api.r4j.basic.constants.api.*;
import no.stelar7.api.r4j.basic.exceptions.APIResponseException;
import no.stelar7.api.r4j.basic.utils.*;
import no.stelar7.api.r4j.pojo.lol.liveclient.*;
import no.stelar7.api.r4j.pojo.lol.liveclient.events.*;
import no.stelar7.api.r4j.pojo.lol.replay.ReplayTeamType;

import java.util.*;

public class LiveClientDataAPI
{
    public static ActiveGameData getGameData()
    {
        try
        {
            Object data = new DataCallBuilder()
                    .withLimiters(false)
                    .withProxy(Constants.CLIENT_PROXY)
                    .withEndpoint(URLEndpoint.LIVECLIENT_GAME_DATA)
                    .withRequestMethod("GET")
                    .build();
            
            if (data instanceof Pair)
            {
                return null;
            }
            
            JsonObject obj = ((JsonElement) data).getAsJsonObject();
            
            ActiveGameData returnMe = new ActiveGameData(
                    Utils.getGson().fromJson(obj.get("activePlayer"), ActiveGameClientPlayer.class),
                    Utils.getGson().fromJson(obj.get("allPlayers"), new TypeToken<List<ActiveGamePlayer>>() {}.getType()),
                    parseEventObjectToList(obj.get("events")),
                    Utils.getGson().fromJson(obj.get("gameData"), ActiveGameState.class));
            
            return returnMe;
            
        } catch (APIResponseException e)
        {
            return null;
        }
    }
    
    private static List<GameEvent> parseEventObjectToList(JsonElement data)
    {
        List<GameEvent> events = new ArrayList<>();
        JsonArray       obj    = data.getAsJsonObject().getAsJsonArray("Events");
        for (JsonElement elem : obj)
        {
            String eventType = elem.getAsJsonObject().get("EventName").getAsString();
            switch (eventType)
            {
                case "GameStart":
                case "GameEnd":
                case "MinionsSpawning":
                {
                    events.add(Utils.getGson().fromJson(elem, GameEvent.class));
                    break;
                }
                case "ChampionKill":
                {
                    events.add(Utils.getGson().fromJson(elem, ChampionKillEvent.class));
                    break;
                }
                case "FirstBlood":
                case "FirstBrick":
                {
                    events.add(Utils.getGson().fromJson(elem, RewardEvent.class));
                    break;
                }
                
                case "TurretKilled":
                {
                    events.add(Utils.getGson().fromJson(elem, TurretKillEvent.class));
                    break;
                }
                
                case "InhibKilled":
                {
                    events.add(Utils.getGson().fromJson(elem, InhibKillEvent.class));
                    break;
                }
                
                case "HeraldKill":
                case "DragonKill":
                case "BaronKill":
                {
                    events.add(Utils.getGson().fromJson(elem, EpicUnitKillEvent.class));
                    break;
                }
                
                case "InhibRespawningSoon":
                {
                    events.add(Utils.getGson().fromJson(elem, InhibRespawningSoonEvent.class));
                    break;
                }
                
                case "InhibRespawned":
                {
                    events.add(Utils.getGson().fromJson(elem, InhibRespawnedEvent.class));
                    break;
                }
                
                case "Multikill": {
                    events.add(Utils.getGson().fromJson(elem, MultikillEvent.class));
                    break;
                }
                default:
                    System.out.println("Unknown event: " + eventType);
            }
        }
        return events;
    }
    
    public static List<GameEvent> getEventData()
    {
        try
        {
            Object data = new DataCallBuilder()
                    .withLimiters(false)
                    .withProxy(Constants.CLIENT_PROXY)
                    .withEndpoint(URLEndpoint.LIVECLIENT_EVENT_DATA)
                    .withRequestMethod("GET")
                    .build();
            <commit_msg>Split Dragon to its own event<commit_after>package no.stelar7.api.r4j.impl.lol.liveclient;

import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import no.stelar7.api.r4j.basic.calling.DataCallBuilder;
import no.stelar7.api.r4j.basic.constants.api.*;
import no.stelar7.api.r4j.basic.exceptions.APIResponseException;
import no.stelar7.api.r4j.basic.utils.*;
import no.stelar7.api.r4j.pojo.lol.liveclient.*;
import no.stelar7.api.r4j.pojo.lol.liveclient.events.*;
import no.stelar7.api.r4j.pojo.lol.replay.ReplayTeamType;

import java.util.*;

public class LiveClientDataAPI
{
    public static ActiveGameData getGameData()
    {
        try
        {
            Object data = new DataCallBuilder()
                    .withLimiters(false)
                    .withProxy(Constants.CLIENT_PROXY)
                    .withEndpoint(URLEndpoint.LIVECLIENT_GAME_DATA)
                    .withRequestMethod("GET")
                    .build();
            
            if (data instanceof Pair)
            {
                return null;
            }
            
            JsonObject obj = ((JsonElement) data).getAsJsonObject();
            
            ActiveGameData returnMe = new ActiveGameData(
                    Utils.getGson().fromJson(obj.get("activePlayer"), ActiveGameClientPlayer.class),
                    Utils.getGson().fromJson(obj.get("allPlayers"), new TypeToken<List<ActiveGamePlayer>>() {}.getType()),
                    parseEventObjectToList(obj.get("events")),
                    Utils.getGson().fromJson(obj.get("gameData"), ActiveGameState.class));
            
            return returnMe;
            
        } catch (APIResponseException e)
        {
            return null;
        }
    }
    
    private static List<GameEvent> parseEventObjectToList(JsonElement data)
    {
        List<GameEvent> events = new ArrayList<>();
        JsonArray       obj    = data.getAsJsonObject().getAsJsonArray("Events");
        for (JsonElement elem : obj)
        {
            String eventType = elem.getAsJsonObject().get("EventName").getAsString();
            switch (eventType)
            {
                case "GameStart":
                case "GameEnd":
                case "MinionsSpawning":
                {
                    events.add(Utils.getGson().fromJson(elem, GameEvent.class));
                    break;
                }
                case "ChampionKill":
                {
                    events.add(Utils.getGson().fromJson(elem, ChampionKillEvent.class));
                    break;
                }
                case "FirstBlood":
                case "FirstBrick":
                {
                    events.add(Utils.getGson().fromJson(elem, RewardEvent.class));
                    break;
                }
                
                case "TurretKilled":
                {
                    events.add(Utils.getGson().fromJson(elem, TurretKillEvent.class));
                    break;
                }
                
                case "InhibKilled":
                {
                    events.add(Utils.getGson().fromJson(elem, InhibKillEvent.class));
                    break;
                }
                
                case "HeraldKill":
                case "BaronKill":
                {
                    events.add(Utils.getGson().fromJson(elem, EpicUnitKillEvent.class));
                    break;
                }
                
                case "DragonKill":
                {
                    events.add(Utils.getGson().fromJson(elem, DragonKillEvent.class));
                    break;
                }
                
                case "InhibRespawningSoon":
                {
                    events.add(Utils.getGson().fromJson(elem, InhibRespawningSoonEvent.class));
                    break;
                }
                
                case "InhibRespawned":
                {
                    events.add(Utils.getGson().fromJson(elem, InhibRespawnedEvent.class));
                    break;
                }
                
                case "Multikill":
                {
                    events.add(Utils.getGson().fromJson(elem, MultikillEvent.class));
                    break;
                }
                default:
                    System.out.println("Unknown event: " + eventType);
            }
        }
        return events;
    }
    
    public static List<GameEvent> getEventData()
    {
        try
        {
            Object data = new DataCallBuilder()
                    .withLimiters(false)
                    .withProxy(Constants.CLIENT_PROXY)
                    .withEndpoint(URLEndpoint.LIVECLIENT_EVENT_DATA)
                    .withRequestMethod("GET")
                    .build();
            
{'fraction_non_alphanumeric': 0.09901095395086675, 'fraction_numerical': 0.003403169201318728, 'mean_word_length': 1.2562380038387715, 'pattern_counts': {'":': 28, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5219795', 'n_tokens_mistral': 2561, 'n_tokens_neox': 2398, 'n_words': 338}