Class StorageProvider
java.lang.Object
fr.prodrivers.bukkit.commons.storage.StorageProvider
Persistent storage provider for Prodrivers plugins.
StorageProvider allows Prodrivers plugins to store persistent data across servers in a document format, backed by MongoDB.
Its primary feature is to allow plugins to store players data across servers.
StorageProvider exposes a Java MongoDB driver database, as well as players-related storage primitives.
Initialization is handled by the plugin.
It is strongly encouraged to use player primitives when dealing with players data, as they take care of document initialization.
StorageProvider is an optional part of the plugin, meaning that the result of its methods, on top of MongoDB internal quirks and wrong queries, is not guaranteed to be correct.
One must check against null each results returned by StorageProvider.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.bson.Document
createPlayer
(UUID playerUniqueId) Creates a document for a player in the database, and returns it.static org.bson.Document
Get a player's document.static com.mongodb.client.MongoCollection<org.bson.Document>
Gets the players collection from database.static com.mongodb.client.MongoDatabase
Gets the used MongoDatabase instance.static boolean
replacePlayer
(UUID playerUniqueId, org.bson.Document replaceDocument) Replaces a player's document with anotherstatic boolean
updatePlayer
(UUID playerUniqueId, org.bson.conversions.Bson updates) Updates a player's document with provided BSON values.
-
Constructor Details
-
StorageProvider
public StorageProvider()
-
-
Method Details
-
getStorage
public static com.mongodb.client.MongoDatabase getStorage()Gets the used MongoDatabase instance.- Returns:
- Mongo database instance or null
-
getPlayersCollection
public static com.mongodb.client.MongoCollection<org.bson.Document> getPlayersCollection()Gets the players collection from database.- Returns:
- Players document collection or null
-
getPlayer
Get a player's document.- Parameters:
playerUniqueId
- Player's Unique ID- Returns:
- Player's document or null
-
createPlayer
Creates a document for a player in the database, and returns it. There is little need to call it directly, as getPlayer automatically creates it if it does not exists.- Parameters:
playerUniqueId
- Player's Unique ID- Returns:
- Player's document or null
-
updatePlayer
Updates a player's document with provided BSON values.- Parameters:
playerUniqueId
- Player's Unique IDupdates
- BSON values to insert/update/delete in the document- Returns:
true
if the update was successful
-
replacePlayer
Replaces a player's document with another- Parameters:
playerUniqueId
- Player's Unique IDreplaceDocument
- Document- Returns:
true
if the repalce was successful
-