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);