From 3d3f861866c2196bdb83bdfbd73e58aa56be2966 Mon Sep 17 00:00:00 2001 From: Cow Date: Mon, 22 Jun 2020 03:47:04 +0200 Subject: Improved mc log file search - added help button - added search option: chatbox only - enhanced log entry details (including time and log file) - double click to open corresponding log file - fix: search results are now properly sorted by date --- .../java/eu/olli/cowmoonication/data/LogEntry.java | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/main/java/eu/olli/cowmoonication/data/LogEntry.java (limited to 'src/main/java/eu/olli/cowmoonication/data') diff --git a/src/main/java/eu/olli/cowmoonication/data/LogEntry.java b/src/main/java/eu/olli/cowmoonication/data/LogEntry.java new file mode 100644 index 0000000..e258105 --- /dev/null +++ b/src/main/java/eu/olli/cowmoonication/data/LogEntry.java @@ -0,0 +1,82 @@ +package eu.olli.cowmoonication.data; + +import net.minecraft.util.EnumChatFormatting; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + +import java.nio.file.Path; +import java.time.LocalDateTime; +import java.util.regex.Pattern; + +public class LogEntry { + private static final Pattern UTF_PARAGRAPH_SYMBOL = Pattern.compile("§"); + private LocalDateTime time; + private Path filePath; + private String message; + + public LogEntry(LocalDateTime time, Path filePath, String logEntry) { + this.time = time; + this.filePath = filePath; + this.message = logEntry; + } + + public LogEntry(String message) { + this.message = message; + } + + public LocalDateTime getTime() { + return time; + } + + public Path getFilePath() { + return filePath; + } + + public String getMessage() { + return message; + } + + public void addLogLine(String logLine) { + message += "\n" + logLine; + } + + public void removeFormatting() { + this.message = EnumChatFormatting.getTextWithoutFormattingCodes(message); + } + + public void fixWeirdCharacters() { + if (message.contains("§")) { + message = UTF_PARAGRAPH_SYMBOL.matcher(message).replaceAll("§"); + } + } + + /** + * Is this log entry a 'real' log entry or just an error message from the search process? + * + * @return true if error message, otherwise false + */ + public boolean isError() { + return time == null && filePath == null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LogEntry logEntry = (LogEntry) o; + return new EqualsBuilder() + .append(time, logEntry.time) + .append(filePath, logEntry.filePath) + .append(message, logEntry.message) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(time) + .append(filePath) + .append(message) + .toHashCode(); + } +} -- cgit