Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Some help with Regex


Scriptly
 Share

Recommended Posts

I'm making a kill counter for solo and double bedwars on Hypixel.

Hypixel doesn't use normal kill/death events, so someone recommended to use Regex patterns with ClientChatReceivedEvent. I've gotten this far and everything seems right. If someone could

look at this and tell me what I did wrong that would be great.

 

Screenshot_7.png

Link to comment
Share on other sites

A-Za-z -> A-z

 

Also, don't post pictures of code.

Also, show examples of text that needs to be matched (both positives, false positives, and false negatives).

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Sorry about the picture of code.

Some examples are: "

 
 
 
1
54 minutes ago, Draco18s said:

A-Za-z -> A-z

 

Also, don't post pictures of code.

Also, show examples of text that needs to be matched (both positives, false positives, and false negatives).

Sorry about the picture of code.

Some examples are:

"Mega3008 was killed by Scriptly!" (The name at the end would be the players name)

"The_Theif was killed by Scriptly!"

"Arant was stomped by Scriptly."

"Xeroplasma was glazed in BBQ sauce by Scriptly."

Link to comment
Share on other sites

Your examples have a character after the players name, but the regex isn't looking for it.

 

This may work for you (its basically what you had but shortened and captures the character at the end):

"\\w+ [ |\\w]+ (by|of|to|for) " + Minecraft.getMinecraft().thePlayer.getName() + "."

 

Or this one if you want to use capture groups to grab the name to keep track of how often a player is killed

"(\\w+) [ |\\w]+ (by|of|to|for) " + Minecraft.getMinecraft().thePlayer.getName() + "."

 

I use this url when working with regex: https://regex101.com

 

If that still doesn't work you'll want to verify the messages received are in the format you expect.

Link to comment
Share on other sites

5 hours ago, diesieben07 said:

Literal text needs to be escaped using Pattern.quote when embedded in a regular expression.

    @SubscribeEvent
    public void chatReceivedEvent(ClientChatReceivedEvent event) {
        Pattern p = Pattern.compile("\\w{1,16} [ A-Za-z0-9_]+ (by|of|to|for) "+Pattern.quote(Minecraft.getMinecraft().thePlayer.getName()));
        Matcher m = p.matcher(event.message.getUnformattedText());
        if (m.matches()) {
        ++kills;
        }
    }  

Does this look right? I haven't gotten it to work yet.

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.   Restore formatting

  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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.