Class StorageProvider

java.lang.Object
fr.prodrivers.bukkit.commons.storage.StorageProvider

public class StorageProvider extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.bson.Document
    createPlayer(UUID playerUniqueId)
    Creates a document for a player in the database, and returns it.
    static org.bson.Document
    getPlayer(UUID playerUniqueId)
    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 another
    static boolean
    updatePlayer(UUID playerUniqueId, org.bson.conversions.Bson updates)
    Updates a player's document with provided BSON values.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static org.bson.Document getPlayer(UUID playerUniqueId)
      Get a player's document.
      Parameters:
      playerUniqueId - Player's Unique ID
      Returns:
      Player's document or null
    • createPlayer

      public static org.bson.Document createPlayer(UUID playerUniqueId)
      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

      public static boolean updatePlayer(UUID playerUniqueId, org.bson.conversions.Bson updates)
      Updates a player's document with provided BSON values.
      Parameters:
      playerUniqueId - Player's Unique ID
      updates - BSON values to insert/update/delete in the document
      Returns:
      true if the update was successful
    • replacePlayer

      public static boolean replacePlayer(UUID playerUniqueId, org.bson.Document replaceDocument)
      Replaces a player's document with another
      Parameters:
      playerUniqueId - Player's Unique ID
      replaceDocument - Document
      Returns:
      true if the repalce was successful