import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.NumberFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
@ScriptManifest(author = "", name = "Bank Evaluator", info = "Determines the value of bank", logo = "", version = 1)
public class Main extends Script {
private int wealth = 0;
private long startTime;
private long endTime;
private static final Pattern pattern = Pattern.compile("(?:\"overall\":)([0-9]+)");
private static int getPrice(int id) throws MalformedURLException, IOException {
String url = "http://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + id;
BufferedReader reader = new BufferedReader(
new InputStreamReader(new URL(String.format(url, id)).openConnection().getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
Matcher m = pattern.matcher(line);
if (m.find() && m.groupCount() > 0) {
int overallPrice = Integer.parseInt(m.group(1));
if (overallPrice == 0) break;
return overallPrice;
}
}
reader.close();
return 0;
}
@Override
public void onPaint(Graphics2D paint) {
paint.setColor(Color.ORANGE);
paint.drawString("Amount of time took to get bank wealth: " + formatT(endTime), 10, 310);
paint.drawString("Amount of items found in bank: " + formatIntegers(getBank().getItems().length), 10, 325);
paint.drawString("Bank amount: " + formatIntegers(wealth), 10, 340);
}
private String formatT(final long ms) {
long s = ms / 1000, m = s / 60, h = m / 60;
s %= 60;
m %= 60;
h %= 24;
return String.format("%02d:%02d:%02d", h, m, s);
}
@Override
public void onStart() {
startTime = System.currentTimeMillis();
if (getBank().isOpen()) {
for (Item i : getBank().getItems()) {
if (i != null){
try {
wealth = wealth + (getPrice(i.getId()) * i.getAmount());
} catch (IOException e) {
e.printStackTrace();
}
}
}
endTime = System.currentTimeMillis() - startTime;
}
}
private String formatIntegers(int num) {
return NumberFormat.getInstance().format(num);
}
@Override
public int onLoop() throws InterruptedException {
return 1000;
}
}
made some changes hope u like