From ecfcd6d67b6b424b6ac494534a73ede58031face Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Sun, 14 Oct 2018 02:56:08 +0200 Subject: [PATCH 1/3] Make 3 step cryptic clues more robust (better splitting) - Instead of depending on specific formatting and size of clue text, just split and parse everything stripping all tags when needed. - Exit early on size < 3 to prevent NPEs and ArrayOutOfBounds Signed-off-by: Tomas Slusny --- .../clues/ThreeStepCrypticClue.java | 61 ++++++------------- 1 file changed, 19 insertions(+), 42 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/ThreeStepCrypticClue.java b/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/ThreeStepCrypticClue.java index 3858f6c68a..45efa2a36b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/ThreeStepCrypticClue.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/ThreeStepCrypticClue.java @@ -47,17 +47,16 @@ import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin; import net.runelite.client.ui.overlay.components.LineComponent; import net.runelite.client.ui.overlay.components.PanelComponent; import net.runelite.client.ui.overlay.components.TitleComponent; +import net.runelite.client.util.Text; @Getter public class ThreeStepCrypticClue extends ClueScroll implements TextClueScroll, ObjectClueScroll, NpcClueScroll, LocationsClueScroll { - private static final int CLUE_STEPS = 3; - - private List> clueSteps; - private int[] objectIds; + private final List> clueSteps; + private final int[] objectIds; + private final String[] npcs; + private final String text; private WorldPoint[] locations; - private String[] npcs; - private String text; private ThreeStepCrypticClue(List> steps, String text) { @@ -70,8 +69,7 @@ public class ThreeStepCrypticClue extends ClueScroll implements TextClueScroll, for (int i = 0; i < numClueSteps; i++) { - CrypticClue c = clueSteps.get(i).getKey(); - + final CrypticClue c = clueSteps.get(i).getKey(); locations[i] = c.getLocation(); npcs[i] = c.getNpc(); objectIds[i] = c.getObjectId(); @@ -83,9 +81,9 @@ public class ThreeStepCrypticClue extends ClueScroll implements TextClueScroll, { panelComponent.setPreferredSize(new Dimension(200, 0)); - for (int i = 0; i < CLUE_STEPS; i++) + for (int i = 0; i < clueSteps.size(); i++) { - Map.Entry e = clueSteps.get(i); + final Map.Entry e = clueSteps.get(i); if (!e.getValue()) { @@ -142,48 +140,27 @@ public class ThreeStepCrypticClue extends ClueScroll implements TextClueScroll, public static ThreeStepCrypticClue forText(String plainText, String text) { - List> steps = new ArrayList<>(CLUE_STEPS); - StringBuilder threeStepText = new StringBuilder(text.replaceAll("

", " ").toLowerCase()); - boolean stepDone; + final String[] split = text.split("
\\s*
"); + final List> steps = new ArrayList<>(split.length); - for (int i = 0; i < CLUE_STEPS; i++) + for (String part : split) { - // if text has - strikethrough - tag then it is already done - stepDone = threeStepText.toString().startsWith(""); - - if (stepDone) - { - // chop off tag - threeStepText.delete(0, 5); - } + boolean isDone = part.contains(""); + final String rawText = Text.sanitizeMultilineText(part); for (CrypticClue clue : CrypticClue.CLUES) { - if (threeStepText.toString().startsWith(clue.getText().toLowerCase())) + if (!rawText.equalsIgnoreCase(clue.getText())) { - if (stepDone) - { - steps.add(new AbstractMap.SimpleEntry<>(clue, true)); - // chop off tag - threeStepText.delete(0, 6); - } - else - { - steps.add(new AbstractMap.SimpleEntry<>(clue, false)); - } - - if (i < CLUE_STEPS - 1) - { - // chop off the length of the clue text plus a space - threeStepText.delete(0, clue.getText().length() + 1); - } - - break; + continue; } + + steps.add(new AbstractMap.SimpleEntry<>(clue, isDone)); + break; } } - if (steps.isEmpty()) + if (steps.isEmpty() || steps.size() < 3) { return null; } From 636aa2f0799460c60269be91ea68dbc80f1a5097 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Sun, 14 Oct 2018 18:04:44 +0200 Subject: [PATCH 2/3] Null-check location for multi-location clues Sometimes it can be null. Signed-off-by: Tomas Slusny --- .../client/plugins/cluescrolls/ClueScrollPlugin.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/ClueScrollPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/ClueScrollPlugin.java index 08067ca341..e52ffa3e82 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/ClueScrollPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/ClueScrollPlugin.java @@ -308,7 +308,10 @@ public class ClueScrollPlugin extends Plugin { for (WorldPoint location : locations) { - highlightObjectsForLocation(location, objectIds); + if (location != null) + { + highlightObjectsForLocation(location, objectIds); + } } } } From 72bf82348ab1d86317bf0e8ed83185ae504461f3 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Sun, 14 Oct 2018 18:10:35 +0200 Subject: [PATCH 3/3] Fix punctionation in "Fiendish cooks" cryptic clue Closes #5968 Signed-off-by: Tomas Slusny --- .../runelite/client/plugins/cluescrolls/clues/CrypticClue.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/CrypticClue.java b/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/CrypticClue.java index 86016aa169..eb2e0142eb 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/CrypticClue.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/CrypticClue.java @@ -195,7 +195,7 @@ public class CrypticClue extends ClueScroll implements TextClueScroll, NpcClueSc new CrypticClue("Reflection is the weakness for these eyes of evil.", null, "Kill a basilisk."), new CrypticClue("Search a bookcase in Lumbridge swamp.", BOOKCASE_9523, new WorldPoint(3146, 3177, 0), "Located in Father Urhney's house."), new CrypticClue("Surround my bones in fire, ontop the wooden pyre. Finally lay me to rest, before my one last test.", null, "Kill a confused/lost barbarian to receive mangled bones. Construct and burn a pyre ship. Kill the ferocious barbarian spirit that spawns to receive a clue casket."), - new CrypticClue("Fiendish cooks probably won’t dig the dirty dishes.", new WorldPoint(3043, 4974, 1), "Dig by the fire in the Rogues' Den."), + new CrypticClue("Fiendish cooks probably won't dig the dirty dishes.", new WorldPoint(3043, 4974, 1), "Dig by the fire in the Rogues' Den."), new CrypticClue("My life was spared but these voices remain, now guarding these iron gates is my bane.", "Key Master", new WorldPoint(1310, 1251, 0), "Speak to the Key Master in Cerberus' Lair."), new CrypticClue("Search the boxes in one of the tents in Al Kharid.", BOXES_361, new WorldPoint(3308, 3206, 0), "Search the boxes in the tent east of the Silk trader."), new CrypticClue("One of several rhyming brothers, in business attire with an obsession for paper work.", "Piles", new WorldPoint(3186, 3936, 0), "Speak to Piles in the Wilderness Resource Area. An entry fee of 7,500 coins is required, or less if Wilderness Diaries have been completed."),