Do not expose saving tasks to the api and change the way saving data is handled.
This commit is contained in:
@@ -46,7 +46,17 @@ public abstract class StorageProvider {
|
||||
|
||||
protected abstract EssentiaUser load(UUID uuid);
|
||||
|
||||
public abstract void save(@NotNull User user) throws Exception;
|
||||
public void startSaving(EssentiaUser user) throws Exception {
|
||||
if (user.saving() || !user.needsSaving()) return;
|
||||
user.saving(true);
|
||||
|
||||
save(user);
|
||||
|
||||
user.saving(false);
|
||||
user.needsSaving(false);
|
||||
}
|
||||
|
||||
public abstract void save(@NotNull EssentiaUser user) throws Exception;
|
||||
|
||||
public abstract void delete(UUID uuid) throws Exception;
|
||||
|
||||
@@ -54,17 +64,7 @@ public abstract class StorageProvider {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (User user : plugin.userManager().getUsers().values()) {
|
||||
try {
|
||||
if (user.saving()) {
|
||||
continue;
|
||||
}
|
||||
save(user);
|
||||
} catch (Exception e) {
|
||||
user.saving(false);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
plugin.userManager().saveAllUsers();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.storage.StorageProvider;
|
||||
import com.alttd.essentia.user.EssentiaUser;
|
||||
import com.alttd.essentia.user.User;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@@ -140,7 +139,7 @@ public class SQLStorageProvider extends StorageProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(@NotNull User user) throws Exception {
|
||||
public void save(@NotNull EssentiaUser user) throws Exception {
|
||||
// might not be the best way if new fields are added...
|
||||
// split into multiple tables - users, userdata, userhomes, ... ?
|
||||
String sql = "INSERT INTO users" +
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.alttd.essentia.storage.sqlite;
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.storage.StorageProvider;
|
||||
import com.alttd.essentia.user.EssentiaUser;
|
||||
import com.alttd.essentia.user.User;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
@@ -20,7 +19,7 @@ public class SQLiteStorageProvider extends StorageProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(@NotNull User user) throws Exception {
|
||||
public void save(@NotNull EssentiaUser user) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.alttd.essentia.storage.yaml;
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.storage.StorageProvider;
|
||||
import com.alttd.essentia.user.EssentiaUser;
|
||||
import com.alttd.essentia.user.User;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -42,10 +41,7 @@ public class YamlStorageProvider extends StorageProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(@NotNull User user) throws Exception {
|
||||
if (user.saving()) return;
|
||||
user.saving(true);
|
||||
|
||||
public void save(@NotNull EssentiaUser user) throws Exception {
|
||||
File configFile = new File(dataDirectory, user.getUUID() + ".yml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
@@ -57,7 +53,6 @@ public class YamlStorageProvider extends StorageProvider {
|
||||
config.set("allow-teleports", user.allowTeleports());
|
||||
|
||||
config.save(configFile);
|
||||
user.saving(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user