diff options
author | ftbsc <dev@fantabos.co> | 2023-02-28 21:50:01 +0100 |
---|---|---|
committer | ftbsc <dev@fantabos.co> | 2023-02-28 21:50:01 +0100 |
commit | e3af53002f59167ae1923211be7982ac47ecf85d (patch) | |
tree | d10c3dd04a76ef8ae4fac7fb8317000624269755 | |
parent | c833568c4b9dabc690bb4c962058da0e9e0c455b (diff) |
fix: optional builder/dispatcher, moved cfg.pop
-rw-r--r-- | src/main/java/ftbsc/bscv/modules/AbstractModule.java | 2 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/system/ModManager.java | 19 |
2 files changed, 13 insertions, 8 deletions
diff --git a/src/main/java/ftbsc/bscv/modules/AbstractModule.java b/src/main/java/ftbsc/bscv/modules/AbstractModule.java index 7e6d2a6..a7f4b04 100644 --- a/src/main/java/ftbsc/bscv/modules/AbstractModule.java +++ b/src/main/java/ftbsc/bscv/modules/AbstractModule.java @@ -68,8 +68,6 @@ public abstract class AbstractModule implements IModule<AbstractModule.Group> { return 1; }) ); - - this.getConfigBuilder().pop(); } protected void onEnabled() {} diff --git a/src/main/java/ftbsc/bscv/system/ModManager.java b/src/main/java/ftbsc/bscv/system/ModManager.java index ea64b0c..d5ce124 100644 --- a/src/main/java/ftbsc/bscv/system/ModManager.java +++ b/src/main/java/ftbsc/bscv/system/ModManager.java @@ -14,29 +14,36 @@ import net.minecraft.command.CommandSource; import net.minecraftforge.common.ForgeConfigSpec; import java.util.HashSet; +import java.util.Optional; import java.util.Set; public class ModManager { - private final ForgeConfigSpec.Builder cfgBuilder; - private final CommandDispatcher<CommandSource> dispatcher; + private Optional<ForgeConfigSpec.Builder> cfgBuilder; + private Optional<CommandDispatcher<CommandSource>> dispatcher; public final Set<IModule<? extends Enum<?>> > mods; public ModManager(ForgeConfigSpec.Builder cfgBuilder, CommandDispatcher<CommandSource> dispatcher) { - this.cfgBuilder = cfgBuilder; - this.dispatcher = dispatcher; + this.cfgBuilder = Optional.of(cfgBuilder); + this.dispatcher = Optional.of(dispatcher); this.mods = new HashSet<>(); } public void registerMod(IModule<? extends Enum<?>> mod) { this.mods.add(mod); + this.cfgBuilder.get().pop(); // TODO solved by AutoService, soon TM + } + + public void finalize() { + this.cfgBuilder = Optional.empty(); + this.dispatcher = Optional.empty(); } public ForgeConfigSpec.Builder getCfgBuilder() { - return cfgBuilder; + return cfgBuilder.get(); } public CommandDispatcher<CommandSource> getDispatcher() { - return dispatcher; + return dispatcher.get(); } } |