2020-10-27 20:12:38 +00:00
|
|
|
package me.totalfreedom.plex.cache;
|
|
|
|
|
|
|
|
import me.totalfreedom.plex.Plex;
|
|
|
|
import me.totalfreedom.plex.player.PlexPlayer;
|
2020-10-28 03:45:01 +00:00
|
|
|
import org.mongodb.morphia.query.FindOptions;
|
|
|
|
import org.mongodb.morphia.query.Query;
|
|
|
|
import org.mongodb.morphia.query.UpdateOperations;
|
2020-10-27 20:12:38 +00:00
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
public class MongoPlayerData
|
|
|
|
{
|
|
|
|
|
|
|
|
private PlexPlayerDAO plexPlayerDAO;
|
|
|
|
|
|
|
|
public MongoPlayerData()
|
|
|
|
{
|
|
|
|
this.plexPlayerDAO = new PlexPlayerDAO(PlexPlayer.class, Plex.get().getMongoConnection().getDatastore());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean exists(UUID uuid) {
|
|
|
|
|
|
|
|
Query<PlexPlayer> query = plexPlayerDAO.createQuery();
|
|
|
|
|
2020-10-28 03:45:01 +00:00
|
|
|
if (query.field("uuid").exists().field("uuid").equal(uuid.toString()).get() != null)
|
2020-10-27 20:12:38 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlexPlayer getByUUID(UUID uuid) {
|
|
|
|
|
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:45:01 +00:00
|
|
|
return query2.get();
|
2020-10-27 20:12:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void update(PlexPlayer player)
|
|
|
|
{
|
|
|
|
Query<PlexPlayer> filter = plexPlayerDAO.createQuery()
|
|
|
|
.field("uuid").equal(player.getUuid());
|
|
|
|
|
|
|
|
UpdateOperations<PlexPlayer> updateOps = plexPlayerDAO.createUpdateOperations();
|
|
|
|
|
|
|
|
updateOps.set("name", player.getName());
|
|
|
|
updateOps.set("loginMSG", player.getLoginMSG());
|
|
|
|
updateOps.set("prefix", player.getPrefix());
|
2020-10-28 03:45:01 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlexPlayerDAO getPlexPlayerDAO() {
|
|
|
|
return plexPlayerDAO;
|
|
|
|
}
|
|
|
|
}
|