Merge pull request #5907 from deathbeam/fix-slayer-counter
Correctly parse slayer task with the and breaks in npc name
This commit is contained in:
@@ -414,11 +414,7 @@ public class ClueScrollPlugin extends Plugin
|
||||
}
|
||||
|
||||
// Remove line breaks and also the rare occasion where there are double line breaks
|
||||
final String text = Text.removeTags(clueScrollText.getText()
|
||||
.replaceAll("-<br>", "-")
|
||||
.replaceAll("<br>", " ")
|
||||
.replaceAll("[ ]+", " ")
|
||||
.toLowerCase());
|
||||
final String text = Text.sanitizeMultilineText(clueScrollText.getText()).toLowerCase();
|
||||
|
||||
// Early return if this is same clue as already existing one
|
||||
if (clue instanceof TextClueScroll)
|
||||
|
||||
@@ -95,7 +95,7 @@ public class SlayerPlugin extends Plugin
|
||||
|
||||
//NPC messages
|
||||
private static final Pattern NPC_ASSIGN_MESSAGE = Pattern.compile(".*Your new task is to kill\\s*(\\d*) (.*)\\.");
|
||||
private static final Pattern NPC_ASSIGN_BOSS_MESSAGE = Pattern.compile("^Excellent. You're now assigned to kill (.*) (\\d+) times.*Your reward point tally is (.*)\\.$");
|
||||
private static final Pattern NPC_ASSIGN_BOSS_MESSAGE = Pattern.compile("^Excellent. You're now assigned to kill (?:the )?(.*) (\\d+) times.*Your reward point tally is (.*)\\.$");
|
||||
private static final Pattern NPC_CURRENT_MESSAGE = Pattern.compile("You're still hunting (.*); you have (\\d*) to go\\..*");
|
||||
|
||||
//Reward UI
|
||||
@@ -259,13 +259,13 @@ public class SlayerPlugin extends Plugin
|
||||
@Subscribe
|
||||
public void onGameTick(GameTick tick)
|
||||
{
|
||||
Widget NPCDialog = client.getWidget(WidgetInfo.DIALOG_NPC_TEXT);
|
||||
if (NPCDialog != null)
|
||||
Widget npcDialog = client.getWidget(WidgetInfo.DIALOG_NPC_TEXT);
|
||||
if (npcDialog != null)
|
||||
{
|
||||
String NPCText = Text.removeTags(NPCDialog.getText()); //remove color and linebreaks
|
||||
final Matcher mAssign = NPC_ASSIGN_MESSAGE.matcher(NPCText); //number, name
|
||||
final Matcher mAssignBoss = NPC_ASSIGN_BOSS_MESSAGE.matcher(NPCText); // name, number, points
|
||||
final Matcher mCurrent = NPC_CURRENT_MESSAGE.matcher(NPCText); //name, number
|
||||
String npcText = Text.sanitizeMultilineText(npcDialog.getText()); //remove color and linebreaks
|
||||
final Matcher mAssign = NPC_ASSIGN_MESSAGE.matcher(npcText); //number, name
|
||||
final Matcher mAssignBoss = NPC_ASSIGN_BOSS_MESSAGE.matcher(npcText); // name, number, points
|
||||
final Matcher mCurrent = NPC_CURRENT_MESSAGE.matcher(npcText); //name, number
|
||||
|
||||
if (mAssign.find())
|
||||
{
|
||||
|
||||
@@ -48,10 +48,26 @@ public class Text
|
||||
/**
|
||||
* In addition to removing all tags, replaces nbsp with space, trims string and lowercases it
|
||||
* @param str The string to standardize
|
||||
*
|
||||
* @return The given `str` that is standardized
|
||||
*/
|
||||
public static String standardize(String str)
|
||||
{
|
||||
return Text.removeTags(str).replace('\u00A0', ' ').trim().toLowerCase();
|
||||
return removeTags(str).replace('\u00A0', ' ').trim().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* In addition to removing all tags, replaces all <br> delimited text with spaces and all multiple continuous
|
||||
* spaces with single space
|
||||
*
|
||||
* @param str The string to sanitize
|
||||
* @return sanitized string
|
||||
*/
|
||||
public static String sanitizeMultilineText(String str)
|
||||
{
|
||||
return removeTags(str
|
||||
.replaceAll("-<br>", "-")
|
||||
.replaceAll("<br>", " ")
|
||||
.replaceAll("[ ]+", " "));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user