Okay. Gimme a few minutes
I don't want to spoon feed everything, but this should be a good basis.
Also note that this class extends the API so you wont have to use script.client or script.inventory.
The thread will automatically stop after a script has stopped.
import org.osbot.rs07.Bot;
import org.osbot.rs07.script.API;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Xerion on 16-1-2017.
*/
public class InventoryObserver extends API {
private List<InventoryListener> listeners = new ArrayList<>();
/**
*
* @param bot
*/
public InventoryObserver(Bot bot){
this.exchangeContext(bot);
new Thread(() -> {
logger.debug("Started: InventoryWatcher");
while (isRunning()) {
try {
sleep(loop());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
logger.debug("Stopped: InventoryWatcher");
}).start();
}
@[member=Override]
public void initializeModule() {
}
/**
*
* @[member=Return]
*/
private int loop(){
/**
* Add your code here to check if item is added/removed
*/
return 100;
}
/**
*
* @[member=Return] True if a script is running
*/
private boolean isRunning(){
return bot.getScriptExecutor().getCurrent() != null;
}
/**
*
* @param listener
*/
public void addListener(InventoryListener listener) {
listeners.add(listener);
}
/**
*
* @param listener
*/
public void removeListener(InventoryListener listener) {
if(listener != null && listeners.contains(listener)) {
listeners.remove(listener);
}
}
}