MongoDB Module

Module must be shaded to your JAR file

{VERSION} - current version form GitHub releases section: https://github.com/timsixth/MinigameAPI/releases

<repositories>
  <repository>
   <id>jitpack.io</id>
   <url>https://jitpack.io</url>
  </repository>
</repositories>

<dependency>
   <groupId>com.github.timsixth.MinigameAPI</groupId>
   <artifactId>mongodb-support</artifactId>
   <version>{VERSION}</version>
</dependency>

How to register MongoDB Module?

//Use MongoDbLibraryConfiguration instend of LibraryConfiguration
    //Type list with MongoDbModule
    @Override
    protected LibraryConfiguration configure() {
        return new MongoDbLibraryConfiguration(this, getConfiguratorsInitializer())
                .builder()
                .setGameManager(new MyGameManager())
                .registerModules(new MongoDbModule())
                .build();
    }

with custom MongoDb module configuration (Optional but recommended)

    @Override
    protected LibraryConfiguration configure() {
        return new MongoDbLibraryConfiguration(this, getConfiguratorsInitializer())
                .builder()
                .setGameManager(new MyGameManager())
                .registerModules(new MongoDbModule(new MyMongoDbModuleConfigurator().configure()))
                .build();
    }
public class MyMongoDbModuleConfigurator extends DefaultMongoDbModuleConfigurator {

   @Override
    public MongoDbModuleConfiguration configure() {
        return MongoDbModuleConfiguration.builder()
                .mongoDbUri("mongodb://localhost:27017") //you can change this
                .databaseName("minigameapi") //you can change this
                .build();
    }
}

MongoDB module methods:

MongoDbModule mongoDbModule = MongoDbModule.getInstance(); //Gets instance of module

mongoDbModule.getMongoDbConnector(); //Gets MongoDbConnector

Last updated