From b20e0a03fd89f2f3e09e58aad7b0ad0248bde188 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Tue, 11 May 2021 11:42:46 +0200 Subject: [PATCH] Added Autosave --- .../ruekov/ruakij/LinkedBeaconTeleporters/Main.java | 10 ++++++++++ .../LinkedBeaconTeleporterManager.java | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java index a5b4e2e..ee048f8 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java @@ -42,6 +42,8 @@ public class Main extends JavaPlugin { LinkedBeaconTeleporterManager.init(); + initAutoSave(); + log.info("Plugin activated"); } @@ -90,4 +92,12 @@ public class Main extends JavaPlugin { ex.printStackTrace(); } } + + static int autosaveInterval = 600 * 20; + static void initAutoSave(){ + Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> { + saveData(); + + }, autosaveInterval, autosaveInterval); + } } diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java index 4c6256e..d82d71f 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java @@ -83,7 +83,17 @@ public class LinkedBeaconTeleporterManager { Main.log.info("All done!"); } - public static boolean saveData(){ + static int oldDataHashCode; + public static boolean writeData(){ + // Check if data changed + int dataHashCode = placedLBTsById.hashCode(); + if(oldDataHashCode != dataHashCode){ + // Changed + oldDataHashCode = dataHashCode; + } + else // Did not change + return false; + Main.data = new YamlConfiguration(); for(String teleporterId : placedLBTsById.keySet()){ List LBTs = placedLBTsById.get(teleporterId);