summaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/bscv/system/ModManager.java
blob: e5f1c3cdd744a2eb2789b5e1230ebb5245e13bdd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package ftbsc.bscv.system;

import com.mojang.brigadier.CommandDispatcher;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.api.IModule;
import net.minecraft.command.CommandSource;
import net.minecraftforge.common.ForgeConfigSpec;

import java.util.HashSet;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;

public class ModManager {
   private Optional<ForgeConfigSpec.Builder> cfgBuilder;
   private Optional<CommandDispatcher<CommandSource>> dispatcher;

   public final Set<IModule> mods;
   public final Set<String> categories;

   public ModManager(ForgeConfigSpec.Builder cfgBuilder, CommandDispatcher<CommandSource> dispatcher) {
      this.cfgBuilder = Optional.of(cfgBuilder);
      this.dispatcher = Optional.of(dispatcher);
      this.mods = new HashSet<>();
      this.categories = new HashSet<>();
   }
      
   public void load() {
      for (ILoadable module : ServiceLoader.load(ILoadable.class)) {
         if(module instanceof IModule) {
            IModule mod =  (IModule) module;
            this.mods.add(mod);
            this.categories.add(mod.getGroup());
            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.get();
   }

   public CommandDispatcher<CommandSource> getDispatcher() {
      return dispatcher.get();
   }
}