Minor changes

This commit is contained in:
samo_lego 2020-10-16 23:00:47 +02:00
parent 653823e2ee
commit 630c3a1fe9
2 changed files with 14 additions and 5 deletions

View File

@ -113,7 +113,13 @@ public abstract class MixinPlayerEntity implements PlayerAuth {
if(!playerCacheMap.containsKey(this.getFakeUuid())) { if(!playerCacheMap.containsKey(this.getFakeUuid())) {
// First join // First join
playerCache = PlayerCache.fromJson(player, DB.getUserData(this.getFakeUuid())); String jsonString = DB.getUserData(this.getFakeUuid());
if(jsonString != null && !jsonString.isEmpty())
playerCache = PlayerCache.fromJson(player, jsonString);
else
playerCache = new PlayerCache(player);
// Saving to hashmap of player caches
playerCacheMap.put(this.getFakeUuid(), playerCache); playerCacheMap.put(this.getFakeUuid(), playerCache);
} }
else { else {

View File

@ -65,6 +65,11 @@ public class PlayerCache {
private static final Gson gson = new Gson(); private static final Gson gson = new Gson();
/**
* Creates an empty cache for player (when player doesn't exist in DB).
*
* @param player player to create cache for
*/
public PlayerCache(ServerPlayerEntity player) { public PlayerCache(ServerPlayerEntity player) {
if(config.experimental.debugMode) if(config.experimental.debugMode)
logInfo("Creating cache for " + Objects.requireNonNull(player).getName()); logInfo("Creating cache for " + Objects.requireNonNull(player).getName());
@ -100,10 +105,6 @@ public class PlayerCache {
} }
public static PlayerCache fromJson(ServerPlayerEntity player, String json) { public static PlayerCache fromJson(ServerPlayerEntity player, String json) {
if(json.isEmpty()) {
// Player doesn't have data yet
return new PlayerCache(player);
}
if(config.experimental.debugMode) if(config.experimental.debugMode)
logInfo("Creating cache for " + Objects.requireNonNull(player).getName()); logInfo("Creating cache for " + Objects.requireNonNull(player).getName());
@ -111,6 +112,8 @@ public class PlayerCache {
PlayerCache playerCache = gson.fromJson(json, PlayerCache.class); PlayerCache playerCache = gson.fromJson(json, PlayerCache.class);
playerCache.loginTries = 0; playerCache.loginTries = 0;
playerCache.isAuthenticated = false;
if(playerCache.password != null && !playerCache.password.isEmpty()) { if(playerCache.password != null && !playerCache.password.isEmpty()) {
playerCache.isRegistered = true; playerCache.isRegistered = true;
} }