This commit is contained in:
iTakinn
2025-03-16 19:40:37 -03:00
parent 10fa12e809
commit 4de0018c7d
@@ -27,16 +27,15 @@ public class LoggerReader {
public void start() { public void start() {
try { try {
// Configura o WatchService para monitorar modificações no diretório
watchService = FileSystems.getDefault().newWatchService(); watchService = FileSystems.getDefault().newWatchService();
logDir.register(watchService, ENTRY_MODIFY); logDir.register(watchService, ENTRY_MODIFY);
// Inicia a thread de monitoramento assíncrona
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
while (!Thread.currentThread().isInterrupted()) { while (!Thread.currentThread().isInterrupted()) {
WatchKey key; WatchKey key;
try { try {
key = watchService.take(); // Aguarda eventos key = watchService.take();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
return; return;
@@ -61,9 +60,9 @@ public class LoggerReader {
private void processLogChanges(File logFile) { private void processLogChanges(File logFile) {
try (RandomAccessFile raf = new RandomAccessFile(logFile, "r")) { try (RandomAccessFile raf = new RandomAccessFile(logFile, "r")) {
// Pula para a última posição lida
if (raf.length() < lastReadPosition) { if (raf.length() < lastReadPosition) {
lastReadPosition = 0; // Log foi reiniciado (ex: servidor reiniciou) lastReadPosition = 0;
} }
raf.seek(lastReadPosition); raf.seek(lastReadPosition);