Jump to content

Hiscores checker snippet


Recommended Posts

Posted (edited)

How to use, simply add the player into your map. Then your able to access their skills, rank, level, and exp. I have to give some credit to @Swizzbeat, because i used parts of his snippet to build mine.

 

package dependencies.hiscores;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;

public class Hiscores {
	
	private Script script; 
	private static final String URL_BASE = "http://services.runescape.com/m=hiscore_oldschool/hiscorepersonal.ws?user1=";
	
	public Map<String, Map<Skill, Stat>> playersMap = new HashMap<String, Map<Skill, Stat>>();
		
	public Hiscores(Script s)	{
		script = s;
	}
	
	public static class Stat	{
		
		private int rank, level, exp;
		
		public Stat(int rank, int level, int exp)	{
			this.rank = rank;
			this.level = level;
			this.exp = exp;
		}
		
		public int getRank()	{
			return this.rank;
		}
		
		public int getLevel()	{
			return this.level;
		}
		
		public int getExp()	{
			return this.exp;
		}		
	}

	public int formatString(String string)	{
		String number = string.substring(string.indexOf('>') +1, string.lastIndexOf('<'));
		number = number.replace(",", "");
		return Integer.parseInt(number);
	}
	
	private void getInfo(String userName) throws IOException	{
		String name = userName.replace(" ", "_");
		URL url = new URL(URL_BASE + name);
		BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
		String skillName;

		
		while ((skillName = reader.readLine()) != null)	{
			for (Skill skill: Skill.values())	{
				int rank = 0, level = 0, exp = 0;
				String string;
				
				if (skillName.equalsIgnoreCase(skill.name()))	{
					for (int i = 0; i <= 3; i++)	{
						string = reader.readLine();
						if (i == 1)
							rank = formatString(string);
						else if (i == 2)
							level = formatString(string);
						else if (i == 3)
							exp = formatString(string);
					}
					
					if (!playersMap.containsKey(userName))	
						playersMap.put(userName, new HashMap<Skill, Hiscores.Stat>());
					else
						playersMap.get(userName).put(skill, new Stat(rank, level, exp));
				}				
			}
		}
		reader.close();
	}
		
	public void addPlayer(String userName) throws IOException	{
		if (playersMap.containsKey(userName))	
			playersMap.remove(userName);
		else
			this.getInfo(userName);		
	}
	
	public Stat get(String userName, Skill skill)	{
		if (playersMap.containsKey(userName))
			return playersMap.get(userName).get(skill);
		return null;
	}
} 
Edited by josedpay
  • Like 1
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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