VitaPlugin
Extend this instead of Plugin to get a loop() that runs off the game thread.
ClassRLPlugins API
public class VitaPlugin extends PluginOverride loop(). At every game tick the client starts it on a worker thread, unless the last run is still going. In loop() you may wait: use Delays and the other helpers in com.tonic.api.threaded.
Your @Subscribe methods still run on the game thread. Never wait in them.
If loop() throws a RuntimeException, such as a NullPointerException, the log only says the loop was interrupted, without the error. Check for null, and while you test, catch and log errors yourself.
Example
import com.tonic.api.threaded.Delays;
import com.tonic.api.widgets.BankAPI;
import com.tonic.api.widgets.InventoryAPI;
import com.tonic.util.VitaPlugin;
import net.runelite.client.plugins.PluginDescriptor;
@PluginDescriptor(name = "Shark Withdrawer")
public final class SharkPlugin extends VitaPlugin {
@Override
public void loop() throws Exception {
if (!BankAPI.isOpen() || InventoryAPI.isFull()) {
return;
}
BankAPI.withdraw("Shark", 10, false);
Delays.tick(2);
}
}Members
Constructors
- newVitaPlugin()
Creates a VitaPlugin.
Methods
- voidhaltLoop(Runnable)
Gracefully prematurely end/cancel a running async loop().
- voidloop()
Overridable loop() method.
VitaPlugin()
public VitaPlugin()Creates a VitaPlugin.
haltLoop(Runnable)
public void haltLoop(Runnable callback)Gracefully prematurely end/cancel a running async loop().
Parameters
callback- Callback.
loop()
public void loop() throws ExceptionOverridable loop() method.
It is safe to sleep in, but as a result is not thread safe, so you must use invoke()'s to do operations that require thread safety. It is started from the start of a gametick.
Also allowed
Every class has these, as in plain Java.
toString