Wiki 9Minecraft Wiki 9Minecraft

Make a Plugin Optional but Database-Ready

Java EditionPluginGuides 4FAQ 10Related mods 60
DownloadMongoDB Loader Plugin

Get the files on 9Minecraft

Contents (3)
  1. Use Soft Dependencies
  2. How This Works
  3. Code Considerations

Use Soft Dependencies

Some plugins work fine without a database but gain extra features when MongoDB is available. Use soft dependencies to allow this flexibility.

1. Open your plugin's plugin.yml

2. Add the line softdepend: [MongoDBLoader]

3. Save and restart the server

How This Works

With softdepend, your plugin loads regardless of whether MongoDB Loader Plugin is present. However, if MongoDB Loader Plugin is installed, it will load first, giving your plugin access to database tools.

Code Considerations

Your plugin code should check whether MongoDB Loader Plugin loaded before attempting database operations. If it's not available, your plugin should fall back to alternative storage methods—like local files—or disable database features gracefully.

This approach is ideal for plugins that enhance servers with optional features, ensuring they never break a server setup.

More guides for this mod