From 2892462bf27ae177e955bd8486adb4853495a02f Mon Sep 17 00:00:00 2001 From: chsami <23292806+chsami@users.noreply.github.com> Date: Mon, 19 Oct 2026 06:13:12 +0200 Subject: [PATCH] fix(sulphurnagua): guard null player location in fighting and runecrafting (2.0.4) handleFighting passed Rs2Player.getWorldLocation() straight into WorldArea.contains, which throws an NPE when the local player is briefly unavailable during logout, hop, death or loading. Skip the tick when the location is null and route the combat-area check through a shared null-safe isInArea helper. Apply the same guard to the Eytallali distance check. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LjtEMzQHGuq4M1Mpqk9pPV --- .../SulphurNaguaPlugin.java | 2 +- .../SulphurNaguaScript.java | 21 ++++++++--- .../SulphurNaguaCombatAreaTest.java | 35 +++++++++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 src/test/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaCombatAreaTest.java diff --git a/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaPlugin.java b/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaPlugin.java index 12fd1b2c14..c2592382b7 100644 --- a/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaPlugin.java +++ b/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaPlugin.java @@ -29,7 +29,7 @@ @Slf4j public class SulphurNaguaPlugin extends Plugin { - public static final String version = "2.0.3"; + public static final String version = "2.0.4"; @Inject SulphurNaguaScript sulphurNaguaScript; diff --git a/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaScript.java b/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaScript.java index be83b19046..f31b80050f 100644 --- a/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaScript.java +++ b/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaScript.java @@ -205,8 +205,11 @@ private int getEffectiveTargetPotions(SulphurNaguaConfig config) { private boolean isInCombatArea() { WorldArea combatArea = getNaguaCombatArea(); - WorldPoint playerLoc = Rs2Player.getWorldLocation(); - return combatArea != null && playerLoc != null && combatArea.contains(playerLoc); + return isInArea(combatArea, Rs2Player.getWorldLocation()); + } + + static boolean isInArea(WorldArea area, WorldPoint point) { + return area != null && point != null && area.contains(point); } private void determineState(SulphurNaguaConfig config) { @@ -486,7 +489,12 @@ private void handleGettingRunecraftingXp(SulphurNaguaConfig config) { return; } - if (Rs2Player.getWorldLocation().distanceTo(EYTALLALI_LOCATION) > 5) { + WorldPoint playerLoc = Rs2Player.getWorldLocation(); + if (playerLoc == null) { + return; + } + + if (playerLoc.distanceTo(EYTALLALI_LOCATION) > 5) { Rs2Walker.walkTo(EYTALLALI_LOCATION); sleep(400, 800); return; @@ -533,9 +541,14 @@ private void handleFighting(SulphurNaguaConfig config) { boolean needsNewTarget = !Rs2Player.isInCombat() || Rs2Player.getInteracting() == null; if (needsNewTarget) { + WorldPoint playerLoc = Rs2Player.getWorldLocation(); + if (playerLoc == null) { + return; + } + WorldArea combatArea = getNaguaCombatArea(); - if (combatArea != null && combatArea.contains(Rs2Player.getWorldLocation())) { + if (isInArea(combatArea, playerLoc)) { var attackingNagua = Microbot.getRs2NpcCache().query() .withName("Sulphur Nagua") diff --git a/src/test/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaCombatAreaTest.java b/src/test/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaCombatAreaTest.java new file mode 100644 index 0000000000..d3d1fa8e07 --- /dev/null +++ b/src/test/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaCombatAreaTest.java @@ -0,0 +1,35 @@ +package net.runelite.client.plugins.microbot.sulphurnaguafigther; + +import net.runelite.api.coords.WorldArea; +import net.runelite.api.coords.WorldPoint; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class SulphurNaguaCombatAreaTest { + + private final WorldArea area = new WorldArea(1350, 9570, 10, 10, 0); + + @Test + void missingPlayerLocationIsNotInArea() { + assertDoesNotThrow(() -> SulphurNaguaScript.isInArea(area, null)); + assertFalse(SulphurNaguaScript.isInArea(area, null)); + } + + @Test + void missingAreaIsNotInArea() { + assertFalse(SulphurNaguaScript.isInArea(null, new WorldPoint(1355, 9575, 0))); + } + + @Test + void pointInsideAreaIsInArea() { + assertTrue(SulphurNaguaScript.isInArea(area, new WorldPoint(1355, 9575, 0))); + } + + @Test + void pointOutsideAreaIsNotInArea() { + assertFalse(SulphurNaguaScript.isInArea(area, new WorldPoint(1400, 9575, 0))); + } +}