mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2025-01-07 19:28:10 +01:00
Fix async save on shutdown
This commit is contained in:
parent
f60b738248
commit
57f91cd95f
@ -49,7 +49,7 @@ public class Main extends JavaPlugin implements Listener {
|
||||
public void onDisable() {
|
||||
int file = 0;
|
||||
Bukkit.getScheduler().cancelTask(file);
|
||||
Files.DATA.saveFile();
|
||||
Files.DATA.saveFile(true);
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args) {
|
||||
|
@ -200,7 +200,7 @@ public class FileManager {
|
||||
/**
|
||||
* Saves the file from the loaded state to the file system.
|
||||
*/
|
||||
public void saveFile(Files file) {
|
||||
public void saveFile(Files file, boolean sync) {
|
||||
try {
|
||||
File targetFile = files.get(file);
|
||||
FileConfiguration configuration = configurations.get(file);
|
||||
@ -208,7 +208,7 @@ public class FileManager {
|
||||
YamlConfiguration copy = new YamlConfiguration();
|
||||
configuration.getValues(false).forEach(copy::set);
|
||||
|
||||
new BukkitRunnable() {
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -218,7 +218,12 @@ public class FileManager {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
};
|
||||
if (sync) {
|
||||
runnable.run();
|
||||
} else {
|
||||
runnable.runTaskAsynchronously(plugin);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
System.out.println(prefix + "File is null " + file.getFileName() + "!");
|
||||
e.printStackTrace();
|
||||
@ -352,10 +357,14 @@ public class FileManager {
|
||||
/**
|
||||
* Saves the file from the loaded state to the file system.
|
||||
*/
|
||||
public void saveFile() {
|
||||
getInstance().saveFile(this);
|
||||
public void saveFile(boolean sync) {
|
||||
getInstance().saveFile(this, sync);
|
||||
}
|
||||
|
||||
|
||||
public void saveFile() {
|
||||
getInstance().saveFile(this, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the loaded state file and loads the file systems file.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user