feat: delete from cache when leaving, reopen gui on changing language
This commit is contained in:
parent
6a4826f441
commit
ccae0084ea
3 changed files with 9 additions and 7 deletions
|
@ -4,6 +4,7 @@ import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import xyz.atnrch.nicko.NickoBukkit;
|
import xyz.atnrch.nicko.NickoBukkit;
|
||||||
|
import xyz.atnrch.nicko.gui.SettingsGUI;
|
||||||
import xyz.atnrch.nicko.i18n.I18N;
|
import xyz.atnrch.nicko.i18n.I18N;
|
||||||
import xyz.atnrch.nicko.i18n.I18NDict;
|
import xyz.atnrch.nicko.i18n.I18NDict;
|
||||||
import xyz.atnrch.nicko.i18n.ItemTranslation;
|
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.
|
// TODO (Ineanto, 7/14/23): This checks a 2nd time for the profile.
|
||||||
if (dataStore.updateCache(player.getUniqueId(), nickoProfile).isError()) {
|
if (dataStore.updateCache(player.getUniqueId(), nickoProfile).isError()) {
|
||||||
player.sendMessage(i18n.translate(I18NDict.Event.Settings.ERROR));
|
player.sendMessage(i18n.translate(I18NDict.Event.Settings.ERROR));
|
||||||
player.getOpenInventory().close();
|
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage("Updated language to " + nickoProfile.getLocale().getCode());
|
new SettingsGUI(player).open();
|
||||||
}
|
}
|
||||||
|
player.getOpenInventory().close();
|
||||||
}, localeOrdinal, providers);
|
}, localeOrdinal, providers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,12 +76,12 @@ public class PlayerDataStore {
|
||||||
if (storage.isError()) return ActionResult.error(I18NDict.Error.GENERIC);
|
if (storage.isError()) return ActionResult.error(I18NDict.Error.GENERIC);
|
||||||
if (cache.isError()) return ActionResult.error(I18NDict.Error.CACHE);
|
if (cache.isError()) return ActionResult.error(I18NDict.Error.CACHE);
|
||||||
if (!cache.isCached(player.getUniqueId())) return ActionResult.error(I18NDict.Error.GENERIC);
|
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
|
final Optional<NickoProfile> cachedProfile = cache.retrieve(player.getUniqueId());
|
||||||
//profiles.remove(player.getUniqueId());
|
if (!cachedProfile.isPresent()) return ActionResult.error(I18NDict.Error.GENERIC);
|
||||||
return storage.store(player.getUniqueId(), cache.retrieve(player.getUniqueId()).get());
|
|
||||||
|
cache.delete(player.getUniqueId());
|
||||||
|
return storage.store(player.getUniqueId(), cachedProfile.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Storage getStorage() {
|
public Storage getStorage() {
|
||||||
|
|
|
@ -50,6 +50,7 @@ public class RedisCache extends Cache {
|
||||||
@Override
|
@Override
|
||||||
public Optional<NickoProfile> retrieve(UUID uuid) {
|
public Optional<NickoProfile> retrieve(UUID uuid) {
|
||||||
try (Jedis jedis = provider.getJedis()) {
|
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
|
// 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 String data = jedis.get("nicko:" + uuid.toString());
|
||||||
final NickoProfile profile = gson.fromJson(data, NickoProfile.class);
|
final NickoProfile profile = gson.fromJson(data, NickoProfile.class);
|
||||||
|
|
Loading…
Reference in a new issue