The plugin sets up a connection to a MongoDB. With the help of Jackson its able to store and work with POJO's directly.
An example can be found in the tests here.
repositories {
maven(url = "https://jitpack.io")
}
dependencies {
implementation("com.github.ItsKev.persistence-framework:persistence-framework-proxy:v1.0.0:all")
}
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.ItsKev.persistence-framework</groupId>
<artifactId>persistence-framework-bukkit</artifactId>
<version>v1.0.0</version>
<classifier>all</classifier>
</dependency>
Name | Description |
---|---|
CONNECTION_STRING | The connection string for MongoDB. Examples can be found here. |
AUTHENTICATION_DATABASE | The database where the user is stored. (e.g. admin) |
USERNAME | The username which the login is done with |
PASSWORD | The password to the given username |
Getting an instance of the MongoDbService is done over the ServicesManager
from Bukkit itself. This is done to prevent opening multiple connections to the MongoDB.
MongoDbService mongoDbService = getServer().getServicesManager().load(MongoDbService.class);
To get an instance of the MongoDbService you have to get an instance of the PersistenceFrameworkPlugin first and get the MongoDbService from there.
PersistenceFrameworkPlugin persistenceFrameworkPlugin =
(PersistenceFrameworkPlugin) getProxy().getPluginManager().getPlugin("PersistenceFramework");
MongoDbService mongoDbService = persistenceFrameworkPlugin.getMongoDbService();