Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR refactors the APIs provided by CivModCore that were intended to help hooking into soft dependencies. Now, any plugin that wishes to create a dependency glue need only do the following:
Ensure that CivModCore is declared within the
depend
orsoftdepend
lists in your plugin'splugin.yml
Create a class that will NEVER be touched by any other code, eg:
src/main/java/net/civmc/example/glues/NameLayerGlue.java
Which must implement the
DependencyGlue
interface.Create a file called
glues.properties
and with the content:Where the key is the name of the dependency and the value the class-name of the glue.
Done.
That's it... the glue class will be initialised when CivModCore detects the dependency is enabled for the first time and then invoke
enable()
. If the dependency is disabled at some point, thedisable()
method is called. Any subsequent re-enabling will callenable()
, etc.This does mean that glues cannot themselves be API interfaces: the entire point is that they're only interacted with by CivModCore's
GlueManager
class, but this is a great way of safely registering listeners and such without fear these kinds of issues, since the class is never initialised if the dependency is not present.