Malcolm_OSBot

Highscores Grabber

Sep 13th, 2019
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.net.MalformedURLException;
  5. import java.net.URL;
  6. import java.net.URLConnection;
  7. import java.util.ArrayList;
  8.  
  9. public class Highscores {
  10.    
  11.     ArrayList<String> stats = new ArrayList<String>();
  12.    
  13.     public Highscores(String player) {
  14.         getStats(player);
  15.     }
  16.    
  17.     public final int getSkillLevel(Skills skill) {
  18.         int index = skill.getLevelIndex();
  19.         String[] array = stats.get(index).split(",");
  20.         return Integer.parseInt(array[1]);
  21.     }
  22.    
  23.     public final int getSkillExperience(Skills skill) {
  24.         int index = skill.getLevelIndex();
  25.         String[] array = stats.get(index).split(",");
  26.         return Integer.parseInt(array[2]);
  27.     }
  28.  
  29.     private void getStats(final String player) {
  30.         try {
  31.             URL url = new URL("https://secure.runescape.com/m=hiscore_oldschool/index_lite.ws?player=" + player);
  32.             URLConnection con = url.openConnection();
  33.             BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  34.  
  35.             String inputLine;
  36.             while ((inputLine = in.readLine()) != null) {
  37.                 stats.add(inputLine);
  38.             }
  39.             in.close();
  40.         } catch (MalformedURLException e) {
  41.             //CATCH
  42.         } catch (IOException e) {
  43.             //CATCH
  44.         }
  45.     }
  46. }
  47.  
  48.  
  49.  
  50. public enum Skills {
  51.  
  52.     TOTAL(0), ATTACK(1), DEFENCE(2), STRENGTH(3), HITPOINTS(4), RANGED(5), PRAYER(6), MAGIC(7),
  53.     COOKING(8), WOODCUTTING(9), FLETCHING(10), FISHING(11), FIREMAKING(12), CRAFTING(13),
  54.     SMITHING(14), MINING(15), HERBLORE(16), AGILITY(17), THIEVING(18), SLAYER(19),
  55.     FARMING(20), RUNECRAFT(21), HUNTER(22), CONSTRUCTION(23);
  56.  
  57.     Skills(int levelIndex) {
  58.         this.levelIndex = levelIndex;
  59.     }
  60.    
  61.     private int levelIndex;
  62.  
  63.     public int getLevelIndex() {
  64.         return levelIndex;
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment