Skip to content

Commit

Permalink
added an option to also include lines other than chat (errors for exa…
Browse files Browse the repository at this point in the history
…mple)
  • Loading branch information
doej1367 committed Aug 21, 2022
1 parent a79b1ae commit e5c909e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
20 changes: 16 additions & 4 deletions src/main/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import util.MCLogFile;
import util.MCLogLine;
import util.OSFileSystem;
import java.awt.Checkbox;

/**
*
Expand All @@ -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;
Expand All @@ -61,6 +63,7 @@ public class MainWindow extends JFrame {

private int tmpStauslength = 0;
private JPanel panel_south;
private Component horizontalGlue_3;

/**
* Create the frame.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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<File> minecraftLogFolders = fileSystem.lookForMinecraftLogFolders();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -275,7 +287,7 @@ private void startAnalysis() {
Thread t0 = new Thread() {
@Override
public void run() {
mainWindow.analyze();
mainWindow.analyze(onlyChatCheckBox.getState());
}
};
t0.start();
Expand Down
4 changes: 2 additions & 2 deletions src/util/MCLogFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class MCLogFile {
private String playerName;
private Stream<String> 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);
Expand All @@ -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;
}
Expand Down

0 comments on commit e5c909e

Please sign in to comment.