Initial commit

This commit is contained in:
Govindas
2021-06-12 14:43:58 +03:00
parent 6f22ce03d7
commit 05107f72e4
7 changed files with 206 additions and 23 deletions

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: net.limework.automaticlogdeleter.AutomaticLogDeleter

View File

@@ -0,0 +1,53 @@
package net.limework.automaticlogdeleter;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.logging.Level;
public final class AutomaticLogDeleter extends JavaPlugin {
@Override
public void onEnable() {
new Thread(() -> {
this.saveDefaultConfig();
deleteLogs();
}).start();
}
@Override
public void onDisable() {
new Thread(() -> {
FileConfiguration config = getConfig();
if (config.getBoolean("also-delete-logs-on-shutdown")) {
deleteLogs();
}
}).start();
}
public void deleteLogs() {
File path = new File("logs");
File[] files = path.listFiles();
if (files == null) { return; }
FileConfiguration config = getConfig();
//maximum file age allowed
long maxOldMillis = config.getLong("delete-logs-older-than-seconds") * 1000;
for (File file : files) {
if (file.isFile()) {
if ((System.currentTimeMillis() - file.lastModified()) > maxOldMillis) {
if (!file.delete()) {
Bukkit.getLogger().log(Level.WARNING, "Failed to delete server log file! Are you sure the file permissions are correct?");
}
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
#AutomaticLogDeleter plugin config
#lines that start with a hashtag are comments
#delete logs older than 24 hours by default
#default value: 86400
delete-logs-older-than-seconds: 86400
#by default old logs are deleted only on startup
#default value: false
also-delete-logs-on-shutdown: false

View File

@@ -0,0 +1,8 @@
name: AutomaticLogDeleter
version: ${project.version}
main: net.limework.automaticlogdeleter.AutomaticLogDeleter
api-version: 1.13
load: STARTUP
authors: [ Govindas ]
description: Delete your old server logs on startup
website: limework.net