database not connecting every time an instance is created

This commit is contained in:
NK 2022-12-22 18:46:09 +00:00
parent 2f6281b2aa
commit 3771481d17
2 changed files with 2 additions and 4 deletions

View file

@ -18,7 +18,7 @@ public final class Main extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
EnchantmentManager.register(); EnchantmentManager.register();
new DatabaseManager(); new DatabaseManager().connect();
new CommandManager(); new CommandManager();
Bukkit.getPluginManager().registerEvents(new ServerEvents(), this); Bukkit.getPluginManager().registerEvents(new ServerEvents(), this);
Bukkit.getPluginManager().registerEvents(new InventoryListener(), this); Bukkit.getPluginManager().registerEvents(new InventoryListener(), this);

View file

@ -5,11 +5,9 @@ import org.bson.Document;
public class DatabaseManager { public class DatabaseManager {
public static MongoDatabase database; public static MongoDatabase database;
public void connect() {
public DatabaseManager() {
database = MongoClients.create(System.getenv("MONGODB_URI")).getDatabase("NullValkyrie"); database = MongoClients.create(System.getenv("MONGODB_URI")).getDatabase("NullValkyrie");
} }
public MongoCollection<Document> getMinersDB() { public MongoCollection<Document> getMinersDB() {
return database.getCollection("miners"); return database.getCollection("miners");
} }