Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best practices in regex matching and editing the entire component content #1092

Closed
kangarko opened this issue Jul 13, 2024 · 1 comment
Closed

Comments

@kangarko
Copy link

I have an anti-caps feature in my plugin and I am looking to know what is the best practice to replace excessive caps in an Adventure component.

Current code (chatMessage is a legacy string):

final String[] words = chatMessage.split(" ");

boolean capsAllowed = false;
boolean whitelisted = false;

for (int i = 0; i < words.length; i++) {
	final String word = words[i];

       // Some logic code here
	 
	if (!whitelisted) {
		if (!capsAllowed) {
			final char firstChar = word.charAt(0);

			words[i] = firstChar + word.toLowerCase().substring(1);

		} else
			words[i] = word.toLowerCase();

		capsAllowed = !words[i].endsWith(".") && !words[i].endsWith("!") && !words[i].endsWith("?");
	}

	whitelisted = false;
}

// I need to set the component here.
String.join(" ", words);

My current solution involves converting the component to legacy and then back which destroys hover/click events and to my knowledge has a unnecessarily performance hit.

Any advice would be greatly appreciated!

Matej

@kangarko kangarko changed the title Best practices in regex matching Best practices in regex matching and editing the entire component content Jul 13, 2024
@PedroMPagani
Copy link

A couple of rewrites and you can get there

@KyoriPowered KyoriPowered locked and limited conversation to collaborators Jul 15, 2024
@kezz kezz converted this issue into discussion #1094 Jul 15, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants