From 5a1c809d89b99dbff951ed86570225b2ab37a5fb Mon Sep 17 00:00:00 2001 From: Ruakij Date: Tue, 11 May 2021 11:42:05 +0200 Subject: [PATCH] Changed save-system --- .../ruekov/ruakij/LinkedBeaconTeleporters/Main.java | 13 +++++++++++-- .../LinkedBeaconTeleporterManager.java | 11 ++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java index e1f9ecf..a5b4e2e 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java @@ -47,7 +47,8 @@ public class Main extends JavaPlugin { public void onDisable() { - LinkedBeaconTeleporterManager.saveData(); + LinkedBeaconTeleporterManager.writeData(); + saveData(); log.info("Plugin deactivated"); } @@ -71,7 +72,15 @@ public class Main extends JavaPlugin { } } - public static void saveData() { + public static void saveData(){ + boolean lbtDataChanged = LinkedBeaconTeleporterManager.writeData(); + + // Only run save, when data changed + if(lbtDataChanged) + saveData(); + } + + public static void saveFiles() { // data.yml try{ File dataFile = new File("plugins/"+ plugin.getName() +"/data.yml"); 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 124baaf..4c6256e 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java @@ -78,12 +78,12 @@ public class LinkedBeaconTeleporterManager { placedLBTsById.put(teleporterId, linkedBeaconTeleporters); } + Main.saveData(); + Main.log.info("All done!"); } - public static void saveData(){ - Main.log.info("Saving data.."); - + public static boolean saveData(){ Main.data = new YamlConfiguration(); for(String teleporterId : placedLBTsById.keySet()){ List LBTs = placedLBTsById.get(teleporterId); @@ -100,10 +100,7 @@ public class LinkedBeaconTeleporterManager { Main.data.set(teleporterId, dataList); } - - Main.saveData(); - - Main.log.info("done"); + return true; } static void constructAndAddRecipes(){