Added Autosave
This commit is contained in:
parent
5a1c809d89
commit
b20e0a03fd
@ -42,6 +42,8 @@ public class Main extends JavaPlugin {
|
|||||||
|
|
||||||
LinkedBeaconTeleporterManager.init();
|
LinkedBeaconTeleporterManager.init();
|
||||||
|
|
||||||
|
initAutoSave();
|
||||||
|
|
||||||
log.info("Plugin activated");
|
log.info("Plugin activated");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,4 +92,12 @@ public class Main extends JavaPlugin {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int autosaveInterval = 600 * 20;
|
||||||
|
static void initAutoSave(){
|
||||||
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||||
|
saveData();
|
||||||
|
|
||||||
|
}, autosaveInterval, autosaveInterval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,17 @@ public class LinkedBeaconTeleporterManager {
|
|||||||
Main.log.info("All done!");
|
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();
|
Main.data = new YamlConfiguration();
|
||||||
for(String teleporterId : placedLBTsById.keySet()){
|
for(String teleporterId : placedLBTsById.keySet()){
|
||||||
List<LinkedBeaconTeleporter> LBTs = placedLBTsById.get(teleporterId);
|
List<LinkedBeaconTeleporter> LBTs = placedLBTsById.get(teleporterId);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user