I have moderated content on here cause I'm an asshole so my posts need to be approved by mods.
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
/**
* Created with IntelliJ IDEA
* User: Anthony
* Date: 6/8/2014
*/
public class XPListener extends Thread {
private boolean running;
private int lastXpGain;
private long lastXpGainTime;
private Script sI;
private Skill skill;
public XPListener(Script sI, Skill skill) {
this.running = true;
this.sI = sI;
this.skill = skill;
}
@Override
public void run() {
while (running) {
int oldXp = sI.skills.getExperience(skill);
try {
Thread.sleep(600);
}
catch (InterruptedException e) {
}
int newXp = sI.skills.getExperience(skill);
if (oldXp != newXp) {
lastXpGain = newXp - oldXp;
lastXpGainTime = System.currentTimeMillis();
}
}
}
public void setRunning(boolean running) {
this.running = running;
}
public Skill getSkill() {
return skill;
}
public int getLastXpGain() {
return lastXpGain;
}
public long getLastXpGainTime() {
return lastXpGainTime;
}
}
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/**
* Created with IntelliJ IDEA
* User: Anthony
* Date: 6/8/2014
*/
public class XPTracker {
private Script sI;
private Set<XPListener> xpListeners;
public XPTracker(Script sI) {
this.sI = sI;
this.xpListeners = new HashSet<>();
}
public void startTrackingSkills(Skill... skills) {
for (Skill s : skills) {
XPListener listener = new XPListener(sI, s);
listener.start();
xpListeners.add(listener);
}
}
public void stopTrackingSkills(Skill... skills) {
Iterator<XPListener> iterator = xpListeners.iterator();
for (Skill s : skills) {
while (iterator.hasNext()) {
XPListener l = iterator.next();
if (l.getSkill() == s) {
l.setRunning(false);
iterator.remove();
break;
}
}
}
}
public int getLastXpGainForSkill(Skill skill) {
int returnValue = -1;
for (XPListener l : xpListeners) {
if (l.getSkill() == skill) {
returnValue = l.getLastXpGain();
break;
}
}
return returnValue;
}
public long getLastXpGainTimeForSkill(Skill skill) {
long returnValue = -1;
for (XPListener l : xpListeners) {
if (l.getSkill() == skill) {
returnValue = l.getLastXpGainTime();
break;
}
}
return returnValue;
}
public Set<XPListener> getXpListeners() {
return xpListeners;
}
}
Code is shit I wrote it awhile ago (it's not even a listener lol idk why I called it that). Create and register like so:
XPTracker tracker = new XPTracker(this);
tracker.startTrackingSkills(Skill.FLETCHING);
The check using tracker methods:
tracker.getLastXpGainTimeForSkill(Skill.FLETCHING) // returns milliseconds since last xp gain