diff --git a/buildnumber.properties b/buildnumber.properties index c025ec48..2e33052c 100644 --- a/buildnumber.properties +++ b/buildnumber.properties @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Sun May 11 18:05:04 CEST 2014 -build.number=826 +#Sun May 11 18:41:12 CEST 2014 +build.number=830 diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java index 81834761..4bdd3f22 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java @@ -11,6 +11,7 @@ import java.text.SimpleDateFormat; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import me.StevenLawson.TotalFreedomMod.Config.TFM_Config; import net.minecraft.util.org.apache.commons.io.FileUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils; @@ -687,8 +688,8 @@ public class TFM_Util try { - FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE)); - ObjectOutputStream oos = new ObjectOutputStream(fos); + final FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE)); + final ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(flags); oos.close(); fos.close(); @@ -699,10 +700,54 @@ public class TFM_Util } } - public static void createBackup(String file) + public static void createBackups(String file) { + final String save = file.split("\\.")[0]; + final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, "backup.yml", false); + config.load(); + + // Daily + if (!config.isInt(save + ".daily")) + { + performBackup(file, "daily"); + config.set(save + ".daily", TFM_Util.getUnixTime()); + } + else + { + int lastBackupDaily = config.getInt(save + ".daily"); + + if (lastBackupDaily + 3600 * 24 < TFM_Util.getUnixTime()) + { + performBackup(file, "daily"); + config.set(save + ".daily", TFM_Util.getUnixTime()); + } + } + + // Weekly + if (!config.isInt(save + ".weekly")) + { + performBackup(file, "weekly"); + config.set(save + ".weekly", TFM_Util.getUnixTime()); + } + else + { + int lastBackupWeekly = config.getInt(save + ".weekly"); + + if (lastBackupWeekly + 3600 * 24 * 7 < TFM_Util.getUnixTime()) + { + performBackup(file, "weekly"); + config.set(save + ".weekly", TFM_Util.getUnixTime()); + } + } + + config.save(); + } + + private static void performBackup(String file, String type) + { + TFM_Log.info("Backing up " + file + " to " + file + "." + type + ".bak"); final File oldYaml = new File(TotalFreedomMod.plugin.getDataFolder(), file); - final File newYaml = new File(TotalFreedomMod.plugin.getDataFolder(), file + ".bak"); + final File newYaml = new File(TotalFreedomMod.plugin.getDataFolder(), file + "." + type + ".bak"); FileUtil.copy(oldYaml, newYaml); } @@ -853,6 +898,8 @@ public class TFM_Util Field field = checkClass.getDeclaredField(name); field.setAccessible(true); return (T) field.get(from); + + } catch (NoSuchFieldException ex) { @@ -861,7 +908,9 @@ public class TFM_Util { } } - while (checkClass.getSuperclass() != Object.class && ((checkClass = checkClass.getSuperclass()) != null)); + while (checkClass.getSuperclass() != Object.class + && ((checkClass = checkClass.getSuperclass()) != null)); + return null; } @@ -899,6 +948,8 @@ public class TFM_Util { String packageName = Bukkit.getServer().getClass().getPackage().getName(); return packageName.substring(packageName.lastIndexOf('.') + 1); + + } public static class TFM_EntityWiper diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java index cb6aa281..f8e7e26f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java @@ -90,11 +90,11 @@ public class TotalFreedomMod extends JavaPlugin } // Admin list - TFM_Util.createBackup(SUPERADMIN_FILE); + TFM_Util.createBackups(SUPERADMIN_FILE); TFM_AdminList.load(); // Permban list - TFM_Util.createBackup(PERMBAN_FILE); + TFM_Util.createBackups(PERMBAN_FILE); TFM_PermbanList.load(); // Playerlist and bans