mirror of
https://github.com/taoneill/war.git
synced 2025-02-15 02:41:33 +01:00
Startup warning when War files take over 100MB
Temp files tend to accumulate rapidly if some zonemakers are particularly trigger happy with /savezone. Added a warning. Should probably add a real limit on number of oldversions that can be saved.
This commit is contained in:
parent
7a90119c97
commit
4835d0f37d
@ -52,6 +52,7 @@ import com.tommytony.war.structure.HubLobbyMaterials;
|
|||||||
import com.tommytony.war.structure.ZoneLobby;
|
import com.tommytony.war.structure.ZoneLobby;
|
||||||
import com.tommytony.war.utility.ChatFixUtil;
|
import com.tommytony.war.utility.ChatFixUtil;
|
||||||
import com.tommytony.war.utility.PlayerState;
|
import com.tommytony.war.utility.PlayerState;
|
||||||
|
import com.tommytony.war.utility.SizeCounter;
|
||||||
import com.tommytony.war.utility.WarLogFormatter;
|
import com.tommytony.war.utility.WarLogFormatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -265,6 +266,14 @@ public class War extends JavaPlugin {
|
|||||||
this.getLogger().log(Level.WARNING, "Failed to create War log file");
|
this.getLogger().log(Level.WARNING, "Failed to create War log file");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size check
|
||||||
|
long datSize = SizeCounter.getFileOrDirectorySize(new File(this.getDataFolder() + "/dat/")) / 1024 / 1024;
|
||||||
|
long tempSize = SizeCounter.getFileOrDirectorySize(new File(this.getDataFolder() + "/temp/")) / 1024 / 1024;
|
||||||
|
|
||||||
|
if (datSize + tempSize > 100) {
|
||||||
|
this.log("War data files are taking " + datSize + "MB and its temp files " + tempSize + "MB. Consider permanently deleting old warzone versions and backups in /plugins/War/temp/.", Level.WARNING);
|
||||||
|
}
|
||||||
|
|
||||||
this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO);
|
this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
33
war/src/main/java/com/tommytony/war/utility/SizeCounter.java
Normal file
33
war/src/main/java/com/tommytony/war/utility/SizeCounter.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package com.tommytony.war.utility;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileFilter;
|
||||||
|
|
||||||
|
// Credit: http://sanjaal.com/java/48/java-utilities/calculating-folder-size/
|
||||||
|
public class SizeCounter implements FileFilter
|
||||||
|
{
|
||||||
|
private long total = 0;
|
||||||
|
|
||||||
|
public SizeCounter(){};
|
||||||
|
|
||||||
|
public boolean accept(File pathname) {
|
||||||
|
if (pathname.isFile()) {
|
||||||
|
total += pathname.length();
|
||||||
|
} else {
|
||||||
|
pathname.listFiles(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTotal()
|
||||||
|
{
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getFileOrDirectorySize(File file) {
|
||||||
|
SizeCounter counter = new SizeCounter();
|
||||||
|
file.listFiles(counter);
|
||||||
|
return counter.getTotal();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user