From ecfcd6d67b6b424b6ac494534a73ede58031face Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Sun, 14 Oct 2018 02:56:08 +0200 Subject: [PATCH] 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; }