Cleanup task
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.drtshock</groupId>
|
||||
<artifactId>PlayerVaults</artifactId>
|
||||
<version>3.4.4</version>
|
||||
<version>3.4.5-SNAPSHOT</version>
|
||||
<name>PlayerVaults</name>
|
||||
<url>http://dev.bukkit.org/server-mods/playervaults/</url>
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.drtshock.playervaults;
|
||||
import com.drtshock.playervaults.commands.Commands;
|
||||
import com.drtshock.playervaults.commands.SignSetInfo;
|
||||
import com.drtshock.playervaults.listeners.Listeners;
|
||||
import com.drtshock.playervaults.tasks.Cleanup;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.util.Metrics;
|
||||
import com.drtshock.playervaults.util.Updater;
|
||||
@@ -92,6 +93,10 @@ public class PlayerVaults extends JavaPlugin {
|
||||
|
||||
new File(DIRECTORY + File.separator + "backups").mkdirs();
|
||||
VM = new VaultManager(this);
|
||||
|
||||
if(getConfig().getBoolean("cleanup.enable", false)) {
|
||||
getServer().getScheduler().runTaskAsynchronously(this, new Cleanup(getConfig().getInt("cleanup.lastEdit", 30)));
|
||||
}
|
||||
}
|
||||
|
||||
private void startMetrics() {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.drtshock.playervaults.tasks;
|
||||
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Cleanup extends BukkitRunnable {
|
||||
|
||||
private long diff;
|
||||
|
||||
public Cleanup(int diff) {
|
||||
this.diff = diff * 86400;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
File file = new File(PlayerVaults.DIRECTORY);
|
||||
if(!file.exists()) return;
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
for(File f : file.listFiles()) {
|
||||
if(time - f.lastModified() > diff) {
|
||||
f.delete();
|
||||
PlayerVaults.PLUGIN.getLogger().info("Deleting vault file: " + f.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,6 +204,9 @@ public class VaultManager {
|
||||
public void deleteVault(CommandSender sender, String holder, int number) throws IOException {
|
||||
String name = holder.toLowerCase();
|
||||
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
||||
if(!file.exists()) {
|
||||
return;
|
||||
}
|
||||
FileConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||
if (file.exists()) {
|
||||
playerFile.set("vault" + number, null);
|
||||
|
||||
@@ -17,3 +17,14 @@ economy:
|
||||
cost-to-create: 100
|
||||
cost-to-open: 10
|
||||
refund-on-delete: 50
|
||||
|
||||
# Cleanup
|
||||
# Should we cleanup vaults that haven't been used in awhile?
|
||||
# Only checks on restarts. Runs on another thread so it won't
|
||||
# lag the server.
|
||||
cleanup:
|
||||
enable: false
|
||||
|
||||
# If a file hasn't been edited for this long, we'll clean it up.
|
||||
# Time is in days.
|
||||
lastEdit: 30
|
||||
Reference in New Issue
Block a user