Skip to content

Commit

Permalink
Async saving
Browse files Browse the repository at this point in the history
  • Loading branch information
galacticwarrior9 committed Jul 30, 2021
1 parent 18949d7 commit f6c6283
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 46 deletions.
24 changes: 14 additions & 10 deletions src/com/dogonfire/gods/managers/BelieverManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dogonfire.gods.managers;

import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand All @@ -17,6 +18,7 @@
import com.dogonfire.gods.Gods;
import com.dogonfire.gods.config.GodsConfiguration;
import com.dogonfire.gods.managers.LanguageManager.LANGUAGESTRING;
import org.bukkit.scheduler.BukkitRunnable;

public class BelieverManager
{
Expand Down Expand Up @@ -659,18 +661,20 @@ public void removePrayer(UUID believerId)
public void save()
{
this.lastSaveTime = System.currentTimeMillis();
if ((this.believersConfig == null) || (this.believersConfigFile == null))
{
if ((this.believersConfig == null) || (this.believersConfigFile == null)) {
return;
}
try
{
this.believersConfig.save(this.believersConfigFile);
}
catch (Exception ex)
{
Gods.instance().log("Could not save config to " + this.believersConfigFile.getName() + ": " + ex.getMessage());
}
new BukkitRunnable() {
@Override
public void run() {
try {
believersConfig.save(believersConfigFile);
}
catch (IOException ex) {
Gods.instance().log("Could not save config to " + believersConfigFile.getName() + ": " + ex.getMessage());
}
}
}.runTaskAsynchronously(Gods.instance());
}

public void saveTimed()
Expand Down
24 changes: 14 additions & 10 deletions src/com/dogonfire/gods/managers/HolyBookManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dogonfire.gods.managers;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -13,6 +14,7 @@
import com.dogonfire.gods.Gods;
import com.dogonfire.gods.HolyBook;
import com.dogonfire.gods.config.GodsConfiguration;
import org.bukkit.scheduler.BukkitRunnable;

public class HolyBookManager
{
Expand Down Expand Up @@ -236,18 +238,20 @@ public void load()

public void save()
{
if ((this.biblesConfig == null) || (this.biblesConfigFile == null))
{
if ((this.biblesConfig == null) || (this.biblesConfigFile == null)) {
return;
}
try
{
this.biblesConfig.save(this.biblesConfigFile);
}
catch (Exception ex)
{
Gods.instance().log("Could not save config to " + this.biblesConfigFile.getName() + ": " + ex.getMessage());
}
new BukkitRunnable() {
@Override
public void run() {
try {
biblesConfig.save(biblesConfigFile);
}
catch (IOException ex) {
Gods.instance().log("Could not save config to " + biblesConfigFile.getName() + ": " + ex.getMessage());
}
}
}.runTaskAsynchronously(Gods.instance());
}

public boolean setBible(String godName, String priestName)
Expand Down
23 changes: 13 additions & 10 deletions src/com/dogonfire/gods/managers/QuestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;

import com.dogonfire.gods.Gods;
Expand Down Expand Up @@ -2655,18 +2656,20 @@ public void resetItemRewardValues()

public void save()
{
if ((this.questsConfig == null) || (this.questsConfigFile == null))
{
if ((this.questsConfig == null) || (this.questsConfigFile == null)) {
return;
}
try
{
this.questsConfig.save(this.questsConfigFile);
}
catch (Exception ex)
{
Gods.instance().log("Could not save config to " + this.questsConfigFile.getName() + ": " + ex.getMessage());
}
new BukkitRunnable() {
@Override
public void run() {
try {
questsConfig.save(questsConfigFile);
}
catch (Exception ex) {
Gods.instance().log("Could not save config to " + questsConfigFile.getName() + ": " + ex.getMessage());
}
}
}.runTaskAsynchronously(Gods.instance());
}

/*
Expand Down
35 changes: 19 additions & 16 deletions src/com/dogonfire/gods/managers/WhitelistManager.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.dogonfire.gods.managers;

import java.io.File;
import java.io.IOException;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import com.dogonfire.gods.Gods;
import com.dogonfire.gods.config.GodsConfiguration;
import org.bukkit.scheduler.BukkitRunnable;

public class WhitelistManager
{
Expand Down Expand Up @@ -98,21 +100,22 @@ public void load()

public void save()
{
try
{
this.whiteList.save(this.whiteListFile);
}
catch (Exception ex)
{
Gods.instance().log("Could not save whitelist to " + this.whiteListFile + ": " + ex.getMessage());
}
try
{
this.blackList.save(this.blackListFile);
}
catch (Exception ex)
{
Gods.instance().log("Could not save blacklist to " + this.blackListFile + ": " + ex.getMessage());
}
new BukkitRunnable() {
@Override
public void run() {
try {
whiteList.save(whiteListFile);
}
catch (IOException ex) {
Gods.instance().log("Could not save whitelist to " + whiteListFile + ": " + ex.getMessage());
}
try {
blackList.save(blackListFile);
}
catch (IOException ex) {
Gods.instance().log("Could not save blacklist to " + blackListFile + ": " + ex.getMessage());
}
}
}.runTaskAsynchronously(Gods.instance());
}
}

0 comments on commit f6c6283

Please sign in to comment.