Skip to content

Instantly share code, notes, and snippets.

@DanBradbury
Created November 22, 2013 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanBradbury/7605383 to your computer and use it in GitHub Desktop.
Save DanBradbury/7605383 to your computer and use it in GitHub Desktop.
command test
package com.achimala.leaguelib.tests;
import java.util.concurrent.locks.ReentrantLock;
import com.achimala.leaguelib.connection.LeagueAccount;
import com.achimala.leaguelib.connection.LeagueConnection;
import com.achimala.leaguelib.connection.LeagueServer;
import com.achimala.leaguelib.errors.*;
import com.achimala.leaguelib.models.*;
import com.achimala.util.Callback;
import java.io.*;
import java.util.Map;
import java.util.Iterator;
import java.util.concurrent.locks.Condition;
public class ConsoleTest {
private static int count = 0;
private static ReentrantLock lock = new ReentrantLock();
private static Condition done = lock.newCondition();
private static String[] commands = {"find_player", "find_last_match"};
private static void incrementCount() {
lock.lock();
count++;
lock.unlock();
}
private static void decrementCount() {
lock.lock();
count--;
if(count == 0)
done.signal();
lock.unlock();
}
public static void main(String[] args) throws IOException, LeagueException {
// we want to be able to startup a session before the console is even technically started
final LeagueConnection c = new LeagueConnection(LeagueServer.NORTH_AMERICA);
c.getAccountQueue().addAccount(new LeagueAccount(LeagueServer.NORTH_AMERICA, "3.14find.xx", "iSixPool", "d6ADBN%Q"));
Map<LeagueAccount, LeagueException> exceptions = c.getAccountQueue().connectAll();
if(exceptions != null) {
for(LeagueAccount account : exceptions.keySet())
System.out.println(account + " error: " + exceptions.get(account));
return;
}
lock.lock();
incrementCount();
// now that we have established the connection we can start to perform whatever we want
System.out.println("League Lookup Console");
Boolean run = true;
while(run){
System.out.print(">> ");
BufferedReader dataIn = new BufferedReader( new InputStreamReader(System.in) );
String command = dataIn.readLine();
if(command.equals("quit")){
System.out.println("Bye, bye!");
break;
}else if(command.equals("help")){
System.out.println("List of available commands: ");
for(int i=0; i<commands.length;i++){
System.out.println(commands[i]);
}
}else if(command.startsWith("find_player")){
String[] split_array = command.split("\\s+");
if (split_array.length < 2){
System.out.println("USAGE: find_player <summoner_name>");
continue;
}
// we want to process the summoner name
c.getSummonerService().getSummonerByName(split_array[1], new Callback<LeagueSummoner>() {
public void onCompletion(LeagueSummoner summoner) {
System.out.println(summoner.getName());
System.out.println("accountID: " + summoner.getAccountId());
System.out.println("summonerID: " + summoner.getId());
incrementCount();
lock.unlock();
}
public void onError(Exception ex) {
lock.lock();
ex.printStackTrace();
decrementCount();
lock.unlock();
}
});
}else if(command.startsWith("find_last_match")){
String[] split_array = command.split("\\s+");
if (split_array.length < 2){
System.out.println("USAGE: find_last_match <summoner_name>");
continue;
}
// lets get some match information
c.getSummonerService().getSummonerByName(split_array[1], new Callback<LeagueSummoner>() {
public void onCompletion(LeagueSummoner summoner) {
c.getPlayerStatsService().fillMatchHistory(summoner, new Callback<LeagueSummoner>() {
public void onCompletion(LeagueSummoner summoner){
MatchHistoryEntry last_match = summoner.getMostRecentMatch();
System.out.println(last_match.getChampionSelectionForSummoner(summoner));
Map stats = last_match.getAllStats();
Iterator iterator = stats.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry mapEntry = (Map.Entry) iterator.next();
System.out.println(mapEntry.getKey()
+ ": " + mapEntry.getValue());
}
}
public void onError(Exception ex) {
}
});
}
public void onError(Exception ex) {
}
});
}else{
System.out.println("Unrecognized Command entered");
continue;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment