mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-18 14:50:56 +00:00
convert all addons to use monad initialiser
This commit is contained in:
+17
-14
@@ -7,27 +7,30 @@
|
||||
|
||||
package com.dfsek.terra.addons.feature;
|
||||
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.addons.manifest.api.MonadAddonInitializer;
|
||||
import com.dfsek.terra.addons.manifest.api.monad.Do;
|
||||
import com.dfsek.terra.addons.manifest.api.monad.Get;
|
||||
import com.dfsek.terra.addons.manifest.api.monad.Init;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
import com.dfsek.terra.api.util.function.monad.Monad;
|
||||
|
||||
|
||||
public class FeatureAddon implements AddonInitializer {
|
||||
@Inject
|
||||
private Platform platform;
|
||||
|
||||
@Inject
|
||||
private BaseAddon addon;
|
||||
|
||||
public class FeatureAddon implements MonadAddonInitializer {
|
||||
@Override
|
||||
public void initialize() {
|
||||
platform.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> event.getPack().registerConfigType(new FeatureConfigType(), addon.key("FEATURE"), 500))
|
||||
.failThrough();
|
||||
public Monad<?, Init<?>> initialize() {
|
||||
return Do.with(
|
||||
Get.eventManager().map(eventManager -> eventManager.getHandler(FunctionalEventHandler.class)),
|
||||
Get.addon(),
|
||||
((functionalEventHandler, base) -> Init.ofPure(
|
||||
functionalEventHandler.register(base, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> event.getPack()
|
||||
.registerConfigType(new FeatureConfigType(), base.key("FEATURE"), 500))
|
||||
.failThrough()))
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user