refactor(redis): removed debug message
This commit is contained in:
parent
7c70ebf9b6
commit
f795d42564
3 changed files with 39 additions and 21 deletions
|
@ -1,4 +1,4 @@
|
||||||
package xyz.atnrch.nicko.appearance;
|
package xyz.atnrch.nicko.profile;
|
||||||
|
|
||||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||||
import com.comphenix.protocol.wrappers.*;
|
import com.comphenix.protocol.wrappers.*;
|
||||||
|
@ -11,6 +11,7 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import xyz.atnrch.nicko.NickoBukkit;
|
import xyz.atnrch.nicko.NickoBukkit;
|
||||||
import xyz.atnrch.nicko.i18n.I18NDict;
|
import xyz.atnrch.nicko.i18n.I18NDict;
|
||||||
|
import xyz.atnrch.nicko.i18n.Locale;
|
||||||
import xyz.atnrch.nicko.mojang.MojangAPI;
|
import xyz.atnrch.nicko.mojang.MojangAPI;
|
||||||
import xyz.atnrch.nicko.mojang.MojangSkin;
|
import xyz.atnrch.nicko.mojang.MojangSkin;
|
||||||
import xyz.atnrch.nicko.storage.PlayerDataStore;
|
import xyz.atnrch.nicko.storage.PlayerDataStore;
|
||||||
|
@ -23,29 +24,32 @@ import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
public class AppearanceManager {
|
public class ProfileManager {
|
||||||
private final NickoProfile profile;
|
private final NickoProfile profile;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
private final UUID uuid;
|
||||||
private final NickoBukkit instance = NickoBukkit.getInstance();
|
private final NickoBukkit instance = NickoBukkit.getInstance();
|
||||||
private final PlayerDataStore dataStore = instance.getDataStore();
|
private final PlayerDataStore dataStore = instance.getDataStore();
|
||||||
private final PlayerNameStore nameStore = instance.getNameStore();
|
private final PlayerNameStore nameStore = instance.getNameStore();
|
||||||
|
|
||||||
private AppearanceManager(UUID uuid) {
|
private ProfileManager(UUID uuid) {
|
||||||
this.player = Bukkit.getPlayer(uuid);
|
this.player = Bukkit.getPlayer(uuid);
|
||||||
|
this.uuid = uuid;
|
||||||
this.profile = dataStore.getData(uuid).orElse(NickoProfile.EMPTY_PROFILE.clone());
|
this.profile = dataStore.getData(uuid).orElse(NickoProfile.EMPTY_PROFILE.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
private AppearanceManager(String name) {
|
private ProfileManager(String name) {
|
||||||
this.player = null;
|
this.player = null;
|
||||||
|
this.uuid = null;
|
||||||
this.profile = dataStore.getOfflineData(name).orElse(NickoProfile.EMPTY_PROFILE.clone());
|
this.profile = dataStore.getOfflineData(name).orElse(NickoProfile.EMPTY_PROFILE.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AppearanceManager get(Player player) {
|
public static ProfileManager get(Player player) {
|
||||||
return new AppearanceManager(player.getUniqueId());
|
return new ProfileManager(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AppearanceManager get(String name) {
|
public static ProfileManager get(String name) {
|
||||||
return new AppearanceManager(name);
|
return new ProfileManager(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasData() {
|
public boolean hasData() {
|
||||||
|
@ -54,6 +58,7 @@ public class AppearanceManager {
|
||||||
|
|
||||||
public void setSkin(String skin) {
|
public void setSkin(String skin) {
|
||||||
profile.setSkin(skin);
|
profile.setSkin(skin);
|
||||||
|
dataStore.getCache().cache(uuid, profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSkin() {
|
public String getSkin() {
|
||||||
|
@ -66,12 +71,22 @@ public class AppearanceManager {
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
profile.setName(name);
|
profile.setName(name);
|
||||||
|
dataStore.getCache().cache(uuid, profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return profile.getName();
|
return profile.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLocale(Locale locale) {
|
||||||
|
profile.setLocale(locale);
|
||||||
|
dataStore.getCache().cache(uuid, profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Locale getLocale() {
|
||||||
|
return profile.getLocale();
|
||||||
|
}
|
||||||
|
|
||||||
public NickoProfile getProfile() {
|
public NickoProfile getProfile() {
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
@ -79,6 +94,7 @@ public class AppearanceManager {
|
||||||
public void setNameAndSkin(String name, String skin) {
|
public void setNameAndSkin(String name, String skin) {
|
||||||
this.profile.setName(name);
|
this.profile.setName(name);
|
||||||
this.profile.setSkin(skin);
|
this.profile.setSkin(skin);
|
||||||
|
dataStore.getCache().cache(uuid, profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult reset() {
|
public ActionResult reset() {
|
||||||
|
|
|
@ -3,9 +3,9 @@ package xyz.atnrch.nicko.storage.redis;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import xyz.atnrch.nicko.config.Configuration;
|
|
||||||
import xyz.atnrch.nicko.appearance.ActionResult;
|
import xyz.atnrch.nicko.appearance.ActionResult;
|
||||||
import xyz.atnrch.nicko.appearance.NickoProfile;
|
import xyz.atnrch.nicko.profile.NickoProfile;
|
||||||
|
import xyz.atnrch.nicko.config.Configuration;
|
||||||
import xyz.atnrch.nicko.storage.Cache;
|
import xyz.atnrch.nicko.storage.Cache;
|
||||||
import xyz.atnrch.nicko.storage.CacheProvider;
|
import xyz.atnrch.nicko.storage.CacheProvider;
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ public class RedisCache extends Cache {
|
||||||
private RedisCacheProvider provider;
|
private RedisCacheProvider provider;
|
||||||
|
|
||||||
public RedisCache(Configuration configuration) {
|
public RedisCache(Configuration configuration) {
|
||||||
System.out.println("Loaded REDIS CACHE");
|
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,23 +34,26 @@ public class RedisCache extends Cache {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult cache(UUID uuid, NickoProfile profile) {
|
public ActionResult cache(UUID uuid, NickoProfile profile) {
|
||||||
final Jedis jedis = provider.getJedis();
|
try (Jedis jedis = provider.getJedis()) {
|
||||||
jedis.set("nicko:" + uuid.toString(), gson.toJson(profile));
|
jedis.set("nicko:" + uuid.toString(), gson.toJson(profile));
|
||||||
return ActionResult.ok();
|
return ActionResult.ok();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCached(UUID uuid) {
|
public boolean isCached(UUID uuid) {
|
||||||
final Jedis jedis = provider.getJedis();
|
try (Jedis jedis = provider.getJedis()) {
|
||||||
return jedis.exists("nicko:" + uuid.toString());
|
return jedis.exists("nicko:" + uuid.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<NickoProfile> retrieve(UUID uuid) {
|
public Optional<NickoProfile> retrieve(UUID uuid) {
|
||||||
final Jedis jedis = provider.getJedis();
|
try (Jedis jedis = provider.getJedis()) {
|
||||||
// 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);
|
||||||
return Optional.of(profile);
|
return Optional.of(profile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue