diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java index 8f0c69dd6..26f9d1c9d 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java @@ -9,8 +9,10 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CoderResult; import java.util.*; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; @@ -249,6 +251,31 @@ public class EssentialsConf extends YamlConfiguration @Override public synchronized void save(final File file) throws IOException + { + delayedSave(file); + } + + public synchronized void forceSave() + { + try + { + Future future = delayedSave(configFile); + if (future != null) + { + future.get(); + } + } + catch (InterruptedException ex) + { + LOGGER.log(Level.SEVERE, ex.getMessage(), ex); + } + catch (ExecutionException ex) + { + LOGGER.log(Level.SEVERE, ex.getMessage(), ex); + } + } + + private Future delayedSave(final File file) { //long startTime = System.nanoTime(); if (file == null) @@ -260,14 +287,16 @@ public class EssentialsConf extends YamlConfiguration if (data.length() == 0) { - return; + return null; } pendingDiskWrites.incrementAndGet(); - EXECUTOR_SERVICE.submit(new WriteRunner(configFile, data, pendingDiskWrites)); + Future future = EXECUTOR_SERVICE.submit(new WriteRunner(configFile, data, pendingDiskWrites)); //LOGGER.log(Level.INFO, configFile + " prepared for writing in " + (System.nanoTime() - startTime) + " nsec."); + + return future; } diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java index 384e15603..60b23a8c8 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -230,7 +230,7 @@ public class EssentialsUpgrade config.removeProperty("home"); config.setProperty("home.default", worldName); config.setProperty("home.worlds." + worldName, loc); - config.save(); + config.forceSave(); } } } @@ -285,7 +285,7 @@ public class EssentialsUpgrade ((Map)powertools).put(entry.getKey(), temp); } } - config.save(); + config.forceSave(); } } catch (RuntimeException ex) @@ -358,7 +358,7 @@ public class EssentialsUpgrade } } config.removeProperty("home"); - config.save(); + config.forceSave(); } } diff --git a/Essentials/src/com/earth2me/essentials/api/Economy.java b/Essentials/src/com/earth2me/essentials/api/Economy.java index 579afd4d1..c22145a13 100644 --- a/Essentials/src/com/earth2me/essentials/api/Economy.java +++ b/Essentials/src/com/earth2me/essentials/api/Economy.java @@ -42,7 +42,7 @@ public final class Economy npcConfig.load(); npcConfig.setProperty("npc", true); npcConfig.setProperty("money", ess.getSettings().getStartingBalance()); - npcConfig.save(); + npcConfig.forceSave(); } private static void deleteNPC(String name)