How can I enforce the presence of mods and Sponge of certain version?

Hello!

Imagine I want my plugin to work only, if the Minecraft installation it runs on

a) has a certain Sponge version,
b) certain Forge version and
c) some mods are present and all of them have the correct versions (the correct versions are hard-coded into my plugin).

Questions:

  1. Is it possible to get the list and the version information of installed mods from within plugin?

  2. What is the best practice to disable (and let the user know) a Sponge mod/plugin, if some of the prerequisites are not met? Print a console message, write to log, both, or something else?

Thanks

Dmitri Pisarenko

One phrase: dependency annotations

You can depend on any “plugin,” and according to Sponge, mods, forge, plugins, and MC itself, are plugins. Furthermore, there is a “version” option in the annotation.

Edit:
Using the annotation takes care of everything you want. Now, if you don’t want to prevent the server from starting, make the dependencies optional and only register listeners if all the plugins are present.

Edit 2:
You may also want to use the PluginManager to get information. (Sponge.getPluginManager()).

1 Like