Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.Kelsoncraft.KBP.testing;
- import java.io.File;
- import net.Kelsoncraft.KBP.KbpMain;
- public class ResworldTest {
- static KbpMain plugin;
- /** Values obtained from IDP, ServerRestartTimer testing. */
- // Resworld deletion settings
- private static final String RESOURCEWORLD_DATANAME = "resworld";
- private static final long RESOURCEWORLD_RESET_SECONDS = 3600 * 24;
- protected long delay = 2000;
- /**
- * This will mark the given file or directory to be deleted after shutdown.
- * If the given file is a directory, it will recursively go into the given folders.
- * @param curFile
- */
- private static void recursiveFileDeletionMarking(File curFile) {
- curFile.deleteOnExit();
- if (curFile.isDirectory()) {
- for (File f : curFile.listFiles()) {
- recursiveFileDeletionMarking(f);
- }
- }
- }
- public static void deleteFinal() {
- // No more restart time, so let's restart
- /*
- if (delayIdx == ALL_POSSIBLE_DELAYS.length) {
- Bukkit.broadcastMessage(ChatColor.LIGHT_PURPLE + "Server restarting now!");
- */
- if (shouldDeleteResourceWorld()) {
- deleteResourceWorld();
- }
- //plugin.getServer().shutdown();
- //delay = Integer.MAX_VALUE;
- }
- /**
- * This will check if resource world should be deleted this restart.
- * If DEBUGMODE is enabled, it will return false.
- * If the world hasn't been reset in over X time, it will return true.
- * @return
- */
- private static boolean shouldDeleteResourceWorld() {
- // Get last reset time from database.
- String value = plugin.getConfig().getString("resworld-last_reset"); //possibly work?
- // Hasn't ever been reset? Yes, its due!
- if (value == null) {
- return true;
- }
- try {
- Long lastReset = Long.parseLong(value);
- return (System.currentTimeMillis() > lastReset + RESOURCEWORLD_RESET_SECONDS * 1000);
- } catch (NumberFormatException ex) {
- //InnPlugin.logError("Unable to find get last resource zone reset! Resetting anyway!");
- return true;
- }
- }
- /**
- * This will mark the resource world to be deleted on plugin-shutdown.
- * This will then save the last time this world was deleted.
- */
- private static void deleteResourceWorld() {
- // Delete the resworld
- File resworld = new File(RESOURCEWORLD_DATANAME);
- recursiveFileDeletionMarking(resworld);
- //InnPlugin.logInfo("Deleted Resource World!");
- // Save that resource world was deleted.
- plugin.getConfig().set("resworld-last_reset", String.valueOf(System.currentTimeMillis()));; // Should this work?
- //ConfigValueHandler.saveValue(RESOURCEWORLD_DATANAME, String.valueOf(System.currentTimeMillis()));
- }
- }
Add Comment
Please, Sign In to add comment