feat(storage): fallback on local storage
This commit is contained in:
parent
cb98fd2671
commit
48ca85028b
4 changed files with 25 additions and 12 deletions
|
@ -6,7 +6,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = "xyz.ineanto"
|
||||
version = "1.0.7-RC1"
|
||||
version = "1.0.8-RC1"
|
||||
|
||||
val shadowImplementation: Configuration by configurations.creating
|
||||
configurations["implementation"].extendsFrom(shadowImplementation)
|
||||
|
|
|
@ -16,6 +16,8 @@ import xyz.ineanto.nicko.i18n.LocaleFileManager;
|
|||
import xyz.ineanto.nicko.mojang.MojangAPI;
|
||||
import xyz.ineanto.nicko.placeholder.NickoExpansion;
|
||||
import xyz.ineanto.nicko.storage.PlayerDataStore;
|
||||
import xyz.ineanto.nicko.storage.json.JSONStorage;
|
||||
import xyz.ineanto.nicko.storage.map.MapCache;
|
||||
import xyz.ineanto.nicko.storage.name.PlayerNameStore;
|
||||
import xyz.xenondevs.invui.gui.structure.Structure;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
|
@ -73,14 +75,18 @@ public class NickoBukkit extends JavaPlugin {
|
|||
|
||||
getLogger().info("Loading persistence...");
|
||||
if (!dataStore.getStorage().getProvider().init()) {
|
||||
dataStore.getStorage().setError(true);
|
||||
getLogger().severe("Failed to open persistence, data will NOT be saved!");
|
||||
getLogger().severe("Couldn't connect to distant persistence, falling back on local persistence.");
|
||||
final JSONStorage storage = new JSONStorage();
|
||||
storage.getProvider().init();
|
||||
dataStore.setStorage(storage);
|
||||
}
|
||||
|
||||
getLogger().info("Loading cache...");
|
||||
if (!dataStore.getCache().getProvider().init()) {
|
||||
dataStore.getCache().setError(true);
|
||||
getLogger().severe("Failed to open cache, data will NOT be saved!");
|
||||
getLogger().severe("Couldn't connect to distant cache, falling back on local cache.");
|
||||
final MapCache cache = new MapCache();
|
||||
cache.getProvider().init();
|
||||
dataStore.setCache(cache);
|
||||
}
|
||||
|
||||
if (!unitTesting) {
|
||||
|
|
|
@ -19,10 +19,11 @@ import java.util.UUID;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class PlayerDataStore {
|
||||
private final Storage storage;
|
||||
private final Cache cache;
|
||||
private final MojangAPI mojangAPI;
|
||||
|
||||
private Storage storage;
|
||||
private Cache cache;
|
||||
|
||||
public PlayerDataStore(MojangAPI mojangAPI, Configuration configuration) {
|
||||
this.mojangAPI = mojangAPI;
|
||||
this.storage = configuration.getSqlConfiguration().isEnabled() ?
|
||||
|
@ -81,7 +82,7 @@ public class PlayerDataStore {
|
|||
if (!cache.isCached(player.getUniqueId())) return ActionResult.error(I18NDict.Error.CACHE);
|
||||
|
||||
final Optional<NickoProfile> cachedProfile = cache.retrieve(player.getUniqueId());
|
||||
if (!cachedProfile.isPresent()) return ActionResult.error(I18NDict.Error.CACHE);
|
||||
if (cachedProfile.isEmpty()) return ActionResult.error(I18NDict.Error.CACHE);
|
||||
|
||||
cache.delete(player.getUniqueId());
|
||||
return storage.store(player.getUniqueId(), cachedProfile.get());
|
||||
|
@ -91,7 +92,15 @@ public class PlayerDataStore {
|
|||
return storage;
|
||||
}
|
||||
|
||||
public void setStorage(Storage storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
public Cache getCache() {
|
||||
return cache;
|
||||
}
|
||||
|
||||
public void setCache(Cache cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,7 @@ package xyz.ineanto.nicko.test.storage;
|
|||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.*;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
|
@ -19,6 +16,7 @@ import java.util.Optional;
|
|||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@Disabled
|
||||
public class BrokenSQLTest {
|
||||
private static NickoBukkit plugin;
|
||||
private static PlayerMock player;
|
||||
|
|
Loading…
Reference in a new issue