Jump to content

Parsing valuable drop notification


Polymorphism

Recommended Posts

Takes a little bit of regex but it's simple to do.

Instead of adding the item name to a list, in my loop() I do if valuableLootName !empty then force loot the one item, then resume normal function.

 

				String tmpLootName = "";
				if (msg.contains("aluable drop")) {
					tmpLootName = msg.replace("<col=ef1020>", "").replace("</col>", "")
							.replaceFirst("(.{0,15})", "").replaceFirst("(\\d x)", "")
							.replaceFirst("\\(([^\\)]+)\\)", "").trim();
					log("DROP MESSAGE: " + tmpLootName);
					valuableLootName = tmpLootName;
				}

 

Link to comment
Share on other sites

13 hours ago, Swizzbeat said:

Overcomplicated to hell. A simple between : and ( parsing with trim would suffice.

 

 

Meh, looks overcomplicated to hell. You'd still have to parse out the quantity by going with substring and trim. I found it easier on my eyes to do it this way, and the speed difference is so little it's laughable. Now if we were doing like 20k of these in one go this would be done a little different.

Link to comment
Share on other sites

14 hours ago, Polymorphism said:

Takes a little bit of regex but it's simple to do.

Instead of adding the item name to a list, in my loop() I do if valuableLootName !empty then force loot the one item, then resume normal function.

 


				String tmpLootName = "";
				if (msg.contains("aluable drop")) {
					tmpLootName = msg.replace("<col=ef1020>", "").replace("</col>", "")
							.replaceFirst("(.{0,15})", "").replaceFirst("(\\d x)", "")
							.replaceFirst("\\(([^\\)]+)\\)", "").trim();
					log("DROP MESSAGE: " + tmpLootName);
					valuableLootName = tmpLootName;
				}

 

 

13 hours ago, Swizzbeat said:

Overcomplicated to hell. A simple between : and ( parsing with trim would suffice.

 

Agreed, this is over complicated. Either of these options would suffice:

Where the message is:

 String lootMessage = "<col=ef1020>Valuable drop: Onyx (3,038,047 coins)</col>";

 

Matcher m = Pattern.compile(": (.+) \\(").matcher(lootMessage);
if (m.find()) {
    String loot = m.group(1);
}

or

String loot = lootMessage.substring(lootMessage.indexOf(": ") + 2, lootMessage.lastIndexOf(" ("));

 

Edited by Explv
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...