Initial commit
This commit is contained in:
3
src/main/java/META-INF/MANIFEST.MF
Normal file
3
src/main/java/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: net.limework.automaticlogdeleter.AutomaticLogDeleter
|
||||
|
||||
@@ -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?");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/main/resources/config.yml
Normal file
12
src/main/resources/config.yml
Normal 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
|
||||
8
src/main/resources/plugin.yml
Normal file
8
src/main/resources/plugin.yml
Normal 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
|
||||
Reference in New Issue
Block a user