Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import java.util.stream.Collectors;

@PluginDescriptor(
version = "1.0.4",
version = "1.0.5",
name = PluginDescriptor.eXioStorm + "Player Monitor",
enabledByDefault = false,
minClientVersion = "2.0.0",
Expand Down Expand Up @@ -215,7 +215,11 @@ protected void shutDown() throws Exception {
if (this.flashOverlay != null) {
overlayManager.remove(flashOverlay);
}
saveMouseClicks();
try {
saveMouseClicks();
} catch (IOException e) {
log.warn("Failed to save mouse clicks", e);
}
this.mouseManager.unregisterMouseListener((net.runelite.client.input.MouseListener)this.mouseListener);
this.mouseListener = null;
if (this.overlayOn) {
Expand Down Expand Up @@ -275,17 +279,16 @@ public static void resetMouseClickCounterListener() {
}
}
public static void saveMouseClicks() throws IOException {
if (!CLICK_TOTAL_FILE.exists())
try {
if (!CLICK_TOTAL_FILE.createNewFile())
System.out.println("Failed to create log file");
} catch (IOException e) {
e.printStackTrace();
}
FileWriter writer = new FileWriter(CLICK_TOTAL_FILE);
Integer[] totals = { Integer.valueOf(getLeftClickCounter()) };
writer.write("" + totals[FILE_CLICK_TYPE_INDICES.LEFT.getValue()] + " ");
writer.close();
writeClickCount(CLICK_TOTAL_FILE, getLeftClickCounter());
}
static void writeClickCount(File file, int leftClicks) throws IOException {
File dir = file.getParentFile();
if (dir != null && !dir.isDirectory() && !dir.mkdirs() && !dir.isDirectory())
throw new IOException("Failed to create directory " + dir);
Integer[] totals = { Integer.valueOf(leftClicks) };
try (FileWriter writer = new FileWriter(file)) {
writer.write("" + totals[FILE_CLICK_TYPE_INDICES.LEFT.getValue()] + " ");
}
}
public void loadMouseClicks() throws FileNotFoundException {
if (!this.CLICK_TOTAL_DIR.mkdir() && CLICK_TOTAL_FILE.exists()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.runelite.client.plugins.microbot.playermonitor;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class PlayerMonitorPluginTest {

@TempDir
Path tempDir;

@Test
void writeClickCountCreatesMissingDirectory() throws IOException {
File file = tempDir.resolve("PlayerMonitor").resolve("click_count.log").toFile();

PlayerMonitorPlugin.writeClickCount(file, 42);

assertTrue(file.isFile());
assertEquals("42 ", new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8));
}

@Test
void writeClickCountOverwritesExistingFile() throws IOException {
File file = tempDir.resolve("click_count.log").toFile();
Files.write(file.toPath(), "999 ".getBytes(StandardCharsets.UTF_8));

PlayerMonitorPlugin.writeClickCount(file, 7);

assertEquals("7 ", new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8));
}
}
Loading