Skip to content

Commit f985cb7

Browse files
Filter accounts highscore target levels from an account text file
Filters accounts by target level from a list .txt
1 parent f01da2e commit f985cb7

File tree

5 files changed

+300
-0
lines changed

5 files changed

+300
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11

22
*.xml
3+
*.iml
4+
*.class
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
package org.chris;
2+
3+
import org.chris.util.CheckLevels;
4+
import org.chris.util.Targets;
5+
6+
import java.awt.*;
7+
import java.awt.event.*;
8+
import java.io.IOException;
9+
import java.nio.charset.StandardCharsets;
10+
import java.nio.file.Files;
11+
import java.nio.file.Paths;
12+
import java.util.ArrayList;
13+
import java.util.HashMap;
14+
import javax.swing.*;
15+
/*
16+
* Created by JFormDesigner on Wed Dec 27 10:46:51 EST 2017
17+
*/
18+
19+
20+
21+
/**
22+
* @author Christopher d
23+
*/
24+
public class GUI extends JFrame {
25+
26+
private java.util.List<String> accsToInput = new ArrayList<>();
27+
private HashMap<String, Integer> accsToOutput = new HashMap<>();
28+
private int search, targetLevel;
29+
private String nameOfSkill;
30+
31+
public GUI() {
32+
initComponents();
33+
}
34+
35+
private void buttonFilterAccountsActionPerformed(ActionEvent e) {
36+
// TODO add your code here
37+
long start = System.currentTimeMillis();
38+
textOutputArea.setText("");
39+
printToOutput("Grabbing accounts from file................\n");
40+
try {
41+
accsToInput = Files.readAllLines(Paths.get("C:\\Users\\Chris\\Desktop\\Accounts.txt")
42+
, StandardCharsets.UTF_8);
43+
} catch (IOException f) {
44+
printToOutput(f + "\n");
45+
}
46+
printToOutput("Loaded accounts: " + (accsToInput.size()) + "\n");
47+
48+
printToOutput("Grabbing hiscore search value...\n");
49+
for (Targets s : Targets.values()) {
50+
if (s.getName().equals(comboSkillTarget.getSelectedItem().toString())) {
51+
search = s.getSearchValue();
52+
targetLevel = Integer.parseInt(textTargetLevel.getText());
53+
nameOfSkill = s.getName();
54+
printToOutput("Searching: " + nameOfSkill + " >= " + targetLevel + "\n");
55+
}
56+
}
57+
58+
printToOutput("Saving each player's highscore value to our map.....\n");
59+
for (String playerName : accsToInput){
60+
int target = 0;
61+
while (target == 0){
62+
printToOutput("Checking the highscores...please wait while I load data...\n");
63+
target = new CheckLevels(playerName, search).getTargetLevel();
64+
/*try {
65+
Thread.sleep(600);
66+
} catch (InterruptedException e1) {
67+
e1.printStackTrace();
68+
}*/
69+
}
70+
if (target >= targetLevel){
71+
printToOutput("Found: " + playerName + " Level: " + target + "\n");
72+
accsToOutput.put(playerName, target);
73+
}
74+
}
75+
printToOutput("Finished loading data for all accounts..sorting....\n");
76+
printToOutput("Clearing our output to display the sort.....\n");
77+
textOutputArea.setText("");
78+
printToOutput("Filtered Accounts for " + nameOfSkill + " Level:" + targetLevel + " or greater.\n");
79+
for (String name : accsToOutput.keySet()){
80+
printToOutput("Account: " + name + " | " + nameOfSkill + " Level: " + accsToOutput.get(name) + " \n");
81+
}
82+
printToOutput("Output time " + (System.currentTimeMillis() - start) + "ms.\n");
83+
}
84+
85+
private void printToOutput(String outputMessage){
86+
textOutputArea.append(outputMessage);
87+
}
88+
89+
private void initComponents() {
90+
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
91+
// Generated using JFormDesigner Evaluation license - Christopher d
92+
label1 = new JLabel();
93+
scrollPane1 = new JScrollPane();
94+
textOutputArea = new JTextArea();
95+
label2 = new JLabel();
96+
comboSkillTarget = new JComboBox<>();
97+
label3 = new JLabel();
98+
textTargetLevel = new JTextField();
99+
buttonFilterAccounts = new JButton();
100+
101+
//======== this ========
102+
setTitle("HiScore Filter Tool");
103+
Container contentPane = getContentPane();
104+
contentPane.setLayout(null);
105+
106+
//---- label1 ----
107+
label1.setText("Output");
108+
label1.setFont(label1.getFont().deriveFont(label1.getFont().getStyle() | Font.BOLD, label1.getFont().getSize() + 5f));
109+
contentPane.add(label1);
110+
label1.setBounds(15, 10, 60, 30);
111+
112+
//======== scrollPane1 ========
113+
{
114+
scrollPane1.setViewportView(textOutputArea);
115+
}
116+
contentPane.add(scrollPane1);
117+
scrollPane1.setBounds(15, 45, 295, 540);
118+
119+
//---- label2 ----
120+
label2.setText("Target:");
121+
label2.setFont(label2.getFont().deriveFont(label2.getFont().getStyle() | Font.BOLD, label2.getFont().getSize() + 5f));
122+
contentPane.add(label2);
123+
label2.setBounds(new Rectangle(new Point(325, 290), label2.getPreferredSize()));
124+
125+
//---- comboSkillTarget ----
126+
comboSkillTarget.setFont(comboSkillTarget.getFont().deriveFont(comboSkillTarget.getFont().getSize() + 5f));
127+
comboSkillTarget.setModel(new DefaultComboBoxModel<>(new String[] {
128+
"Attack",
129+
"Defence",
130+
"Strength",
131+
"Hitpoints",
132+
"Range",
133+
"Prayer",
134+
"Magic",
135+
"Cooking",
136+
"Woodcutting",
137+
"Fletching",
138+
"Fishing",
139+
"Firemaking",
140+
"Crafting",
141+
"Smithing",
142+
"Mining",
143+
"Herblore",
144+
"Agility",
145+
"Theiving",
146+
"Slayer",
147+
"Farming",
148+
"Runecrafting",
149+
"Hunter",
150+
"Construction"
151+
}));
152+
contentPane.add(comboSkillTarget);
153+
comboSkillTarget.setBounds(395, 290, 115, comboSkillTarget.getPreferredSize().height);
154+
155+
//---- label3 ----
156+
label3.setText("Target Level:");
157+
label3.setFont(label3.getFont().deriveFont(label3.getFont().getStyle() | Font.BOLD, label3.getFont().getSize() + 5f));
158+
contentPane.add(label3);
159+
label3.setBounds(new Rectangle(new Point(325, 350), label3.getPreferredSize()));
160+
161+
//---- textTargetLevel ----
162+
textTargetLevel.setText("1");
163+
textTargetLevel.setFont(textTargetLevel.getFont().deriveFont(textTargetLevel.getFont().getSize() + 4f));
164+
contentPane.add(textTargetLevel);
165+
textTargetLevel.setBounds(440, 345, 35, 30);
166+
167+
//---- buttonFilterAccounts ----
168+
buttonFilterAccounts.setText("Start Filter");
169+
buttonFilterAccounts.setFont(buttonFilterAccounts.getFont().deriveFont(buttonFilterAccounts.getFont().getStyle() | Font.BOLD, buttonFilterAccounts.getFont().getSize() + 4f));
170+
buttonFilterAccounts.addActionListener(e -> buttonFilterAccountsActionPerformed(e));
171+
contentPane.add(buttonFilterAccounts);
172+
buttonFilterAccounts.setBounds(330, 420, 190, 60);
173+
174+
contentPane.setPreferredSize(new Dimension(550, 640));
175+
setSize(550, 640);
176+
setLocationRelativeTo(getOwner());
177+
// JFormDesigner - End of component initialization //GEN-END:initComponents
178+
}
179+
180+
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
181+
// Generated using JFormDesigner Evaluation license - Christopher d
182+
private JLabel label1;
183+
private JScrollPane scrollPane1;
184+
private JTextArea textOutputArea;
185+
private JLabel label2;
186+
private JComboBox<String> comboSkillTarget;
187+
private JLabel label3;
188+
private JTextField textTargetLevel;
189+
private JButton buttonFilterAccounts;
190+
// JFormDesigner - End of variables declaration //GEN-END:variables
191+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.chris;
2+
3+
/**
4+
* Created by Chris on 12/27/2017.
5+
*/
6+
public class Main {
7+
8+
public static void main(String[] args) {
9+
GUI gui = new GUI();
10+
gui.setVisible(true);
11+
}
12+
13+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.chris.util;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.net.URL;
7+
import java.net.URLConnection;
8+
import java.util.Arrays;
9+
import java.util.List;
10+
//usage int woodLevel = new CheckLevels("PlayerName",wood).getTargetLevel();
11+
12+
public class CheckLevels {
13+
private int targetLevel;
14+
15+
public CheckLevels(String username, int levelToCheck) {
16+
try {
17+
URL url = new URL("http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player=" + username);
18+
URLConnection urlConnection = url.openConnection();
19+
BufferedReader input = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "UTF-8"));
20+
StringBuilder sb = new StringBuilder();
21+
String scores;
22+
while ((scores = input.readLine()) != null) {
23+
sb.append(scores);
24+
}
25+
input.close();
26+
String jsonResult = sb.toString();
27+
if (jsonResult.contains("404 - Page not found")) {
28+
this.targetLevel = 1;
29+
30+
} else {
31+
List<String> splitSkills = Arrays.asList(jsonResult.split(","));
32+
33+
this.targetLevel = Integer.parseInt(splitSkills.get(levelToCheck));
34+
}
35+
} catch (IOException e) {
36+
e.printStackTrace();
37+
}
38+
}
39+
40+
public int getTargetLevel() {
41+
return this.targetLevel;
42+
}
43+
44+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.chris.util;
2+
3+
/**
4+
* Created by Chris on 12/27/2017.
5+
*/
6+
public enum Targets {
7+
8+
Attack("Attack", 3),
9+
Defence("Defence", 5),
10+
Strength("Strength", 7),
11+
Hitpoints("Hitpoints", 9),
12+
Range("Range", 11),
13+
Prayer("Prayer", 13),
14+
Magic("Magic", 15),
15+
Cooking("Cooking", 17),
16+
Woodcutting("Woodcutting", 19),
17+
Fletching("Fletching", 21),
18+
Fishing("Fishing", 23),
19+
Firemaking("Firemaking", 25),
20+
Crafting("Crafting", 27),
21+
Smithing("Smithing", 29),
22+
Mining("Mining", 31),
23+
Herblore("Herblore", 33),
24+
Agility("Agility", 35),
25+
Theiving("Theiving", 37),
26+
Slayer("Slayer", 39),
27+
Farming("Farming", 41),
28+
Runecrafting("Runecrafting", 43),
29+
Hunter("Hunter", 45),
30+
Construction("Construction", 47)
31+
32+
;
33+
34+
35+
private final String name;
36+
private final int searchValue;
37+
38+
Targets(final String name, final int searchValue) {
39+
this.name = name;
40+
this.searchValue = searchValue;
41+
}
42+
43+
public String getName() {
44+
return name;
45+
}
46+
47+
public int getSearchValue() {
48+
return searchValue;
49+
}
50+
}

0 commit comments

Comments
 (0)