From c4392eb697e507340454a8735e7b4d3bd297f5f1 Mon Sep 17 00:00:00 2001 From: Cow Date: Fri, 23 Apr 2021 14:43:24 +0200 Subject: Added Chest Tracker & Analyzer --- .../de/cowtipper/cowlection/search/GuiSearch.java | 1 - .../de/cowtipper/cowlection/search/LogEntry.java | 82 ++++++++++++++++++++++ .../cowlection/search/LogFilesSearcher.java | 1 - 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/cowtipper/cowlection/search/LogEntry.java (limited to 'src/main/java/de/cowtipper/cowlection/search') diff --git a/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java b/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java index ae17d32..21059ca 100644 --- a/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java +++ b/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java @@ -4,7 +4,6 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.mojang.realmsclient.util.Pair; import de.cowtipper.cowlection.Cowlection; import de.cowtipper.cowlection.config.MooConfig; -import de.cowtipper.cowlection.data.LogEntry; import de.cowtipper.cowlection.util.GuiHelper; import de.cowtipper.cowlection.util.Utils; import net.minecraft.client.Minecraft; diff --git a/src/main/java/de/cowtipper/cowlection/search/LogEntry.java b/src/main/java/de/cowtipper/cowlection/search/LogEntry.java new file mode 100644 index 0000000..cd86a78 --- /dev/null +++ b/src/main/java/de/cowtipper/cowlection/search/LogEntry.java @@ -0,0 +1,82 @@ +package de.cowtipper.cowlection.search; + +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(); + } +} diff --git a/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java b/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java index 0d292ae..a3ed781 100644 --- a/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java +++ b/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java @@ -2,7 +2,6 @@ package de.cowtipper.cowlection.search; import com.mojang.realmsclient.util.Pair; import de.cowtipper.cowlection.config.MooConfig; -import de.cowtipper.cowlection.data.LogEntry; import net.minecraft.util.EnumChatFormatting; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutableTriple; -- cgit