Inverse findClueScroll conditions

For better readability, change the big if blocks in findClueScroll()
method to early returns instead.

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-09-27 12:00:44 +02:00
parent 255ce8ed91
commit 108050a805

View File

@@ -436,17 +436,21 @@ public class ClueScrollPlugin extends Plugin
private ClueScroll findClueScroll() private ClueScroll findClueScroll()
{ {
Widget clueScrollText = client.getWidget(WidgetInfo.CLUE_SCROLL_TEXT); final Widget clueScrollText = client.getWidget(WidgetInfo.CLUE_SCROLL_TEXT);
if (clueScrollText != null) if (clueScrollText == null)
{ {
return null;
}
// Remove line breaks and also the rare occasion where there are double line breaks // Remove line breaks and also the rare occasion where there are double line breaks
String text = Text.removeTags(clueScrollText.getText() final String text = Text.removeTags(clueScrollText.getText()
.replaceAll("-<br>", "-") .replaceAll("-<br>", "-")
.replaceAll("<br>", " ") .replaceAll("<br>", " ")
.replaceAll("[ ]+", " ") .replaceAll("[ ]+", " ")
.toLowerCase()); .toLowerCase());
// Early return if this is same clue as already existing one
if (clue instanceof TextClueScroll) if (clue instanceof TextClueScroll)
{ {
if (((TextClueScroll) clue).getText().equalsIgnoreCase(text)) if (((TextClueScroll) clue).getText().equalsIgnoreCase(text))
@@ -459,24 +463,25 @@ public class ClueScrollPlugin extends Plugin
{ {
return AnagramClue.forText(text); return AnagramClue.forText(text);
} }
else if (text.startsWith("the cipher reveals who to speak to next:"))
if (text.startsWith("the cipher reveals who to speak to next:"))
{ {
return CipherClue.forText(text); return CipherClue.forText(text);
} }
else if (text.contains("degrees") && text.contains("minutes"))
if (text.contains("degrees") && text.contains("minutes"))
{ {
return coordinatesToWorldPoint(text); return coordinatesToWorldPoint(text);
} }
else
{ final CrypticClue crypticClue = CrypticClue.forText(text);
CrypticClue crypticClue = CrypticClue.forText(text);
if (crypticClue != null) if (crypticClue != null)
{ {
return crypticClue; return crypticClue;
} }
EmoteClue emoteClue = EmoteClue.forText(text); final EmoteClue emoteClue = EmoteClue.forText(text);
if (emoteClue != null) if (emoteClue != null)
{ {
@@ -509,10 +514,6 @@ public class ClueScrollPlugin extends Plugin
resetClue(true); resetClue(true);
return null; return null;
} }
}
return null;
}
/** /**
* Example input: "00 degrees 00 minutes north 07 degrees 13 minutes west" * Example input: "00 degrees 00 minutes north 07 degrees 13 minutes west"