make save task async

This commit is contained in:
Pyr 2023-04-19 16:52:01 +01:00
parent 7fe1ade54b
commit 3fe6f73c32
2 changed files with 4 additions and 15 deletions

@ -91,20 +91,9 @@ public class Configuration {
public void save() { public void save() {
synchronized(this.path) { synchronized(this.path) {
try { try (Writer writer = Files.newBufferedWriter(this.path, CHARSET)) {
Writer writer = Files.newBufferedWriter(this.path, CHARSET);
try {
ZNPCsPlus.GSON.toJson(this.configurationValues.size() == 1 ? this.configurationValues.values().iterator().next() : this.configurationValues, writer); ZNPCsPlus.GSON.toJson(this.configurationValues.size() == 1 ? this.configurationValues.values().iterator().next() : this.configurationValues, writer);
writer.close(); } catch (IOException ex) {
} catch (Throwable var7) {
try {
writer.close();
} catch (Throwable var6) {
var7.addSuppressed(var6);
}
throw var7;
}
} catch (IOException var8) {
throw new IllegalStateException("Failed to save config: " + this.name); throw new IllegalStateException("Failed to save config: " + this.name);
} }
} }

@ -6,7 +6,7 @@ import org.bukkit.scheduler.BukkitRunnable;
public class NPCSaveTask extends BukkitRunnable { public class NPCSaveTask extends BukkitRunnable {
public NPCSaveTask(Plugin serversNPC, int seconds) { public NPCSaveTask(Plugin serversNPC, int seconds) {
runTaskTimer(serversNPC, 200L, seconds); runTaskTimerAsynchronously(serversNPC, 200L, seconds);
} }
public void run() { public void run() {