diff --git a/gradle.properties b/gradle.properties index aad34d263dd..84b4c935c44 100644 --- a/gradle.properties +++ b/gradle.properties @@ -31,7 +31,7 @@ project.build.group=net.runelite project.build.version=1.12.22 glslang.path= -microbot.version=2.1.30 +microbot.version=2.1.31 microbot.commit.sha=nogit microbot.repo.url=http://138.201.81.246:8081/repository/microbot-snapshot/ microbot.repo.username= diff --git a/runelite-client/src/main/java/net/runelite/client/game/LootManager.java b/runelite-client/src/main/java/net/runelite/client/game/LootManager.java index fe0718a8f35..9e676155f11 100644 --- a/runelite-client/src/main/java/net/runelite/client/game/LootManager.java +++ b/runelite-client/src/main/java/net/runelite/client/game/LootManager.java @@ -66,6 +66,7 @@ import net.runelite.client.events.ServerNpcLoot; import net.runelite.client.events.NpcLootReceived; import net.runelite.client.events.PlayerLootReceived; +import net.runelite.client.plugins.microbot.util.player.Rs2Player; import net.runelite.client.util.Text; @Singleton @@ -161,7 +162,7 @@ public void onPlayerDespawned(PlayerDespawned playerDespawned) return; } - final WorldPoint worldPoint = player.getWorldLocation(); + final WorldPoint worldPoint = Rs2Player.getWorldLocation(); final LocalPoint location = LocalPoint.fromWorld(client, worldPoint); if (location == null || killPoints.contains(worldPoint)) { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java index 0c78afa7e4f..4c93ed04372 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java @@ -44,6 +44,7 @@ import net.runelite.api.Point; import net.runelite.api.coords.LocalPoint; import net.runelite.api.coords.WorldPoint; +import net.runelite.client.plugins.microbot.util.player.Rs2Player; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayLayer; import net.runelite.client.ui.overlay.OverlayPosition; @@ -78,7 +79,7 @@ public Dimension render(Graphics2D g) return null; } - WorldPoint playerLoc = player.getWorldLocation(); + WorldPoint playerLoc = Rs2Player.getWorldLocation(); if (playerLoc.getRegionID() != KourendLibraryPlugin.REGION) { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryTutorialOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryTutorialOverlay.java index 69090946dcb..c81013c433f 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryTutorialOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryTutorialOverlay.java @@ -30,6 +30,7 @@ import net.runelite.api.Client; import net.runelite.api.Player; import net.runelite.api.coords.WorldPoint; +import net.runelite.client.plugins.microbot.util.player.Rs2Player; import net.runelite.client.ui.overlay.OverlayPanel; import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.components.LineComponent; @@ -77,7 +78,7 @@ public Dimension render(Graphics2D graphics) return null; } - WorldPoint playerLoc = player.getWorldLocation(); + WorldPoint playerLoc = Rs2Player.getWorldLocation(); if (playerLoc.getRegionID() != KourendLibraryPlugin.REGION) { return null; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/MicrobotPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/MicrobotPlugin.java index 147996e076c..be7f3182c39 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/MicrobotPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/MicrobotPlugin.java @@ -179,6 +179,7 @@ protected void startUp() throws AWTException overlayManager.add(gembagOverlay); overlayManager.add(pouchOverlay); } + } protected void shutDown() @@ -502,7 +503,7 @@ public void onOverlayMenuClicked(OverlayMenuClicked overlayMenuClicked) @Subscribe public void onGameTick(GameTick event) - { + { // Cache loading is now handled properly during login/profile changes // No need to call loadInitialCacheFromCurrentConfig on every tick } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginScript.java b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginScript.java index bb5c9d9376e..3e11e78d320 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginScript.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginScript.java @@ -243,6 +243,15 @@ private void initiateLogin(AutoLoginConfig config) { boolean membersOnly = config.membersOnly(); + if (config.usePreferredWorld() && config.world() > 0) { + if (Rs2WorldUtil.canAccessWorld(config.world())) { + targetWorld = config.world(); + log.info("Using preferred world: {}", targetWorld); + } else { + log.warn("Preferred world {} is not accessible, falling back to world selection mode", config.world()); + } + } + // use world selection mode if no preferred world or preferred world not accessible if (targetWorld == -1) { switch (config.worldSelectionMode()) { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/api/boat/models/Rs2BoatModel.java b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/api/boat/models/Rs2BoatModel.java index 9ec9595b3ef..9c47ca2b1ee 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/api/boat/models/Rs2BoatModel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/api/boat/models/Rs2BoatModel.java @@ -15,6 +15,7 @@ import net.runelite.client.plugins.microbot.api.boat.data.PortTaskVarbits; import net.runelite.client.plugins.microbot.globval.enums.InterfaceTab; import net.runelite.client.plugins.microbot.util.menu.NewMenuEntry; +import net.runelite.client.plugins.microbot.util.player.Rs2Player; import net.runelite.client.plugins.microbot.util.tabs.Rs2Tab; import net.runelite.client.plugins.microbot.util.widget.Rs2Widget; @@ -255,7 +256,7 @@ public WorldPoint getPlayerBoatLocation() return null; } - WorldPoint playerLocation = player.getWorldLocation(); + WorldPoint playerLocation = Rs2Player.getWorldLocation(); LocalPoint localPoint = LocalPoint.fromWorld( player.getWorldView(), playerLocation diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/helpers/miniquests/enchantedkey/EnchantedKeyDigStep.java b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/helpers/miniquests/enchantedkey/EnchantedKeyDigStep.java index 72b02d328f7..3e6bd6e3b8a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/helpers/miniquests/enchantedkey/EnchantedKeyDigStep.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/helpers/miniquests/enchantedkey/EnchantedKeyDigStep.java @@ -42,6 +42,7 @@ import net.runelite.api.gameval.VarbitID; import net.runelite.client.eventbus.Subscribe; import net.runelite.client.game.ItemManager; +import net.runelite.client.plugins.microbot.util.player.Rs2Player; import net.runelite.client.ui.overlay.OverlayUtil; import net.runelite.client.ui.overlay.components.LineComponent; import net.runelite.client.ui.overlay.components.PanelComponent; @@ -184,7 +185,7 @@ public boolean update(final String message) return false; } - final WorldPoint localWorld = player.getWorldLocation(); + final WorldPoint localWorld = Rs2Player.getWorldLocation(); if (localWorld == null) { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/helpers/quests/monkeymadnessii/AgilityDungeonSteps.java b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/helpers/quests/monkeymadnessii/AgilityDungeonSteps.java index d748245ef5c..7de82ad5d86 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/helpers/quests/monkeymadnessii/AgilityDungeonSteps.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/helpers/quests/monkeymadnessii/AgilityDungeonSteps.java @@ -44,6 +44,7 @@ import net.runelite.api.events.GameTick; import net.runelite.api.gameval.*; import net.runelite.client.eventbus.Subscribe; +import net.runelite.client.plugins.microbot.util.player.Rs2Player; import java.util.*; @@ -416,7 +417,7 @@ public void checkSection5Successes() { return; } - WorldPoint currentPosition = player.getWorldLocation(); + WorldPoint currentPosition = Rs2Player.getWorldLocation(); for (int i = 0; i < fifthSectionMap.length; i++) { MM2Route[] pathsFromNode = fifthSectionMap[i].getPaths(); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/managers/QuestMenuHandler.java b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/managers/QuestMenuHandler.java index 4a411b70fb2..d05de52e615 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/managers/QuestMenuHandler.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/managers/QuestMenuHandler.java @@ -33,6 +33,7 @@ import net.runelite.api.*; import net.runelite.api.coords.WorldPoint; import net.runelite.api.gameval.InterfaceID; +import net.runelite.client.plugins.microbot.util.player.Rs2Player; import net.runelite.client.util.Text; import javax.inject.Inject; @@ -130,7 +131,7 @@ private void handleShieldOfArrav() return; } - WorldPoint location = player.getWorldLocation(); + WorldPoint location = Rs2Player.getWorldLocation(); QuestHelperQuest questToStart = PHOENIX_START_ZONE.contains(location) ? QuestHelperQuest.SHIELD_OF_ARRAV_PHOENIX_GANG : QuestHelperQuest.SHIELD_OF_ARRAV_BLACK_ARM_GANG; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/statemanagement/PlayerStateManager.java b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/statemanagement/PlayerStateManager.java index c761f48baa5..de991b8078b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/statemanagement/PlayerStateManager.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/statemanagement/PlayerStateManager.java @@ -41,6 +41,7 @@ import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.Subscribe; +import net.runelite.client.plugins.microbot.util.player.Rs2Player; import javax.inject.Inject; import javax.inject.Singleton; @@ -124,7 +125,7 @@ public void onGameTick(GameTick gameTick) Player player = client.getLocalPlayer(); if (player != null) { - WorldPoint newPos = player.getWorldLocation(); + WorldPoint newPos = Rs2Player.getWorldLocation(); if (newPos != null && lastPlayerPos != null) { if (newPos.distanceTo(lastPlayerPos) != 0) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/bank/Rs2Bank.java b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/bank/Rs2Bank.java index 9e3b06abeae..f7d5632302d 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/bank/Rs2Bank.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/bank/Rs2Bank.java @@ -17,6 +17,7 @@ import net.runelite.client.plugins.loottracker.LootTrackerItem; import net.runelite.client.plugins.loottracker.LootTrackerRecord; import net.runelite.client.plugins.microbot.Microbot; +import net.runelite.client.plugins.microbot.api.player.models.Rs2PlayerModel; import net.runelite.client.plugins.microbot.shortestpath.ShortestPathPlugin; import net.runelite.client.plugins.microbot.shortestpath.pathfinder.Pathfinder; import net.runelite.client.plugins.microbot.util.antiban.Rs2AntibanSettings; @@ -35,7 +36,6 @@ import net.runelite.client.plugins.microbot.util.npc.Rs2Npc; import net.runelite.client.plugins.microbot.util.npc.Rs2NpcModel; import net.runelite.client.plugins.microbot.util.player.Rs2Player; -import net.runelite.client.plugins.microbot.util.player.Rs2PlayerModel; import net.runelite.client.plugins.microbot.util.security.Encryption; import net.runelite.client.plugins.microbot.util.security.LoginManager; import net.runelite.client.config.ConfigProfile; @@ -85,25 +85,6 @@ public class Rs2Bank { // Used to synchronize calls private static final Object lock = new Object(); - /** - * Gets the current player name safely using Rs2Player utility. - * - * @return Player name or null if not available - */ - private static String getCurrentPlayerName() { - try { - if (Microbot.isLoggedIn()) { - Rs2PlayerModel localPlayer =Rs2Player.getLocalPlayer(); - if (localPlayer != null) { - return localPlayer.getName(); - } - } - } catch (Exception e) { - log.debug("Error getting current player name: {}", e.getMessage()); - } - return null; - } - /** * Container describes from what interface the action happens * eg: withdraw means the contailer will be the bank container @@ -238,7 +219,7 @@ public static Rs2ItemModel findBankItem(String name) { } /** - * check if the player has a bank item identified by id + * check if the Rs2Player has a bank item identified by id * * @param id the item id * @@ -249,7 +230,7 @@ public static boolean hasItem(int id) { } /** - * check if the player has a bank item identified by contains name + * check if the Rs2Player has a bank item identified by contains name * * @param name the item name * @@ -381,7 +362,7 @@ public static boolean hasAllItems(int[] ids, int amount) { } /** - * check if the player has a bank item identified by exact name. + * check if the Rs2Player has a bank item identified by exact name. * * @param name the item name * @@ -392,7 +373,7 @@ public static boolean hasBankItem(String name) { } /** - * check if the player has a bank item identified by exact name. + * check if the Rs2Player has a bank item identified by exact name. * * @param name the item name * @@ -403,7 +384,7 @@ public static boolean hasBankItem(String name, int amount) { } /** - * check if the player has a bank item identified by exact name. + * check if the Rs2Player has a bank item identified by exact name. * * @param name the item name * @@ -414,7 +395,7 @@ public static boolean hasBankItem(String name, int amount, boolean exact) { } /** - * check if the player has a bank item identified by exact name. + * check if the Rs2Player has a bank item identified by exact name. * * @param name the item name * @param exact exact search based on equalsIgnoreCase @@ -894,7 +875,7 @@ public static boolean depositOne(String name) { /** * Deposits a specified amount of an item into the inventory. * This method checks if the bank window is open, if the provided ItemWidget is valid and - * if the player has the item in their inventory. If all conditions are met, it calls the + * if the Rs2Player has the item in their inventory. If all conditions are met, it calls the * 'handleAmount' method to deposit the specified amount of the item into the inventory. * * @param rs2Item item to handle @@ -1130,7 +1111,7 @@ public static boolean depositAllExcept(Predicate predicate) { } /** - * Deposits all items in the player's inventory into the bank, except for the items with the specified IDs. + * Deposits all items in the Rs2Player's inventory into the bank, except for the items with the specified IDs. * This method uses a lambda function to filter out the items with the specified IDs from the deposit operation. * * @param ids The IDs of the items to be excluded from the deposit. @@ -1142,7 +1123,7 @@ public static boolean depositAllExcept(Integer... ids) { } /** - * Deposits all items in the player's inventory into the bank, except for the items with the specified names. + * Deposits all items in the Rs2Player's inventory into the bank, except for the items with the specified names. * This method uses a lambda function to filter out the items with the specified names from the deposit operation. * * @param names The names of the items to be excluded from the deposit. @@ -1154,7 +1135,7 @@ public static boolean depositAllExcept(String... names) { } /** - * Deposits all items in the player's inventory into the bank, except for the items with the specified names. + * Deposits all items in the Rs2Player's inventory into the bank, except for the items with the specified names. * This method uses a lambda function to filter out the items with the specified names from the deposit operation. * * @param names The names of the items to be excluded from the deposit. @@ -1166,7 +1147,7 @@ public static boolean depositAllExcept(Collection names) { } /** - * Deposits all items in the player's inventory into the bank, + * Deposits all items in the Rs2Player's inventory into the bank, * except for the items in the given map. * Each key is the item name, and the value indicates whether to fuzzy match it. * @@ -1184,7 +1165,7 @@ public static boolean depositAllExcept(Map itemsToExclude) { } /** - * Deposits all items in the player's inventory into the bank, except for the items with the specified names. + * Deposits all items in the Rs2Player's inventory into the bank, except for the items with the specified names. * This method uses a lambda function to filter out the items with the specified names from the deposit operation. * It also allows for a delay between deposit operations. * @@ -1644,9 +1625,9 @@ public static boolean openBank() { if (isOpen()) return true; - final Player player = Microbot.getClient().getLocalPlayer(); - if (player == null) return false; - WorldPoint anchor = player.getWorldLocation(); + final Player Rs2Player = Microbot.getClient().getLocalPlayer(); + if (Rs2Player == null) return false; + WorldPoint anchor = Rs2Player.getWorldLocation(); List candidates = Stream.of( Rs2GameObject.findBank(), @@ -1691,9 +1672,9 @@ public static boolean openCollectionBox() { if (collectionBoxIsOpen()) return true; - Player player = Microbot.getClient().getLocalPlayer(); - if (player == null) return false; - WorldPoint anchor = player.getWorldLocation(); + Player Rs2Player = Microbot.getClient().getLocalPlayer(); + if (Rs2Player == null) return false; + WorldPoint anchor = Rs2Player.getWorldLocation(); List candidates = Stream.of( Rs2GameObject.findBank(), @@ -1931,7 +1912,7 @@ private static Rs2ItemModel findBankItem(Collection names, boolean exact } /** - * Returns the nearest accessible bank to the local player’s current location. + * Returns the nearest accessible bank to the local Rs2Player’s current location. * * @return the nearest {@link BankLocation}, or {@code null} if none was reachable */ @@ -1954,7 +1935,7 @@ public static BankLocation getNearestBank(WorldPoint worldPoint) { * Finds the nearest accessible bank location from the given world point. *

