Resource [Official] Bot Skeleton (Java)

Discussion in 'Tutorials & Resources' started by Cloud, Mar 19, 2014.

  1. Code (Text):
    1. import com.runemate.game.api.client.embeddable.EmbeddableUI;
    2. import com.runemate.game.api.hybrid.util.Resources;
    3. import com.runemate.game.api.script.framework.LoopingScript;
    4. import com.runemate.game.api.script.framework.listeners.MoneyPouchListener;
    5. import com.runemate.game.api.script.framework.listeners.events.MoneyPouchEvent;
    6. import javafx.beans.property.ObjectProperty;
    7. import javafx.beans.property.SimpleObjectProperty;
    8. import javafx.fxml.FXML;
    9. import javafx.fxml.FXMLLoader;
    10. import javafx.fxml.Initializable;
    11. import javafx.scene.Node;
    12. import javafx.scene.Parent;
    13. import javafx.scene.control.ComboBox;
    14.  
    15. import java.io.IOException;
    16. import java.io.InputStream;
    17. import java.net.URL;
    18. import java.util.ResourceBundle;
    19.  
    20. public final class JavaFramework extends LoopingScript implements EmbeddableUI, Initializable, MoneyPouchListener {
    21.     private String aSetting;
    22.  
    23.     // Loading a control from FXML using fx:id and Initializable. Use external resources to learn about Initializable and FXML.
    24.     @FXML
    25.     private ComboBox comboBox;
    26.  
    27.     // 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.
    28.     public JavaFramework() {
    29.         setEmbeddableUI(this);
    30.     }
    31.  
    32.     @Override
    33.     public void onStart(String... args) {
    34.         // Submit your MoneyPouchListener
    35.         getEventDispatcher().addListener(this);
    36.         // Sets the length of time in milliseconds to wait before calling onLoop again
    37.         setLoopDelay(400, 800);
    38.         // Load script configuration
    39.         aSetting = getSettings().getProperty("setting");
    40.     }
    41.  
    42.     @Override
    43.     public void onLoop() {
    44.         // Logic goes here
    45.     }
    46.  
    47.     @Override
    48.     public void onContentsChanged(MoneyPouchEvent moneyPouchEvent) {
    49.         // React to money pouch event
    50.     }
    51.  
    52.     // 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.
    53.  
    54.     @Override
    55.     public ObjectProperty<? extends Node> botInterfaceProperty() {
    56.         if (botInterfaceProperty == null) {
    57.             InputStream input = Resources.getAsStream("path/to/fxml/javafx.fxml");
    58.             if (input != null) {
    59.                 FXMLLoader loader = new FXMLLoader();
    60.                 // setting the controller to this class which implements Initializable
    61.                 loader.setController(this);
    62.                 try {
    63.                     Parent root = loader.load(input);
    64.                     botInterfaceProperty = new SimpleObjectProperty<>(root);
    65.                 } catch (IOException e) {
    66.                     e.printStackTrace();
    67.                 }
    68.             }
    69.         }
    70.         return botInterfaceProperty;
    71.     }
    72.  
    73.     private ObjectProperty<? extends Node> botInterfaceProperty;
    74.  
    75.     @Override
    76.     public void initialize(URL location, ResourceBundle resources) {
    77.         // UI code goes here
    78.     }
    79. }
    And of course an XML Manifest is also needed. :)
     
    #1 Cloud, Mar 19, 2014
    Last edited by a moderator: Apr 22, 2016
    Baddest Man on Earth likes this.
  2. Updated
     
  3. Updated for Beta 42
     
  4. No problem at all, if you run into any issues please post in Client Support.
     
  5. So....What exactly is this?
     
  6. @Cloud
    Could you update this for Spectre 2.0 including a nice UI with a single dropdown?
     
  7. I suck at javafx lol
     
  8. High five!
     
  9. Updated.
     
    Salvation and Derk like this.

Share This Page

Loading...