From e5c909e9675c4040d60945bd3968dec4ee405709 Mon Sep 17 00:00:00 2001 From: John Doe Date: Sun, 21 Aug 2022 16:14:49 +0200 Subject: [PATCH] added an option to also include lines other than chat (errors for example) --- src/main/MainWindow.java | 20 ++++++++++++++++---- src/util/MCLogFile.java | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/MainWindow.java b/src/main/MainWindow.java index 607a009..f0d90d4 100644 --- a/src/main/MainWindow.java +++ b/src/main/MainWindow.java @@ -34,6 +34,7 @@ import util.MCLogFile; import util.MCLogLine; import util.OSFileSystem; +import java.awt.Checkbox; /** * @@ -49,6 +50,7 @@ public class MainWindow extends JFrame { private JTextArea outputTextField; private JScrollPane scrollPaneBottom; private JTextArea statusTextField; + private Checkbox onlyChatCheckBox; private Button defaultButton; private Button addFoldersButton; private JPanel panel_north; @@ -61,6 +63,7 @@ public class MainWindow extends JFrame { private int tmpStauslength = 0; private JPanel panel_south; + private Component horizontalGlue_3; /** * Create the frame. @@ -97,6 +100,14 @@ public void actionPerformed(ActionEvent arg0) { panel_north.add(defaultButton); defaultButton.setForeground(Color.BLUE); defaultButton.setFont(new Font("Consolas", Font.PLAIN, 14)); + + horizontalGlue_3 = Box.createHorizontalGlue(); + panel_north.add(horizontalGlue_3); + + onlyChatCheckBox = new Checkbox("Only filter chat lines"); + onlyChatCheckBox.setState(true); + onlyChatCheckBox.setFont(new Font("Consolas", Font.PLAIN, 14)); + panel_north.add(onlyChatCheckBox); horizontalGlue_2 = Box.createHorizontalGlue(); panel_north.add(horizontalGlue_2); @@ -138,7 +149,8 @@ public void run() { inputTextField.setWrapStyleWord(true); inputTextField.setRows(4); inputTextField.setFont(new Font("Consolas", Font.PLAIN, 14)); - inputTextField.setText("(You bought Kismet Feather!.*)|(You purchased .*Kismet Feather .*)|(The Catacombs - Floor VII)->(Team Score: [0-9]+ \\(S\\+\\).*)"); + inputTextField.setText( + "(You bought Kismet Feather!.*)|(You purchased .*Kismet Feather .*)|(The Catacombs - Floor VII)->(Team Score: [0-9]+ \\(S\\+\\).*)"); inputTextField.setEditable(true); scrollPaneTop.setViewportView(inputTextField); @@ -162,7 +174,7 @@ public void run() { scrollPaneBottom.setViewportView(statusTextField); } - private synchronized void analyze() { + private synchronized void analyze(boolean onlyChat) { try { OSFileSystem fileSystem = new OSFileSystem(mainWindow); ArrayList minecraftLogFolders = fileSystem.lookForMinecraftLogFolders(); @@ -203,7 +215,7 @@ public int compare(File f1, File f2) { addStatusTemporaryly( "INFO: Loading " + fileCount + " files - " + (counter * 100 / fileCount) + "%"); try { - minecraftLogFile = new MCLogFile(logFile, getPreviousFileInFolder(counter, allFiles)); + minecraftLogFile = new MCLogFile(logFile, getPreviousFileInFolder(counter, allFiles), onlyChat); if (minecraftLogFile.getPlayerName() != null) { lastLoginName = minecraftLogFile.getPlayerName(); playerNames.put(lastLoginName, playerNames.getOrDefault(lastLoginName, 0) + 1); @@ -275,7 +287,7 @@ private void startAnalysis() { Thread t0 = new Thread() { @Override public void run() { - mainWindow.analyze(); + mainWindow.analyze(onlyChatCheckBox.getState()); } }; t0.start(); diff --git a/src/util/MCLogFile.java b/src/util/MCLogFile.java index 82039d1..edd848c 100644 --- a/src/util/MCLogFile.java +++ b/src/util/MCLogFile.java @@ -21,7 +21,7 @@ public class MCLogFile { private String playerName; private Stream linesStream; - public MCLogFile(File logFile, File previousLogFile) throws FileNotFoundException, IOException { + public MCLogFile(File logFile, File previousLogFile, boolean onlyChat) throws FileNotFoundException, IOException { creationTime = previousLogFile != null ? getCreationTime(previousLogFile) : getCreationTime(logFile) - 21600000; startingTimeOfFile = null; InputStream inputStream = new FileInputStream(logFile); @@ -33,7 +33,7 @@ public MCLogFile(File logFile, File previousLogFile) throws FileNotFoundExceptio linesStream = br.lines().filter(a -> { if (tmpPlayerName == null && a.matches(userSettingLine + ".*")) tmpPlayerName = a.replaceAll(userSettingLine, ""); - return a.contains("[CHAT]"); + return onlyChat ? a.contains("[CHAT]") : a.matches("\\[[0-9:]{8}\\] .*"); }); playerName = tmpPlayerName; }