mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Remove deprecated BasicDAO and dev.morphia and replace it with the proper dependency
This commit is contained in:
parent
fac87d8c66
commit
f1744f2050
6
pom.xml
6
pom.xml
@ -49,9 +49,9 @@
|
||||
<!-- DATABASING -->
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.morphia.morphia</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<groupId>org.mongodb.morphia</groupId>
|
||||
<artifactId>morphia</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -1,9 +1,10 @@
|
||||
package me.totalfreedom.plex.cache;
|
||||
|
||||
import dev.morphia.query.Query;
|
||||
import dev.morphia.query.UpdateOperations;
|
||||
import me.totalfreedom.plex.Plex;
|
||||
import me.totalfreedom.plex.player.PlexPlayer;
|
||||
import org.mongodb.morphia.query.FindOptions;
|
||||
import org.mongodb.morphia.query.Query;
|
||||
import org.mongodb.morphia.query.UpdateOperations;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -21,7 +22,7 @@ public class MongoPlayerData
|
||||
|
||||
Query<PlexPlayer> query = plexPlayerDAO.createQuery();
|
||||
|
||||
if (query.field("uuid").exists().field("uuid").equal(uuid.toString()).find().tryNext() != null)
|
||||
if (query.field("uuid").exists().field("uuid").equal(uuid.toString()).get() != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -35,7 +36,7 @@ public class MongoPlayerData
|
||||
return PlayerCache.getPlexPlayerMap().get(uuid);
|
||||
}
|
||||
Query<PlexPlayer> query2 = plexPlayerDAO.createQuery().field("uuid").exists().field("uuid").equal(uuid.toString());
|
||||
return query2.first();
|
||||
return query2.get();
|
||||
}
|
||||
|
||||
public void update(PlexPlayer player)
|
||||
@ -48,7 +49,7 @@ public class MongoPlayerData
|
||||
updateOps.set("name", player.getName());
|
||||
updateOps.set("loginMSG", player.getLoginMSG());
|
||||
updateOps.set("prefix", player.getPrefix());
|
||||
updateOps.set("rank", player.getRank() == null ? "" : player.getRank().name().toLowerCase());
|
||||
updateOps.set("rank", player.getRank().toLowerCase());
|
||||
updateOps.set("ips", player.getIps());
|
||||
updateOps.set("coins", player.getCoins());
|
||||
plexPlayerDAO.update(filter, updateOps);
|
||||
|
@ -1,12 +1,12 @@
|
||||
package me.totalfreedom.plex.cache;
|
||||
|
||||
import dev.morphia.Datastore;
|
||||
import dev.morphia.Key;
|
||||
import dev.morphia.dao.BasicDAO;
|
||||
import dev.morphia.query.Query;
|
||||
import dev.morphia.query.UpdateOperations;
|
||||
import dev.morphia.query.UpdateResults;
|
||||
import me.totalfreedom.plex.player.PlexPlayer;
|
||||
import org.mongodb.morphia.Datastore;
|
||||
import org.mongodb.morphia.Key;
|
||||
import org.mongodb.morphia.dao.BasicDAO;
|
||||
import org.mongodb.morphia.query.Query;
|
||||
import org.mongodb.morphia.query.UpdateOperations;
|
||||
import org.mongodb.morphia.query.UpdateResults;
|
||||
|
||||
public class PlexPlayerDAO extends BasicDAO<PlexPlayer, Object> {
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class SQLPlayerData
|
||||
plexPlayer.setName(name);
|
||||
plexPlayer.setLoginMSG(loginMSG);
|
||||
plexPlayer.setPrefix(prefix);
|
||||
plexPlayer.setRank(rankName.isEmpty() ? null : rank);
|
||||
plexPlayer.setRank(rankName.toLowerCase());
|
||||
plexPlayer.setIps(ips);
|
||||
plexPlayer.setCoins(coins);
|
||||
}
|
||||
@ -80,7 +80,7 @@ public class SQLPlayerData
|
||||
statement.setString(1, player.getName());
|
||||
statement.setString(2, player.getLoginMSG());
|
||||
statement.setString(3, player.getPrefix());
|
||||
statement.setString(4, player.getRank() == null ? "" : player.getRank().name().toLowerCase());
|
||||
statement.setString(4, player.getRank().toLowerCase());
|
||||
statement.setString(5, new Gson().toJson(player.getIps()));
|
||||
statement.setLong(6, player.getCoins());
|
||||
statement.setString(7, player.getUuid());
|
||||
@ -100,7 +100,7 @@ public class SQLPlayerData
|
||||
statement.setString(2, player.getName());
|
||||
statement.setString(3, player.getLoginMSG());
|
||||
statement.setString(4, player.getPrefix());
|
||||
statement.setString(5, player.getRank() == null ? "" : player.getRank().name().toLowerCase());
|
||||
statement.setString(5, player.getRank().toLowerCase());
|
||||
statement.setString(6, new Gson().toJson(player.getIps()));
|
||||
statement.execute();
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package me.totalfreedom.plex.player;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.morphia.annotations.Id;
|
||||
import dev.morphia.annotations.IndexOptions;
|
||||
import dev.morphia.annotations.Indexed;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.totalfreedom.plex.rank.enums.Rank;
|
||||
import org.mongodb.morphia.annotations.Entity;
|
||||
import org.mongodb.morphia.annotations.Id;
|
||||
import org.mongodb.morphia.annotations.IndexOptions;
|
||||
import org.mongodb.morphia.annotations.Indexed;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -35,7 +35,7 @@ public class PlexPlayer
|
||||
|
||||
private long coins;
|
||||
|
||||
private Rank rank;
|
||||
private String rank;
|
||||
|
||||
private List<String> ips;
|
||||
|
||||
@ -56,7 +56,12 @@ public class PlexPlayer
|
||||
|
||||
this.ips = new ArrayList<>();
|
||||
|
||||
this.rank = null;
|
||||
this.rank = "";
|
||||
}
|
||||
|
||||
public Rank getRankFromString()
|
||||
{
|
||||
return Rank.valueOf(rank.toUpperCase());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,10 +2,10 @@ package me.totalfreedom.plex.storage;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.MongoClientURI;
|
||||
import dev.morphia.Datastore;
|
||||
import dev.morphia.Morphia;
|
||||
import me.totalfreedom.plex.Plex;
|
||||
import me.totalfreedom.plex.player.PlexPlayer;
|
||||
import org.mongodb.morphia.Datastore;
|
||||
import org.mongodb.morphia.Morphia;
|
||||
|
||||
public class MongoConnection
|
||||
{
|
||||
@ -33,7 +33,7 @@ public class MongoConnection
|
||||
Morphia morphia = new Morphia();
|
||||
Datastore datastore = morphia.createDatastore(client, database);
|
||||
|
||||
datastore.getMapper().addMappedClass(PlexPlayer.class);
|
||||
morphia.map(PlexPlayer.class);
|
||||
datastore.ensureIndexes();
|
||||
|
||||
plugin.setStorageType(StorageType.MONGO);
|
||||
|
@ -37,7 +37,9 @@ public class SQLConnection
|
||||
}
|
||||
|
||||
try {
|
||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (\n" +
|
||||
if (connection != null)
|
||||
{
|
||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (\n" +
|
||||
"\t`uuid` VARCHAR(46),\n" +
|
||||
"\t`name` VARCHAR(18),\n" +
|
||||
"\t`login_msg` VARCHAR(256),\n" +
|
||||
@ -47,6 +49,7 @@ public class SQLConnection
|
||||
"\t`coins` BIGINT,\n" +
|
||||
"\tPRIMARY KEY (`uuid`)\n" +
|
||||
");").execute();
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user