Jump to content

Parsing valuable drop notification


Recommended Posts

Posted

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;
				}

 

Posted
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.

Posted (edited)
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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