chat notifications: simplify finding closing color in pattern matching
Searching the replacement isn't necessary since it won't ever have any additional col tags except for the ones identified by getLastColor, which would be identified even when searching the original message. Instead, just search the original message up to and including the match.
This commit is contained in:
@@ -247,7 +247,7 @@ public class ChatNotificationsPlugin extends Plugin
|
|||||||
StringBuffer stringBuffer = new StringBuffer();
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
final int start = matcher.start();
|
final int start = matcher.start(); // start not end, since username won't contain a col tag
|
||||||
final String closeColor = MoreObjects.firstNonNull(
|
final String closeColor = MoreObjects.firstNonNull(
|
||||||
getLastColor(message.substring(0, start)),
|
getLastColor(message.substring(0, start)),
|
||||||
"<col" + ChatColorType.NORMAL + '>');
|
"<col" + ChatColorType.NORMAL + '>');
|
||||||
@@ -291,26 +291,16 @@ public class ChatNotificationsPlugin extends Plugin
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
String value = matcher.group();
|
final int end = matcher.end();
|
||||||
|
// Determine the ending color by finding the last color tag up to and
|
||||||
// Determine the ending color by:
|
// including the match.
|
||||||
// 1) use the color from value if it has one
|
final String closeColor = MoreObjects.firstNonNull(
|
||||||
// 2) use the last color from stringBuffer + <content between last match and current match>
|
getLastColor(nodeValue.substring(0, end)),
|
||||||
// To do #2 we just search for the last col tag after calling appendReplacement
|
"<col" + ChatColorType.NORMAL + '>');
|
||||||
String endColor = getLastColor(value);
|
|
||||||
|
|
||||||
// Strip color tags from the highlighted region so that it remains highlighted correctly
|
// Strip color tags from the highlighted region so that it remains highlighted correctly
|
||||||
value = stripColor(value);
|
final String value = stripColor(matcher.group());
|
||||||
|
|
||||||
matcher.appendReplacement(stringBuffer, "<col" + ChatColorType.HIGHLIGHT + '>' + value);
|
matcher.appendReplacement(stringBuffer, "<col" + ChatColorType.HIGHLIGHT + '>' + value + closeColor);
|
||||||
|
|
||||||
if (endColor == null)
|
|
||||||
{
|
|
||||||
endColor = getLastColor(stringBuffer.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Append end color
|
|
||||||
stringBuffer.append(endColor == null ? "<col" + ChatColorType.NORMAL + ">" : endColor);
|
|
||||||
|
|
||||||
update = true;
|
update = true;
|
||||||
matchesHighlight = true;
|
matchesHighlight = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user