feat: delete from cache when leaving, reopen gui on changing language

This commit is contained in:
ineanto 2023-08-29 20:20:56 +02:00
parent 6a4826f441
commit ccae0084ea
3 changed files with 9 additions and 7 deletions

View file

@ -4,6 +4,7 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import xyz.atnrch.nicko.NickoBukkit;
import xyz.atnrch.nicko.gui.SettingsGUI;
import xyz.atnrch.nicko.i18n.I18N;
import xyz.atnrch.nicko.i18n.I18NDict;
import xyz.atnrch.nicko.i18n.ItemTranslation;
@ -44,10 +45,10 @@ public class LanguageCyclingItem {
// TODO (Ineanto, 7/14/23): This checks a 2nd time for the profile.
if (dataStore.updateCache(player.getUniqueId(), nickoProfile).isError()) {
player.sendMessage(i18n.translate(I18NDict.Event.Settings.ERROR));
player.getOpenInventory().close();
} else {
player.sendMessage("Updated language to " + nickoProfile.getLocale().getCode());
new SettingsGUI(player).open();
}
player.getOpenInventory().close();
}, localeOrdinal, providers);
}

View file

@ -76,12 +76,12 @@ public class PlayerDataStore {
if (storage.isError()) return ActionResult.error(I18NDict.Error.GENERIC);
if (cache.isError()) return ActionResult.error(I18NDict.Error.CACHE);
if (!cache.isCached(player.getUniqueId())) return ActionResult.error(I18NDict.Error.GENERIC);
if (!cache.retrieve(player.getUniqueId()).isPresent())
return ActionResult.error(I18NDict.Error.GENERIC);
// TODO (Ineanto, 5/20/23): Remove value from cache
//profiles.remove(player.getUniqueId());
return storage.store(player.getUniqueId(), cache.retrieve(player.getUniqueId()).get());
final Optional<NickoProfile> cachedProfile = cache.retrieve(player.getUniqueId());
if (!cachedProfile.isPresent()) return ActionResult.error(I18NDict.Error.GENERIC);
cache.delete(player.getUniqueId());
return storage.store(player.getUniqueId(), cachedProfile.get());
}
public Storage getStorage() {

View file

@ -50,6 +50,7 @@ public class RedisCache extends Cache {
@Override
public Optional<NickoProfile> retrieve(UUID uuid) {
try (Jedis jedis = provider.getJedis()) {
// 29/08/23: what the fuck was I talking about?
// TODO (Ineanto, 5/20/23): Check if cached before because Jedis returns a bulk reply so this is unsafe
final String data = jedis.get("nicko:" + uuid.toString());
final NickoProfile profile = gson.fromJson(data, NickoProfile.class);