41 lines
1.1 KiB
Java
41 lines
1.1 KiB
Java
package net.krakatoa.proxy.mongo;
|
|
|
|
import com.mongodb.async.client.MongoClient;
|
|
import com.mongodb.async.client.MongoClients;
|
|
import com.mongodb.async.client.MongoCollection;
|
|
import com.mongodb.async.client.MongoDatabase;
|
|
import lombok.Getter;
|
|
import org.bson.Document;
|
|
|
|
public class MongoManager {
|
|
|
|
private final String hostname;
|
|
private final int port;
|
|
private final String username;
|
|
private final String password;
|
|
|
|
// TODO: search for replacements for deprecated methods
|
|
@Getter
|
|
private MongoDatabase mongoDatabase;
|
|
@Getter
|
|
private MongoClient mongoClient;
|
|
@Getter
|
|
private MongoCollection<Document> players;
|
|
|
|
public MongoManager(String hostname, int port, String username, String password) {
|
|
this.hostname = hostname;
|
|
this.port = port;
|
|
this.username = username;
|
|
this.password = password;
|
|
}
|
|
|
|
public void connect(String database) {
|
|
mongoClient = MongoClients.create(
|
|
"mongodb://" + username + ":" + password + "@" + hostname + ":" + port + "/?authSource="
|
|
+ database);
|
|
|
|
mongoDatabase = mongoClient.getDatabase(database);
|
|
players = mongoDatabase.getCollection("players");
|
|
}
|
|
}
|