Closed Protonull closed 1 month ago
Hmmm, starting to wonder whether this refactor is moot: the server is just the compiled output of this monorepo; there'll NEVER be a question over whether NameLayer, or Citadel, or JukeAlert, is missing, unless we delete those plugins from the monorepo... which is unlikely. In addition, Okx has said that we should stop pretending that we aren't the only ones who consume our APIs (reference), and SoundTech has said that all changes must be tested with a local docker instance (reference) because it replicates the server as closely as possible. With these things in mind, I'm wondering whether it'd be better to yeet this boilerplate altogether and convert all our soft-dependencies into hard-dependencies.
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 theDependencyGlue
interface.Create a resource 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.