add option to load extra data when retrieving by username

This commit is contained in:
Taah 2022-05-08 17:56:06 -07:00
parent 9557737915
commit 0f76222f90
2 changed files with 9 additions and 4 deletions

View File

@ -81,7 +81,7 @@ public class DataUtils
} }
} }
public static PlexPlayer getPlayer(String username) public static PlexPlayer getPlayer(String username, boolean loadExtraData)
{ {
if (Plex.get().getStorageType() == StorageType.MONGODB) if (Plex.get().getStorageType() == StorageType.MONGODB)
{ {
@ -89,7 +89,7 @@ public class DataUtils
} }
else else
{ {
return Plex.get().getSqlPlayerData().getByName(username); return Plex.get().getSqlPlayerData().getByName(username, loadExtraData);
} }
} }

View File

@ -116,7 +116,7 @@ public class SQLPlayerData
return this.getByUUID(uuid, true); return this.getByUUID(uuid, true);
} }
public PlexPlayer getByName(String username) public PlexPlayer getByName(String username, boolean loadExtraData)
{ {
PlexPlayer player = PlayerCache.getPlexPlayerMap().values().stream().filter(plexPlayer -> plexPlayer.getName().equalsIgnoreCase(username)).findFirst().orElse(null); PlexPlayer player = PlayerCache.getPlexPlayerMap().values().stream().filter(plexPlayer -> plexPlayer.getName().equalsIgnoreCase(username)).findFirst().orElse(null);
if (player != null) if (player != null)
@ -130,7 +130,7 @@ public class SQLPlayerData
ResultSet set = statement.executeQuery(); ResultSet set = statement.executeQuery();
while (set.next()) while (set.next())
{ {
PlexPlayer plexPlayer = new PlexPlayer(UUID.fromString(set.getString("uuid"))); PlexPlayer plexPlayer = new PlexPlayer(UUID.fromString(set.getString("uuid")), loadExtraData);
String loginMSG = set.getString("login_msg"); String loginMSG = set.getString("login_msg");
String prefix = set.getString("prefix"); String prefix = set.getString("prefix");
String rankName = set.getString("rank").toUpperCase(); String rankName = set.getString("rank").toUpperCase();
@ -160,6 +160,11 @@ public class SQLPlayerData
return null; return null;
} }
public PlexPlayer getByName(String username)
{
return getByName(username, true);
}
/** /**
* Gets the player from cache or from the SQL database * Gets the player from cache or from the SQL database
* *