Only delete log files and nothing else

This commit is contained in:
Govindas 2021-06-13 12:12:06 +03:00
parent 4a37ac3691
commit 59d45b6ede
1 changed files with 16 additions and 6 deletions

View File

@ -38,10 +38,21 @@ public class AutomaticLogDeleter extends JavaPlugin {
//maximum file age allowed
long maxOldMillis = config.getLong("delete-logs-older-than-seconds") * 1000;
String fileName;
for (File file : files) {
if (file.isFile()) {
fileName = file.getName();
//if file is not a log file
if (!fileName.endsWith(".log") && !fileName.endsWith(".log.gz")) {
continue;
}
//if file is older than configured time
if ((System.currentTimeMillis() - file.lastModified()) > maxOldMillis) {
continue;
}
if (!file.delete()) {
Bukkit.getLogger().log(Level.WARNING, "[AutomaticLogDeleter] Failed to delete server log file! Are you sure the file permissions are correct?");
@ -51,5 +62,4 @@ public class AutomaticLogDeleter extends JavaPlugin {
}
}
}
}
}