Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Resource [Official] Bot Skeleton (Java)

Engineer
Joined
Jul 28, 2013
Messages
2,776
Code:
import com.runemate.game.api.client.embeddable.EmbeddableUI;
import com.runemate.game.api.hybrid.util.Resources;
import com.runemate.game.api.script.framework.LoopingScript;
import com.runemate.game.api.script.framework.listeners.MoneyPouchListener;
import com.runemate.game.api.script.framework.listeners.events.MoneyPouchEvent;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.control.ComboBox;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ResourceBundle;

public final class JavaFramework extends LoopingBot implements EmbeddableUI, Initializable, MoneyPouchListener {
    private String aSetting;

    // Loading a control from FXML using fx:id and Initializable. Use external resources to learn about Initializable and FXML.
    @FXML
    private ComboBox comboBox;

    // Required to tell the client that the bot is EmbeddableUI compatible. Remember, that a bot's main class must have a public no-args constructor, which every Object has by default.
    public JavaFramework() {
        setEmbeddableUI(this);
    }

    @Override
    public void onStart(String... args) {
        // Submit your MoneyPouchListener
        getEventDispatcher().addListener(this);
        // Sets the length of time in milliseconds to wait before calling onLoop again
        setLoopDelay(400, 800);
        // Load script configuration
        aSetting = getSettings().getProperty("setting");
    }

    @Override
    public void onLoop() {
        // Logic goes here
    }

    @Override
    public void onContentsChanged(MoneyPouchEvent moneyPouchEvent) {
        // React to money pouch event
    }

    // JavaFX code begins here. Don't want a UI for some crazy reason? Delete this stuff, delete the public no-args constructor, and un-implement EmbeddableUI and Initializable. Also keep in mind that all of this can and should be abstracted away from the main class. It's put here for example's sake only.

    @Override
    public ObjectProperty<? extends Node> botInterfaceProperty() {
        if (botInterfaceProperty == null) {
            InputStream input = Resources.getAsStream("path/to/fxml/javafx.fxml");
            if (input != null) {
                FXMLLoader loader = new FXMLLoader();
                // setting the controller to this class which implements Initializable
                loader.setController(this);
                try {
                    Parent root = loader.load(input);
                    botInterfaceProperty = new SimpleObjectProperty<>(root);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return botInterfaceProperty;
    }

    private ObjectProperty<? extends Node> botInterfaceProperty;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        // UI code goes here
    }
}

And of course an XML Manifest is also needed. :)
 
Last edited by a moderator:
Top