2020-10-27 20:12:38 +00:00
|
|
|
package me.totalfreedom.plex.cache;
|
|
|
|
|
2020-10-28 03:49:56 +00:00
|
|
|
import java.util.UUID;
|
2020-10-27 20:12:38 +00:00
|
|
|
import me.totalfreedom.plex.Plex;
|
|
|
|
import me.totalfreedom.plex.player.PlexPlayer;
|
2020-10-28 03:55:35 +00:00
|
|
|
import org.mongodb.morphia.query.Query;
|
|
|
|
import org.mongodb.morphia.query.UpdateOperations;
|
2020-10-27 20:12:38 +00:00
|
|
|
|
|
|
|
public class MongoPlayerData
|
|
|
|
{
|
2020-10-28 03:49:56 +00:00
|
|
|
private final PlexPlayerDAO plexPlayerDAO;
|
2020-10-27 20:12:38 +00:00
|
|
|
|
|
|
|
public MongoPlayerData()
|
|
|
|
{
|
|
|
|
this.plexPlayerDAO = new PlexPlayerDAO(PlexPlayer.class, Plex.get().getMongoConnection().getDatastore());
|
|
|
|
}
|
|
|
|
|
2020-10-28 03:49:56 +00:00
|
|
|
public boolean exists(UUID uuid)
|
|
|
|
{
|
2020-10-27 20:12:38 +00:00
|
|
|
Query<PlexPlayer> query = plexPlayerDAO.createQuery();
|
|
|
|
|
2020-10-28 03:55:35 +00:00
|
|
|
return query.field("uuid").exists().field("uuid").equal(uuid.toString()).get() != null;
|
2020-10-27 20:12:38 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 03:49:56 +00:00
|
|
|
public PlexPlayer getByUUID(UUID uuid)
|
|
|
|
{
|
2020-10-27 20:12:38 +00:00
|
|
|
|
2020-10-27 21:04:05 +00:00
|
|
|
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
|
2020-10-27 20:12:38 +00:00
|
|
|
{
|
2020-10-27 21:04:05 +00:00
|
|
|
return PlayerCache.getPlexPlayerMap().get(uuid);
|
2020-10-27 20:12:38 +00:00
|
|
|
}
|
|
|
|
Query<PlexPlayer> query2 = plexPlayerDAO.createQuery().field("uuid").exists().field("uuid").equal(uuid.toString());
|
2020-10-28 03:55:35 +00:00
|
|
|
return query2.get();
|
2020-10-27 20:12:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void update(PlexPlayer player)
|
|
|
|
{
|
|
|
|
Query<PlexPlayer> filter = plexPlayerDAO.createQuery()
|
2020-10-28 03:49:56 +00:00
|
|
|
.field("uuid").equal(player.getUuid());
|
2020-10-27 20:12:38 +00:00
|
|
|
|
|
|
|
UpdateOperations<PlexPlayer> updateOps = plexPlayerDAO.createUpdateOperations();
|
|
|
|
|
|
|
|
updateOps.set("name", player.getName());
|
|
|
|
updateOps.set("loginMSG", player.getLoginMSG());
|
|
|
|
updateOps.set("prefix", player.getPrefix());
|
2020-10-28 03:55:35 +00:00
|
|
|
updateOps.set("rank", player.getRank().toLowerCase());
|
2020-10-27 20:12:38 +00:00
|
|
|
updateOps.set("ips", player.getIps());
|
2020-10-27 21:30:57 +00:00
|
|
|
updateOps.set("coins", player.getCoins());
|
2020-10-27 20:12:38 +00:00
|
|
|
plexPlayerDAO.update(filter, updateOps);
|
|
|
|
}
|
|
|
|
|
2020-10-28 03:49:56 +00:00
|
|
|
public PlexPlayerDAO getPlexPlayerDAO()
|
|
|
|
{
|
2020-10-27 20:12:38 +00:00
|
|
|
return plexPlayerDAO;
|
|
|
|
}
|
2020-10-28 03:55:35 +00:00
|
|
|
}
|