* First, searches for bank booth {@link TileObject}s within - * {@code maxObjectSearchRadius} tiles of the player and picks the closest + * {@code maxObjectSearchRadius} tiles of the Rs2Player and picks the closest * one whose underlying {@link BankLocation#hasRequirements()} passes. If no booth * is found or none are within range, falls back to running a full pathfinding * search (including configured transports) to all accessible bank coordinates, @@ -2074,7 +2055,7 @@ public static List getPathToNearestBank(WorldPoint worldPoint) { } /** - * Finds the path to the nearest accessible bank location from the player's current location. + * Finds the path to the nearest accessible bank location from the Rs2Player's current location. * Uses a default search radius of 50 tiles for bank object scanning. * * @return the complete path to the nearest bank as List, or empty list if no accessible bank could be reached @@ -2088,7 +2069,7 @@ public static List getPathToNearestBank() { *

* Uses the same logic as getNearestBank but returns the complete path instead of the BankLocation. * First, searches for bank booth {@link TileObject}s within - * {@code maxObjectSearchRadius} tiles of the player and picks the closest + * {@code maxObjectSearchRadius} tiles of the Rs2Player and picks the closest * one whose underlying {@link BankLocation#hasRequirements()} passes. If no booth * is found or none are within range, falls back to running a full pathfinding * search (including configured transports) to all accessible bank coordinates, @@ -2106,9 +2087,9 @@ public static List getPathToNearestBank(WorldPoint worldPoint, int m /** * Walks to the closest bank using the nearest bank location. - * Toggles run energy if the player is not already running. + * Toggles run energy if the Rs2Player is not already running. * - * @return true if the player's location is within 4 tiles of the bank location. + * @return true if the Rs2Player's location is within 4 tiles of the bank location. */ public static boolean walkToBank() { return walkToBank(getNearestBank()); @@ -2116,10 +2097,10 @@ public static boolean walkToBank() { /** * Walks to a specified bank location. - * Toggles run energy if the player is not already running. + * Toggles run energy if the Rs2Player is not already running. * * @param bankLocation the target bank location to walk to. - * @return true if the player's location is within 4 tiles of the specified bank location. + * @return true if the Rs2Player's location is within 4 tiles of the specified bank location. */ public static boolean walkToBank(BankLocation bankLocation) { return walkToBank(bankLocation, true); @@ -2131,7 +2112,7 @@ public static boolean walkToBank(BankLocation bankLocation) { * * @param bankLocation the target bank location to walk to. * @param toggleRun whether to toggle run energy during the walk. - * @return true if the player's location is within 4 tiles of the specified bank location. + * @return true if the Rs2Player's location is within 4 tiles of the specified bank location. */ public static boolean walkToBank(BankLocation bankLocation, boolean toggleRun) { if (Rs2Bank.isOpen()) return true; @@ -2145,7 +2126,7 @@ public static boolean walkToBank(BankLocation bankLocation, boolean toggleRun) { * Distance from the nearest bank location * * @param distance upper bound distance to be considered 'near' - * @return true if player location is less than distance away from the bank location + * @return true if Rs2Player location is less than distance away from the bank location */ public static boolean isNearBank(int distance) { return isNearBank(getNearestBank(), distance); @@ -2156,7 +2137,7 @@ public static boolean isNearBank(int distance) { * * @param bankLocation the bank location to check distance too * @param distance upper bound distance to be considered 'near' - * @return true if player location is less than distance away from the bank location + * @return true if Rs2Player location is less than distance away from the bank location */ public static boolean isNearBank(BankLocation bankLocation, int distance) { int distanceToBank = Rs2Walker.getDistanceBetween(Rs2Player.getWorldLocation(), bankLocation.getWorldPoint()); @@ -2165,7 +2146,7 @@ public static boolean isNearBank(BankLocation bankLocation, int distance) { /** * Walks to the closest bank and attempts to use the bank interface. - * Toggles run energy if the player is not already running. + * Toggles run energy if the Rs2Player is not already running. * * @return true if the bank interface is successfully opened. */ @@ -2175,7 +2156,7 @@ public static boolean walkToBankAndUseBank() { /** * Walks to a specified bank location and attempts to use the bank interface. - * Toggles run energy if the player is not already running. + * Toggles run energy if the Rs2Player is not already running. * * @param bankLocation the target bank location to walk to and use. * @return true if the bank interface is successfully opened. @@ -2267,40 +2248,40 @@ public static boolean isBankPinWidgetVisible() { } /** - * Banks items if your inventory does not have enough empty slots (0 empty slots being full). Will walk back to the initialPlayerLocation passed as param + * Banks items if your inventory does not have enough empty slots (0 empty slots being full). Will walk back to the initialRs2PlayerLocation passed as param * * @param itemNames - * @param initialPlayerLocation + * @param initialRs2PlayerLocation * @param emptySlotCount * @return */ - public static boolean bankItemsAndWalkBackToOriginalPosition(Collection itemNames, WorldPoint initialPlayerLocation, int emptySlotCount) { - return bankItemsAndWalkBackToOriginalPosition(itemNames,false, getNearestBank(), initialPlayerLocation, emptySlotCount, 4); + public static boolean bankItemsAndWalkBackToOriginalPosition(Collection itemNames, WorldPoint initialRs2PlayerLocation, int emptySlotCount) { + return bankItemsAndWalkBackToOriginalPosition(itemNames,false, getNearestBank(), initialRs2PlayerLocation, emptySlotCount, 4); } /** - * Banks items if your inventory is full. Will walk back to the initialplayerlocation passed as param + * Banks items if your inventory is full. Will walk back to the initialRs2Playerlocation passed as param * * @param itemNames - * @param initialPlayerLocation + * @param initialRs2PlayerLocation * @return */ - public static boolean bankItemsAndWalkBackToOriginalPosition(Collection itemNames, WorldPoint initialPlayerLocation) { - return bankItemsAndWalkBackToOriginalPosition(itemNames,false, getNearestBank(), initialPlayerLocation, 0, 4); + public static boolean bankItemsAndWalkBackToOriginalPosition(Collection itemNames, WorldPoint initialRs2PlayerLocation) { + return bankItemsAndWalkBackToOriginalPosition(itemNames,false, getNearestBank(), initialRs2PlayerLocation, 0, 4); } /** - * Banks at specific bank location if your inventory does not have enough emptyslots (0 emptyslots being full). Will walk back to the initialplayerlocation passed as param + * Banks at specific bank location if your inventory does not have enough emptyslots (0 emptyslots being full). Will walk back to the initialRs2Playerlocation passed as param * * @param itemNames The item names, which can be either item names or item IDs as strings. * @param exactItemNames - * @param initialPlayerLocation + * @param initialRs2PlayerLocation * @param bankLocation * @param emptySlotCount * @param distance * @return */ - public static boolean bankItemsAndWalkBackToOriginalPosition(Collection itemNames, boolean exactItemNames, BankLocation bankLocation, WorldPoint initialPlayerLocation, int emptySlotCount, int distance) { + public static boolean bankItemsAndWalkBackToOriginalPosition(Collection itemNames, boolean exactItemNames, BankLocation bankLocation, WorldPoint initialRs2PlayerLocation, int emptySlotCount, int distance) { if (Rs2Inventory.emptySlotCount() <= emptySlotCount) { boolean isBankOpen = Rs2Bank.walkToBankAndUseBank(bankLocation); if (isBankOpen) { @@ -2319,27 +2300,27 @@ public static boolean bankItemsAndWalkBackToOriginalPosition(Collection if (distance > 10) distance = 10; - if (initialPlayerLocation.distanceTo(Rs2Player.getWorldLocation()) > distance || !Rs2Tile.isTileReachable(initialPlayerLocation)) { - Rs2Walker.walkTo(initialPlayerLocation, distance); + if (initialRs2PlayerLocation.distanceTo(Rs2Player.getWorldLocation()) > distance || !Rs2Tile.isTileReachable(initialRs2PlayerLocation)) { + Rs2Walker.walkTo(initialRs2PlayerLocation, distance); } else { - Rs2Walker.walkFastCanvas(initialPlayerLocation); + Rs2Walker.walkFastCanvas(initialRs2PlayerLocation); } - return !(Rs2Inventory.emptySlotCount() <= emptySlotCount) && initialPlayerLocation.distanceTo(Rs2Player.getWorldLocation()) <= distance; + return !(Rs2Inventory.emptySlotCount() <= emptySlotCount) && initialRs2PlayerLocation.distanceTo(Rs2Player.getWorldLocation()) <= distance; } /** - * Banks items if your inventory does not have enough emptyslots (0 emptyslots being full). Will walk back to the initialplayerlocation passed as param + * Banks items if your inventory does not have enough emptyslots (0 emptyslots being full). Will walk back to the initialRs2Playerlocation passed as param * * @param itemNames - * @param initialPlayerLocation + * @param initialRs2PlayerLocation * @param emptySlotCount * @param distance * * @return */ - public static boolean bankItemsAndWalkBackToOriginalPosition(Collection itemNames, WorldPoint initialPlayerLocation, int emptySlotCount, int distance) { - return bankItemsAndWalkBackToOriginalPosition(itemNames,false, getNearestBank(), initialPlayerLocation, emptySlotCount, distance); + public static boolean bankItemsAndWalkBackToOriginalPosition(Collection itemNames, WorldPoint initialRs2PlayerLocation, int emptySlotCount, int distance) { + return bankItemsAndWalkBackToOriginalPosition(itemNames,false, getNearestBank(), initialRs2PlayerLocation, emptySlotCount, distance); } public static boolean isWithdrawAs(boolean noted) { @@ -2398,7 +2379,7 @@ private static OptionalInt getRunePouch(IntPredicate filter) { } /** - * Withdraws the player's rune pouch if it's available in the bank. + * Withdraws the Rs2Player's rune pouch if it's available in the bank. * * @return true if the rune pouch was withdrawn, false otherwise. */ @@ -2408,7 +2389,7 @@ public static boolean withdrawRunePouch() { } /** - * Deposits the player's rune pouch if it's in the inventory. + * Deposits the Rs2Player's rune pouch if it's in the inventory. * * @return true if the rune pouch was deposited, false otherwise. */ @@ -2418,7 +2399,7 @@ public static boolean depositRunePouch() { } /** - * Checks if the player has any type of rune pouch in the bank. + * Checks if the Rs2Player has any type of rune pouch in the bank. * * @return true if a rune pouch is found in the bank, false otherwise. */ diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/gameobject/Rs2GameObject.java b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/gameobject/Rs2GameObject.java index 833aa30519d..77b1ca0c242 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/gameobject/Rs2GameObject.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/gameobject/Rs2GameObject.java @@ -552,7 +552,7 @@ public static TileObject getTileObject(int id, int distance) { if (player == null) { return null; } - return getTileObject(id, player.getWorldLocation(), distance); + return getTileObject(id, Rs2Player.getWorldLocation(), distance); } public static TileObject getTileObject(int id, WorldPoint anchor) { @@ -626,7 +626,7 @@ public static TileObject getTileObject(Predicate predicate) { if (player == null) { return null; } - return getTileObject(predicate, player.getWorldLocation()); + return getTileObject(predicate, Rs2Player.getWorldLocation()); } public static TileObject getTileObject(WorldPoint anchor) { @@ -650,7 +650,7 @@ public static TileObject getTileObject(Predicate predicate, int dist if (player == null) { return null; } - return getTileObject(predicate, player.getWorldLocation(), distance); + return getTileObject(predicate, Rs2Player.getWorldLocation(), distance); } public static TileObject getTileObject(Predicate predicate, WorldPoint anchor) { @@ -686,7 +686,7 @@ public static List getTileObjects(Predicate predicate, i if (player == null) { return Collections.emptyList(); } - return getTileObjects(predicate, player.getWorldLocation(), distance); + return getTileObjects(predicate, Rs2Player.getWorldLocation(), distance); } public static List getTileObjects(WorldPoint anchor) { @@ -702,7 +702,7 @@ public static List getTileObjects(Predicate predicate) { if (player == null) { return Collections.emptyList(); } - return getTileObjects(predicate, player.getWorldLocation()); + return getTileObjects(predicate, Rs2Player.getWorldLocation()); } public static List getTileObjects(Predicate predicate, WorldPoint anchor) { @@ -734,7 +734,7 @@ public static GameObject getGameObject(int id, int distance) { if (player == null) { return null; } - return getGameObject(id, player.getWorldLocation(), distance); + return getGameObject(id, Rs2Player.getWorldLocation(), distance); } public static GameObject getGameObject(int id, WorldPoint anchor) { @@ -814,7 +814,7 @@ public static GameObject getGameObject(Predicate predicate) { if (player == null) { return null; } - return getGameObject(predicate, player.getWorldLocation()); + return getGameObject(predicate, Rs2Player.getWorldLocation()); } public static GameObject getGameObject(WorldPoint anchor) { @@ -834,11 +834,7 @@ public static GameObject getGameObject(LocalPoint anchorLocal, int distance) { } public static GameObject getGameObject(Predicate predicate, int distance) { - Player player = Microbot.getClient().getLocalPlayer(); - if (player == null) { - return null; - } - return getGameObject(predicate, player.getWorldLocation(), distance); + return getGameObject(predicate, Rs2Player.getWorldLocation(), distance); } public static GameObject getGameObject(Predicate predicate, WorldPoint anchor) { @@ -874,7 +870,7 @@ public static List getGameObjects(Predicate predicate, i if (player == null) { return Collections.emptyList(); } - return getGameObjects(predicate, player.getWorldLocation(), distance); + return getGameObjects(predicate, Rs2Player.getWorldLocation(), distance); } public static List getGameObjects(WorldPoint anchor) { @@ -890,7 +886,7 @@ public static List getGameObjects(Predicate predicate) { if (player == null) { return Collections.emptyList(); } - return getGameObjects(predicate, player.getWorldLocation()); + return getGameObjects(predicate, Rs2Player.getWorldLocation()); } public static List getGameObjects(Predicate predicate, WorldPoint anchor) { @@ -918,11 +914,7 @@ public static GroundObject getGroundObject(int id) { } public static GroundObject getGroundObject(int id, int distance) { - Player player = Microbot.getClient().getLocalPlayer(); - if (player == null) { - return null; - } - return getGroundObject(id, player.getWorldLocation(), distance); + return getGroundObject(id, Rs2Player.getWorldLocation(), distance); } public static GroundObject getGroundObject(int id, WorldPoint anchor) { @@ -992,11 +984,7 @@ public static GroundObject getGroundObject(String objectName, LocalPoint anchorL } public static GroundObject getGroundObject(Predicate predicate) { - Player player = Microbot.getClient().getLocalPlayer(); - if (player == null) { - return null; - } - return getGroundObject(predicate, player.getWorldLocation()); + return getGroundObject(predicate, Rs2Player.getWorldLocation()); } public static GroundObject getGroundObject(WorldPoint anchor) { @@ -1020,7 +1008,7 @@ public static GroundObject getGroundObject(Predicate predicate, in if (player == null) { return null; } - return getGroundObject(predicate, player.getWorldLocation(), distance); + return getGroundObject(predicate, Rs2Player.getWorldLocation(), distance); } public static GroundObject getGroundObject(Predicate predicate, WorldPoint anchor) { @@ -1056,7 +1044,7 @@ public static List getGroundObjects(Predicate predic if (player == null) { return Collections.emptyList(); } - return getGroundObjects(predicate, player.getWorldLocation(), distance); + return getGroundObjects(predicate, Rs2Player.getWorldLocation(), distance); } public static List getGroundObjects(WorldPoint anchor) { @@ -1072,7 +1060,7 @@ public static List getGroundObjects(Predicate predic if (player == null) { return Collections.emptyList(); } - return getGroundObjects(predicate, player.getWorldLocation()); + return getGroundObjects(predicate, Rs2Player.getWorldLocation()); } public static List getGroundObjects(Predicate predicate, WorldPoint anchor) { @@ -1104,7 +1092,7 @@ public static WallObject getWallObject(int id, int distance) { if (player == null) { return null; } - return getWallObject(id, player.getWorldLocation(), distance); + return getWallObject(id, Rs2Player.getWorldLocation(), distance); } public static WallObject getWallObject(int id, WorldPoint anchor) { @@ -1178,7 +1166,7 @@ public static WallObject getWallObject(Predicate predicate) { if (player == null) { return null; } - return getWallObject(predicate, player.getWorldLocation()); + return getWallObject(predicate, Rs2Player.getWorldLocation()); } public static WallObject getWallObject(WorldPoint anchor) { @@ -1202,7 +1190,7 @@ public static WallObject getWallObject(Predicate predicate, int dist if (player == null) { return null; } - return getWallObject(predicate, player.getWorldLocation(), distance); + return getWallObject(predicate, Rs2Player.getWorldLocation(), distance); } public static WallObject getWallObject(Predicate predicate, WorldPoint anchor) { @@ -1238,7 +1226,7 @@ public static List getWallObjects(Predicate predicate, i if (player == null) { return Collections.emptyList(); } - return getWallObjects(predicate, player.getWorldLocation(), distance); + return getWallObjects(predicate, Rs2Player.getWorldLocation(), distance); } public static List getWallObjects(WorldPoint anchor) { @@ -1254,7 +1242,7 @@ public static List getWallObjects(Predicate predicate) { if (player == null) { return Collections.emptyList(); } - return getWallObjects(predicate, player.getWorldLocation()); + return getWallObjects(predicate, Rs2Player.getWorldLocation()); } public static List getWallObjects(Predicate predicate, WorldPoint anchor) { @@ -1286,7 +1274,7 @@ public static DecorativeObject getDecorativeObject(int id, int distance) { if (player == null) { return null; } - return getDecorativeObject(id, player.getWorldLocation(), distance); + return getDecorativeObject(id, Rs2Player.getWorldLocation(), distance); } public static DecorativeObject getDecorativeObject(int id, WorldPoint anchor) { @@ -1360,7 +1348,7 @@ public static DecorativeObject getDecorativeObject(Predicate p if (player == null) { return null; } - return getDecorativeObject(predicate, player.getWorldLocation()); + return getDecorativeObject(predicate, Rs2Player.getWorldLocation()); } public static DecorativeObject getDecorativeObject(WorldPoint anchor) { @@ -1384,7 +1372,7 @@ public static DecorativeObject getDecorativeObject(Predicate p if (player == null) { return null; } - return getDecorativeObject(predicate, player.getWorldLocation(), distance); + return getDecorativeObject(predicate, Rs2Player.getWorldLocation(), distance); } public static DecorativeObject getDecorativeObject(Predicate predicate, WorldPoint anchor) { @@ -1420,7 +1408,7 @@ public static List getDecorativeObjects(Predicate getDecorativeObjects(WorldPoint anchor) { @@ -1436,7 +1424,7 @@ public static List getDecorativeObjects(Predicate getDecorativeObjects(Predicate predicate, WorldPoint anchor) { @@ -1693,7 +1681,7 @@ private static List fetchTileObjects(Predicate List fetchGameObjects(Predicate param0: " + param0 + " param1: " + param1 + " opcode: " + opcode + " id: " + identifier + " itemid: " + itemId); } + private static volatile Field evField; + private static volatile Field aqField; + private static volatile Field ajField; + + private static String[] extractActions(java.util.ArrayList list) { + String[] actions = new String[list.size()]; + for (int i = 0; i < list.size(); i++) { + Object element = list.get(i); + if (element instanceof String) { + actions[i] = (String) element; + } else if (element != null) { + try { + if (ajField == null) { + for (Field f : element.getClass().getDeclaredFields()) { + if (f.getName().equals("aj") && f.getType() == String.class) { + ajField = f; + break; + } + } + } + if (ajField != null) { + ajField.setAccessible(true); + Object val = ajField.get(element); + ajField.setAccessible(false); + actions[i] = val instanceof String ? (String) val : null; + } + } catch (Exception ignored) { + } + } + } + return actions; + } + @SneakyThrows public static String[] getGroundItemActions(ItemComposition item) { - List fields = Arrays.stream(item.getClass().getFields()).filter(x -> x.getType().isArray()).collect(Collectors.toList()); - for (Field field : fields) { - if (field.getType().getComponentType().getName().equals("java.lang.String")) { - String[] actions = (String[]) field.get(item); - if (Arrays.stream(actions).anyMatch(x -> x != null && x.equalsIgnoreCase("take"))) { - field.setAccessible(true); - return actions; + if (evField != null && aqField != null) { + evField.setAccessible(true); + Object ev = evField.get(item); + evField.setAccessible(false); + if (ev != null) { + aqField.setAccessible(true); + Object aq = aqField.get(ev); + aqField.setAccessible(false); + if (aq instanceof java.util.ArrayList) { + return extractActions((java.util.ArrayList) aq); + } + } + } + + for (Class clazz = item.getClass(); clazz != null && clazz != Object.class; clazz = clazz.getSuperclass()) { + for (Field field : clazz.getDeclaredFields()) { + if (!field.getName().equals("ev")) continue; + field.setAccessible(true); + Object value = field.get(item); + field.setAccessible(false); + if (value == null || !value.getClass().getName().equals("oo")) continue; + for (Field innerField : value.getClass().getDeclaredFields()) { + if (!innerField.getName().equals("aq")) continue; + innerField.setAccessible(true); + Object innerValue = innerField.get(value); + innerField.setAccessible(false); + if (innerValue instanceof java.util.ArrayList) { + evField = field; + aqField = innerField; + return extractActions((java.util.ArrayList) innerValue); + } } } } + return new String[]{}; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/specialcounter/SpecialCounterPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/specialcounter/SpecialCounterPlugin.java index cc28a409a2e..ced6de700c9 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/specialcounter/SpecialCounterPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/specialcounter/SpecialCounterPlugin.java @@ -78,6 +78,8 @@ import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import static net.runelite.client.plugins.specialcounter.SpecialWeapon.TONALZTICS_OF_RALOS; + +import net.runelite.client.plugins.microbot.util.player.Rs2Player; import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.infobox.InfoBoxManager; import net.runelite.client.util.ImageUtil; @@ -617,7 +619,7 @@ private int getHitDelay(SpecialWeapon specialWeapon, Actor target) if (player == null) return 1; - WorldPoint playerWp = player.getWorldLocation(); + WorldPoint playerWp = Rs2Player.getWorldLocation(); if (playerWp == null) return 1; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/timersandbuffs/TimersAndBuffsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/timersandbuffs/TimersAndBuffsPlugin.java index f6d4b531e78..9ab84b18980 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/timersandbuffs/TimersAndBuffsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/timersandbuffs/TimersAndBuffsPlugin.java @@ -42,6 +42,7 @@ import net.runelite.client.game.SpriteManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.plugins.microbot.util.player.Rs2Player; import net.runelite.client.ui.overlay.infobox.InfoBoxManager; import net.runelite.client.util.RSTimeUnit; import org.apache.commons.lang3.ArrayUtils; @@ -1219,7 +1220,7 @@ private void checkTeleport(@Varp int varPlayer) public void onGameTick(GameTick event) { Player player = client.getLocalPlayer(); - WorldPoint currentWorldPoint = player.getWorldLocation(); + WorldPoint currentWorldPoint = Rs2Player.getWorldLocation(); if (freezeTimer != null) {