Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.bukkit.Bukkit;
- import org.bukkit.craftbukkit.v1_6_R3.CraftServer;
- import java.io.File;
- public class CrashDetection {
- private File crashReportDirectory = null;
- private int startSize;
- private boolean active;
- public CrashDetection() {
- CraftServer server = (CraftServer) Bukkit.getServer();
- if (server != null) {
- File worldFolder = server.getWorldContainer();
- if (worldFolder != null) {
- File serverFolder = worldFolder.getParentFile();
- if (serverFolder != null) {
- this.crashReportDirectory = new File(serverFolder, "crash-reports");
- if (!this.crashReportDirectory.exists()) {
- this.crashReportDirectory.mkdir();
- }
- this.active = true;
- }
- }
- }
- if (this.active) {
- this.startSize = getCrashReportsCount();
- }
- else {
- this.startSize = -1;
- }
- }
- public File getCrashReportDirectory() {
- return this.crashReportDirectory;
- }
- public int getCrashReportsCount() {
- String[] filePaths = this.crashReportDirectory.list();
- if (filePaths == null || filePaths.length == 0) {
- return 0;
- }
- int size = 0;
- for (int i = 0, len = filePaths.length; i < len; i++) {
- if (filePaths[i].endsWith("-server.txt")) {
- size++;
- }
- }
- return size;
- }
- public boolean hasDirectoryContentsChanged() {
- if (!this.active) {
- return false;
- }
- int sizeNow = getCrashReportsCount();
- if (sizeNow < this.startSize) {
- this.startSize = sizeNow;
- }
- return sizeNow != this.startSize;
- }
- public boolean hasCrashed() {
- return hasDirectoryContentsChanged();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement