Jump to content

Retrieve Player Skill Levels


Swizzbeat

Recommended Posts

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA
 * User: Anthony
 * Date: 4/1/2014
 */

public class SkillChecker {

	private static final String URL_BASE = "http://services.runescape.com/m=hiscore_oldschool/hiscorepersonal.ws?user1=";

	public static Map<String, Integer> retrievePlayerLevelForSkill(String playerName, String... skillNames) throws IOException {
		Map<String, Integer> skillPairs = new HashMap<String, Integer>();
		BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(URL_BASE + playerName.replace(" ", "_")).openStream(), "UTF-8"));
		String stringRead;
		while ((stringRead = reader.readLine()) != null) {
			for (String current : skillNames) {
				if (stringRead.equalsIgnoreCase(current)) {
					for (int i = 0; i < 2; i++) {
						reader.readLine();
					}
					skillPairs.put(current.toUpperCase().charAt(0) + current.substring(1), Integer.parseInt(reader.readLine().replace("<td align=\"right\">", "").replace("</td>", "")));
					break;
				}
			}
		}
		reader.close();
		return (skillPairs.size() > 0) ? skillPairs : null;
	}

}

I'm not very familiar with data streams so for some of you this may look disgusting. Please provide me with any ways to improve it :D

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...