mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-27 10:49:08 +00:00
Block main thread on disable to ensure data is saved
This commit is contained in:
@@ -41,7 +41,7 @@ public interface IStorageManager {
|
||||
* Removes an account from the storage cache and saves its data.
|
||||
* @param uuid player's UUID
|
||||
*/
|
||||
void removeCachedAccount(UUID uuid);
|
||||
CompletableFuture<Void> removeCachedAccount(UUID uuid);
|
||||
|
||||
/**
|
||||
* Gets a UUID safe to use in databases.
|
||||
|
||||
@@ -46,6 +46,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI, LanguagyPluginHook {
|
||||
|
||||
@@ -91,15 +92,20 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI, Lang
|
||||
} else {
|
||||
// Save all player data (quit event not called for shutdown)
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
if (managers.getStorageManager().getCachedAccounts().containsKey(player.getUniqueId()))
|
||||
this.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId());
|
||||
if (managers.getStorageManager().getCachedAccounts().containsKey(player.getUniqueId())) {
|
||||
try {
|
||||
this.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId()).get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Save all region configs
|
||||
managers.getRegionsCache().getConfiguredRegions().forEach((id, region) -> region.save(this));
|
||||
}
|
||||
|
||||
// Close database connection
|
||||
RPGRegionsAPI.setAPI(null);
|
||||
DB.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -97,9 +97,9 @@ public abstract class SQLCommonStorage implements IStorageManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCachedAccount(UUID uuid) {
|
||||
public CompletableFuture<Void> removeCachedAccount(UUID uuid) {
|
||||
RPGRegionsAccount account = cachedAccounts.get(uuid);
|
||||
DB.getResultsAsync(SELECT_REGION, getDatabaseUuid(uuid)).thenAccept(results -> {
|
||||
return DB.getResultsAsync(SELECT_REGION, getDatabaseUuid(uuid)).thenAccept(results -> {
|
||||
List<String> current = new ArrayList<>();
|
||||
for (DbRow row : results) {
|
||||
current.add(row.getString("region"));
|
||||
|
||||
@@ -134,7 +134,7 @@ public class YamlStorage implements IStorageManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCachedAccount(UUID uuid) {
|
||||
public CompletableFuture<Void> removeCachedAccount(UUID uuid) {
|
||||
RPGRegionsAccount account = cachedAccounts.get(uuid);
|
||||
File file = new File(plugin.getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
@@ -151,5 +151,6 @@ public class YamlStorage implements IStorageManager {
|
||||
e.printStackTrace();
|
||||
}
|
||||
cachedAccounts.remove(uuid);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user