Upgrading Scripts to DreamBot 3
Changelog
Version | Date | Author | Description |
---|---|---|---|
v1.0 | 27/09/2020 | TheCloakdOne | Initial Document |
Overview
This document outlines the required changes that need to be made to a DreamBot2 script to ensure compatibility with DreamBot 3. This document will outline the changes to the static API along with changes to note.
Static API
With the introduction of DreamBot 3 a new static API has been introduced to facilitate easier script development. Due to this all existing non-static methods are now deprecated and will be removed in a later DreamBot 3 release. The table below outlines the main changes between the two API's; ctx
represents MethodContext
Old API | New API |
---|---|
ctx.getGameObjects() |
GameObjects |
ctx.getNPCs() |
NPCs |
ctx.getClient() |
Client |
ctx.getMap() |
Map |
ctx.getGroundItems() |
GroundItems |
ctx.getLocalPlayer() |
Players.getLocal() |
ctx.getTrade() |
Trade |
ctx.getCamera() |
Camera |
ctx.getClientSettings() |
ClientSettings |
ctx.getQuests() |
Quests |
ctx.getKeyboard() |
Keyboard |
ctx.getWorlds() |
Worlds |
ctx.getRandomManager() |
Client.getInstance().getScriptManager().getCurrentScript().getRandomManager() |
ctx.getWorldHopper() |
WorldHopper |
ctx.getQuests() |
Quests |
ctx.getMagic() |
Magic |
ctx.getPrayer() |
Prayers |
ctx.getCombat() |
Combat |
ctx.getWidgets() |
Widgets |
ctx.getTabs() |
Tabs |
ctx.getGrandExchange() |
GrandExchange |
ctx.getBank() |
Bank |
ctx.getDialogues() |
Dialogues |
ctx.getWalking() |
Walking |
ctx.getSkills() |
Skills |
ctx.getEquipment() |
Equipment |
ctx.getInventory() |
Inventory |
ctx.getPlayerSettings() |
PlayerSettings |
ctx.getPlayers() |
Players |
ctx.getMouse() |
Mouse |
API Changes to note
Below changes may also be required if you are using direct methods to sleep or log through MethodContext
;
Old API | New API |
---|---|
ctx.sleep |
Sleep.sleep |
ctx.log |
Logger.log |
GUI Changes
If the script contains a GUI, make sure any Swing component creation is done on the Event Dispatch Thread (EDT), so instead of this when you setup your GUI (whether that be in your onStart
, or wherever):
MyScriptsGUI gui = new MyScriptsGUI();
gui.setVisible(true);
You'll need to make sure it's wrapped like this to make sure it'll be ran on the EDT:
SwingUtilities.invokeLater(() -> {
MyScriptsGUI gui = new MyScriptsGUI();
gui.setVisible(true);
});
Upgrade Script
The below steps can be used to upgrade the majority of DB2 scripts into DB3 API format, your script may still need additional changes if methods are used outside of the list noted above.
Method Changes
The majority of method changes can be swapped out via mass replace (Most IDE's support mass replace (CTRL + SHIFT + R
) such as IntelliJ, Netbeans, Eclipse). Simply go through each line on the below snippet and replace all instances with the second element denoted by a space. ctx
in this instance is a link to the DB2 MethodContext
, replace this with your own or remove ctx.
if using methods directly.
ctx.getGameObjects() GameObjects
ctx.getClient() Client
ctx.getNPCs() NPCs
ctx.getMap() Map
ctx.getGroundItems() GroundItems
ctx.getLocalPlayer() Players.getLocal()
ctx.getTrade() Trade
ctx.log Logger.log
ctx.sleep Sleep.sleep
ctx.getCamera() Camera
ctx.getMouse() Mouse
ctx.getPlayers() Players
ctx.getPlayerSettings() PlayerSettings
ctx.getInventory() Inventory
ctx.getEquipment() Equipment
ctx.getSkills() Skills
ctx.getWalking() Walking
ctx.getDialogues() Dialogues
ctx.getBank() Bank
ctx.getGrandExchange() GrandExchange
ctx.getTabs() Tabs
ctx.getWidgets() Widgets
ctx.getCombat() Combat
ctx.getPrayer() Prayers
ctx.getMagic() Magic
ctx.getQuests() Quests
ctx.getTrade() Trade
ctx.getWorldHopper() WorldHopper
ctx.getKeyboard() Keyboard
ctx.getQuests() Quests
ctx.getClientSettings() ClientSettings
ctx.getWorlds() Worlds
ctx.getRandomManager() Client.getInstance().getScriptManager().getCurrentScript().getRandomManager()
Import Changes
In order to update the required imports within a script it is suggested to use mass replace to cover the majority of imports:
- Find all instances of the below import (or if using a custom framework, a common import across any files that utilize the DreamBot API.):
- Abstract Script:
import org.dreambot.api.script.AbstractScript;
- Task Script:
import org.dreambot.api.script.impl.TaskScript;
- Replace all instances of the above selected import with the below code (we will clean these up shortly);
- Most IDE's support mass replace (
CTRL + SHIFT + R
) such as IntelliJ, Netbeans, Eclipse
java
import org.dreambot.api.script.AbstractScript; //Remove based on above
import org.dreambot.api.script.impl.TaskScript; //Remove based on above
import org.dreambot.api.Client;
import org.dreambot.api.input.Mouse;
import org.dreambot.api.methods.combat.Combat;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.methods.container.impl.bank.Bank;
import org.dreambot.api.methods.container.impl.equipment.Equipment;
import org.dreambot.api.methods.dialogues.Dialogues;
import org.dreambot.api.methods.grandexchange.GrandExchange;
import org.dreambot.api.methods.input.Camera;
import org.dreambot.api.methods.input.Keyboard;
import org.dreambot.api.methods.interactive.GameObjects;
import org.dreambot.api.methods.interactive.NPCs;
import org.dreambot.api.methods.interactive.Players;
import org.dreambot.api.methods.item.GroundItems;
import org.dreambot.api.methods.magic.Magic;
import org.dreambot.api.methods.map.Map;
import org.dreambot.api.methods.prayer.Prayers;
import org.dreambot.api.methods.quest.Quests;
import org.dreambot.api.methods.settings.PlayerSettings;
import org.dreambot.api.methods.skills.Skills;
import org.dreambot.api.methods.tabs.Tabs;
import org.dreambot.api.methods.trade.Trade;
import org.dreambot.api.methods.walking.impl.Walking;
import org.dreambot.api.methods.widget.Widgets;
import org.dreambot.api.methods.worldhopper.WorldHopper;
- Within your IDE navigate to the root src folder of your script and select
Optimize Imports
, this will remove all unneeded imports for the list above along with any redundant imports from DB2. - Build the script and fix any remaining issues