A general use Java library including Modules, Events, Registries, and some basic data types
Add the following to your build.gradle.kts
file:
repositories {
maven("https://maven.wallentines.org/releases")
}
dependencies {
compileOnly("org.wallentines:midnightlib:2.2.0")
}
- MidnightLib has a system which allows you to create configurable modules which can be enabled or disabled at runtime.
- To implement this, start with a
ModuleManager
- A
ModuleManager
object is responsible for loading and unloading modules, and managing dependencies between them. ModuleManager
expects a template argumentT
, which defines the type of object which will be passed to all modules when they are loaded.
- A
- Next, create a
Registry
forModuleInfo
objects, and populate it withModuleInfo
objectsModuleInfo
objects define suppliers, default configurations, and dependencies forModule
objects
- Pass the registry to
ModuleManger::loadAll
, along with aConfigSection
orModuleConfigProvider
containing module configurations, and a data value of typeT
ModuleManager::loadAll
returns the number of modules successfully loaded
- MidnightLib has an Event system
- Global events can be fired using
Event.invoke()
and listened to usingEvent.register
- Specialized events can be implemented manually using a
HandlerList
object- Use
HandlerList::invoke
to fire events - Use
HandlerList::register
to register events
- Use
Either<A,B>
- Contains only one of the two template typesSingleton<T>
- Contains an instance of the template type- The default type cannot be reset once populated. Use
ResettableSingleton<T>
in the case you need to reset one - Use
DefaultedSingleton<T>
in the case where a default value should be specified before its populated
- The default type cannot be reset once populated. Use
RandomizedQueue<T>
- A queue which randomizes its inputs as they are addedRandomizedLoopingQueue<T>
- A randomized queue which contains a set list of values.- When the queue runs out, it will be refilled in a random order from the original list of values
SortedCollection<T>
- A collection which automatically sorts its contents as they are added