mirror of
https://github.com/games647/ColorConsole.git
synced 2025-02-18 21:11:20 +01:00
Use regex for checking for the presence of plugin tags
This commit is contained in:
parent
7ca5986b76
commit
a974dfd859
@ -37,11 +37,6 @@ public class ColorPluginAppender extends ColorAppender {
|
||||
@Override
|
||||
public LogEvent onAppend(LogEvent logEvent) {
|
||||
String oldMessage = logEvent.getMessage().getFormattedMessage();
|
||||
if (logEvent.getLoggerName().isEmpty()) {
|
||||
// ignore non logging messages like command output
|
||||
return logEvent;
|
||||
}
|
||||
|
||||
String prefix = '[' + logEvent.getLoggerName() + "] ";
|
||||
|
||||
//PaperSpigot append prefix
|
||||
|
@ -27,11 +27,6 @@ public class ColorPluginAppender extends ColorAppender {
|
||||
public LogEvent onAppend(LogEvent logEvent) {
|
||||
String message = logEvent.getMessage().getFormattedMessage();
|
||||
String loggerName = logEvent.getLoggerName();
|
||||
if (logEvent.getLoggerName().isEmpty()) {
|
||||
// ignore non logging messages like command output
|
||||
return logEvent;
|
||||
}
|
||||
|
||||
//old message + potential prefix and color codes
|
||||
StringBuilder msgBuilder = new StringBuilder(message.length() + loggerName.length() + 10);
|
||||
if (!PROXY_PREFIX.equals(loggerName)) {
|
||||
|
@ -10,6 +10,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import org.fusesource.jansi.Ansi.Attribute;
|
||||
@ -21,7 +22,10 @@ public class CommonFormatter {
|
||||
//copied from AnsiEscape in order to provide compatibility with older Minecraft versions
|
||||
private static final String CSI = "\u001b[";
|
||||
private static final char SUFFIX = 'm';
|
||||
private final String reset = Ansi.ansi().a(Ansi.Attribute.RESET).toString();
|
||||
|
||||
private static final Pattern TAG_PATTERN = Pattern.compile("^\\[.+\\].*$");
|
||||
|
||||
private final String reset = Ansi.ansi().a(Attribute.RESET).toString();
|
||||
|
||||
private final Set<String> ignoreMessages;
|
||||
private final boolean truncateColor;
|
||||
@ -63,6 +67,9 @@ public class CommonFormatter {
|
||||
|
||||
public String colorizePluginTag(String message) {
|
||||
String newMessage = message;
|
||||
if (!TAG_PATTERN.matcher(message).matches()) {
|
||||
return newMessage;
|
||||
}
|
||||
|
||||
String startingColorCode = "";
|
||||
if (message.startsWith(CSI)) {
|
||||
|
@ -39,6 +39,33 @@ public class CommonFormatterTest {
|
||||
assertThat(formatter.colorizePluginTag("[TestPlugin] msg"), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColorizePluginTagNotPresentRight() {
|
||||
loadPluginColors();
|
||||
|
||||
// unmodified
|
||||
String msg = "[TestPlugin msg";
|
||||
assertThat(formatter.colorizePluginTag(msg), is(msg));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColorizePluginTagNotPresentLeft() {
|
||||
loadPluginColors();
|
||||
|
||||
// unmodified
|
||||
String msg = "TestPlugin] msg";
|
||||
assertThat(formatter.colorizePluginTag(msg), is(msg));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColorizePluginTagWrongOrder() {
|
||||
loadPluginColors();
|
||||
|
||||
// unmodified
|
||||
String msg = "]TestPlugin[ msg";
|
||||
assertThat(formatter.colorizePluginTag(msg), is(msg));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColorizeNameDefault() {
|
||||
loadPluginColors();
|
||||
|
Loading…
Reference in New Issue
Block a user