From 930ccf34c72fc6c0e85648681b91d46c986e2b9a Mon Sep 17 00:00:00 2001 From: ftbsc Date: Tue, 28 Feb 2023 23:00:03 +0100 Subject: [PATCH] feat: implemented auto service for modules --- build.gradle | 2 ++ src/main/java/ftbsc/bscv/BoSCoVicino.java | 29 ++----------------- src/main/java/ftbsc/bscv/api/IModule.java | 4 +-- .../ftbsc/bscv/modules/AbstractModule.java | 16 ++-------- .../java/ftbsc/bscv/modules/HudModule.java | 7 ++--- .../java/ftbsc/bscv/modules/QuickModule.java | 7 ++--- .../java/ftbsc/bscv/modules/defense/Aura.java | 3 ++ .../ftbsc/bscv/modules/hud/ActiveModules.java | 7 +++-- .../ftbsc/bscv/modules/hud/Coordinates.java | 9 +++--- .../ftbsc/bscv/modules/hud/EntityList.java | 3 ++ .../ftbsc/bscv/modules/hud/InfoDisplay.java | 3 ++ .../ftbsc/bscv/modules/hud/PlayerList.java | 3 ++ .../ftbsc/bscv/modules/motion/BoatFly.java | 5 ++-- .../bscv/modules/motion/VanillaFlight.java | 3 ++ .../ftbsc/bscv/modules/self/AntiHunger.java | 3 ++ .../bscv/modules/self/AutoDisconnect.java | 3 ++ .../ftbsc/bscv/modules/self/AutoFish.java | 3 ++ .../ftbsc/bscv/modules/self/AutoTool.java | 3 ++ .../ftbsc/bscv/modules/self/FastInteract.java | 3 ++ .../java/ftbsc/bscv/modules/self/Freecam.java | 3 ++ .../ftbsc/bscv/modules/self/PortalGui.java | 3 ++ .../ftbsc/bscv/modules/vision/Fullbright.java | 3 ++ .../java/ftbsc/bscv/system/ModManager.java | 28 +++++++++--------- src/main/java/ftbsc/bscv/tools/Setting.java | 4 +-- 24 files changed, 82 insertions(+), 75 deletions(-) diff --git a/build.gradle b/build.gradle index ba15d21..4274a11 100644 --- a/build.gradle +++ b/build.gradle @@ -92,9 +92,11 @@ dependencies { minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}" implementation 'ftbsc:lll:0.2.2' implementation 'ftbsc.lll:processor:0.1.1' + implementation 'com.google.auto.service:auto-service-annotations:1.0.1' annotationProcessor 'com.squareup:javapoet:1.13.0' annotationProcessor 'ftbsc:lll:0.2.2' annotationProcessor 'ftbsc.lll:processor:0.1.1' + annotationProcessor 'com.google.auto.service:auto-service:1.0.1' } jar { diff --git a/src/main/java/ftbsc/bscv/BoSCoVicino.java b/src/main/java/ftbsc/bscv/BoSCoVicino.java index a3911c0..141aa76 100644 --- a/src/main/java/ftbsc/bscv/BoSCoVicino.java +++ b/src/main/java/ftbsc/bscv/BoSCoVicino.java @@ -28,12 +28,6 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import java.lang.reflect.Field; -import ftbsc.bscv.modules.vision.*; -import ftbsc.bscv.modules.motion.*; -import ftbsc.bscv.modules.self.*; -import ftbsc.bscv.modules.hud.*; -import ftbsc.bscv.modules.defense.*; - @Mod("bscv") public class BoSCoVicino implements ICommons { public static String MOD_ID = "bscv"; @@ -52,24 +46,7 @@ public class BoSCoVicino implements ICommons { ForgeConfigSpec.Builder cfg = new ForgeConfigSpec.Builder(); CommandDispatcher dp = this.dispatcher; - this.modManager = new ModManager(cfg, dp); - - this.modManager.registerMod(new AutoDisconnect()); - this.modManager.registerMod(new ActiveModules()); - this.modManager.registerMod(new VanillaFlight()); - this.modManager.registerMod(new FastInteract()); - this.modManager.registerMod(new InfoDisplay()); - this.modManager.registerMod(new Coordinates()); - this.modManager.registerMod(new EntityList()); - this.modManager.registerMod(new PlayerList()); - this.modManager.registerMod(new Fullbright()); - this.modManager.registerMod(new AntiHunger()); - this.modManager.registerMod(new PortalGui()); - this.modManager.registerMod(new AutoFish()); - this.modManager.registerMod(new AutoTool()); - this.modManager.registerMod(new Freecam()); - this.modManager.registerMod(new BoatFly()); - this.modManager.registerMod(new Aura()); + BoSCoVicino.modManager = new ModManager(cfg, dp); BoSCoVicino.spec = cfg.build(); @@ -90,7 +67,7 @@ public class BoSCoVicino implements ICommons { private void clientSetup(final FMLClientSetupEvent event) { LOGGER.info("Initializing modules"); - for (IModule m : modManager.mods) { + for (IModule m : modManager.mods) { if (m.isEnabled()) m.enable(); } @@ -127,7 +104,7 @@ public class BoSCoVicino implements ICommons { dispatcher.register( Commands.literal("toggle-all") .executes(ctx -> { - for (IModule mod : modManager.mods) { + for (IModule mod : modManager.mods) { if (mod.isEnabled()) { mod.disable(); mod.enable(); diff --git a/src/main/java/ftbsc/bscv/api/IModule.java b/src/main/java/ftbsc/bscv/api/IModule.java index e075aa6..d295023 100644 --- a/src/main/java/ftbsc/bscv/api/IModule.java +++ b/src/main/java/ftbsc/bscv/api/IModule.java @@ -3,8 +3,8 @@ package ftbsc.bscv.api; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.MinecraftForge; -public interface IModule> extends ICommand { - T getGroup(); +public interface IModule extends ICommand { + String getGroup(); ForgeConfigSpec.Builder getConfigBuilder(); diff --git a/src/main/java/ftbsc/bscv/modules/AbstractModule.java b/src/main/java/ftbsc/bscv/modules/AbstractModule.java index 2239beb..dc785f9 100644 --- a/src/main/java/ftbsc/bscv/modules/AbstractModule.java +++ b/src/main/java/ftbsc/bscv/modules/AbstractModule.java @@ -5,7 +5,6 @@ import com.mojang.brigadier.arguments.BoolArgumentType; import ftbsc.bscv.BoSCoVicino; import ftbsc.bscv.api.IModule; -import ftbsc.bscv.system.ModManager; import net.minecraft.command.CommandSource; import net.minecraft.command.Commands; import net.minecraftforge.common.ForgeConfigSpec; @@ -13,16 +12,7 @@ import net.minecraftforge.common.MinecraftForge; import static ftbsc.bscv.BoSCoVicino.log; -public abstract class AbstractModule implements IModule { - public enum Group { - SELF, - HUD, - BUILD, - DEFENSE, - VISION, - MOTION, - } - +public abstract class AbstractModule implements IModule { protected ForgeConfigSpec.ConfigValue enabled; @Override @@ -31,9 +21,9 @@ public abstract class AbstractModule implements IModule { } @Override - public Group getGroup() { + public String getGroup() { String[] pkg = this.getClass().getPackage().getName().split("\\."); - return Group.valueOf(pkg[pkg.length - 1].toUpperCase()); + return pkg[pkg.length - 1].toUpperCase(); } @Override diff --git a/src/main/java/ftbsc/bscv/modules/HudModule.java b/src/main/java/ftbsc/bscv/modules/HudModule.java index 52cba0c..031995e 100644 --- a/src/main/java/ftbsc/bscv/modules/HudModule.java +++ b/src/main/java/ftbsc/bscv/modules/HudModule.java @@ -1,11 +1,8 @@ package ftbsc.bscv.modules; -import com.mojang.brigadier.CommandDispatcher; - import ftbsc.bscv.ICommons; import ftbsc.bscv.tools.Anchor; import ftbsc.bscv.tools.Setting; -import net.minecraft.command.CommandSource; import net.minecraftforge.common.ForgeConfigSpec; public abstract class HudModule extends AbstractModule { @@ -16,8 +13,8 @@ public abstract class HudModule extends AbstractModule { public final ForgeConfigSpec.ConfigValue anchor; @Override - public Group getGroup() { - return Group.HUD; + public String getGroup() { + return "HUD"; } protected HudModule() { diff --git a/src/main/java/ftbsc/bscv/modules/QuickModule.java b/src/main/java/ftbsc/bscv/modules/QuickModule.java index 5e06ea5..230d3ef 100644 --- a/src/main/java/ftbsc/bscv/modules/QuickModule.java +++ b/src/main/java/ftbsc/bscv/modules/QuickModule.java @@ -1,19 +1,18 @@ package ftbsc.bscv.modules; -import com.mojang.brigadier.CommandDispatcher; - import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.util.InputMappings; -import net.minecraft.command.CommandSource; import net.minecraftforge.client.event.InputEvent; -import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.client.registry.ClientRegistry; import ftbsc.bscv.BoSCoVicino; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; // TODO rename +@AutoService(ILoadable.class) public abstract class QuickModule extends AbstractModule { public static final int UNBOUND = InputMappings.UNKNOWN.getValue(); diff --git a/src/main/java/ftbsc/bscv/modules/defense/Aura.java b/src/main/java/ftbsc/bscv/modules/defense/Aura.java index d5838ae..7ffb2f5 100644 --- a/src/main/java/ftbsc/bscv/modules/defense/Aura.java +++ b/src/main/java/ftbsc/bscv/modules/defense/Aura.java @@ -9,7 +9,10 @@ import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent.Phase; import net.minecraftforge.eventbus.api.SubscribeEvent; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; +@AutoService(ILoadable.class) public class Aura extends QuickModule implements ICommons { @Override diff --git a/src/main/java/ftbsc/bscv/modules/hud/ActiveModules.java b/src/main/java/ftbsc/bscv/modules/hud/ActiveModules.java index 53a8f89..1893f53 100644 --- a/src/main/java/ftbsc/bscv/modules/hud/ActiveModules.java +++ b/src/main/java/ftbsc/bscv/modules/hud/ActiveModules.java @@ -9,14 +9,17 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.eventbus.api.SubscribeEvent; import static ftbsc.bscv.tools.Text.TextBuilder; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; +@AutoService(ILoadable.class) public class ActiveModules extends HudModule implements ICommons { @SubscribeEvent public void onRenderOverlay(RenderGameOverlayEvent event) { if (event.getType() == ElementType.TEXT) { int offset = 0; - for (IModule m : BoSCoVicino.modManager.mods) { - if (m.isEnabled() && m.getGroup() != Group.HUD) { + for (IModule m : BoSCoVicino.modManager.mods) { + if (m.isEnabled() && m.getGroup().equalsIgnoreCase("HUD")) { TextBuilder() .txt(String.format("%s <", m.getName())) .anchor(this.anchor.get()) diff --git a/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java b/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java index cac6170..44c8756 100644 --- a/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java +++ b/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java @@ -1,18 +1,19 @@ package ftbsc.bscv.modules.hud; -import com.mojang.brigadier.CommandDispatcher; - -import net.minecraft.command.CommandSource; import net.minecraft.util.math.vector.Vector3d; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; -import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.eventbus.api.SubscribeEvent; import static ftbsc.bscv.tools.Text.TextBuilder; + +import com.google.auto.service.AutoService; + import ftbsc.bscv.ICommons; import ftbsc.bscv.modules.HudModule; +import ftbsc.bscv.api.ILoadable; +@AutoService(ILoadable.class) public class Coordinates extends HudModule implements ICommons { @SubscribeEvent public void onRenderOverlay(RenderGameOverlayEvent event) { diff --git a/src/main/java/ftbsc/bscv/modules/hud/EntityList.java b/src/main/java/ftbsc/bscv/modules/hud/EntityList.java index 58e9c11..288f2a7 100644 --- a/src/main/java/ftbsc/bscv/modules/hud/EntityList.java +++ b/src/main/java/ftbsc/bscv/modules/hud/EntityList.java @@ -21,7 +21,10 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.eventbus.api.SubscribeEvent; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; +@AutoService(ILoadable.class) public class EntityList extends HudModule implements ICommons { public final ForgeConfigSpec.ConfigValue search; diff --git a/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java b/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java index 533bed4..f232c70 100644 --- a/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java +++ b/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java @@ -20,7 +20,10 @@ import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent.Phase; import net.minecraftforge.eventbus.api.SubscribeEvent; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; +@AutoService(ILoadable.class) public class InfoDisplay extends HudModule implements ICommons { private Vector3d last_position = new Vector3d(0.0, 0.0, 0.0); diff --git a/src/main/java/ftbsc/bscv/modules/hud/PlayerList.java b/src/main/java/ftbsc/bscv/modules/hud/PlayerList.java index 106531f..00839f9 100644 --- a/src/main/java/ftbsc/bscv/modules/hud/PlayerList.java +++ b/src/main/java/ftbsc/bscv/modules/hud/PlayerList.java @@ -13,7 +13,10 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.eventbus.api.SubscribeEvent; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; +@AutoService(ILoadable.class) public class PlayerList extends HudModule implements ICommons { @SubscribeEvent diff --git a/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java b/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java index f2fdb5d..c8f2c98 100644 --- a/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java +++ b/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java @@ -1,12 +1,12 @@ package ftbsc.bscv.modules.motion; -import com.mojang.brigadier.CommandDispatcher; +import com.google.auto.service.AutoService; import ftbsc.bscv.ICommons; +import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.events.BoatEvent; import ftbsc.bscv.modules.AbstractModule; import ftbsc.bscv.tools.Keyboard; import ftbsc.bscv.tools.Setting; -import net.minecraft.command.CommandSource; import net.minecraft.entity.Entity; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.common.ForgeConfigSpec; @@ -14,6 +14,7 @@ import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent.Phase; import net.minecraftforge.eventbus.api.SubscribeEvent; +@AutoService(ILoadable.class) public class BoatFly extends AbstractModule implements ICommons { public final ForgeConfigSpec.ConfigValue speed; diff --git a/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java b/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java index 47c00a7..1cc4c2c 100644 --- a/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java +++ b/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java @@ -14,7 +14,10 @@ import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent.Phase; import net.minecraftforge.eventbus.api.SubscribeEvent; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; +@AutoService(ILoadable.class) public class VanillaFlight extends QuickModule implements ICommons { @Override diff --git a/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java b/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java index 5bf4411..eb64ac5 100644 --- a/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java +++ b/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java @@ -9,7 +9,10 @@ import net.minecraft.network.play.client.CPlayerPacket; import net.minecraft.network.play.client.CEntityActionPacket.Action; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.eventbus.api.SubscribeEvent; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; +@AutoService(ILoadable.class) public class AntiHunger extends AbstractModule implements ICommons { public final ForgeConfigSpec.ConfigValue sprint; diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java b/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java index 6581546..636f946 100644 --- a/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java +++ b/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java @@ -12,7 +12,10 @@ import net.minecraft.network.play.server.SUpdateHealthPacket; import net.minecraft.util.text.StringTextComponent; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.eventbus.api.SubscribeEvent; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; +@AutoService(ILoadable.class) public class AutoDisconnect extends AbstractModule implements ICommons { public final ForgeConfigSpec.ConfigValue threshold; diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoFish.java b/src/main/java/ftbsc/bscv/modules/self/AutoFish.java index a312cee..eec5b16 100644 --- a/src/main/java/ftbsc/bscv/modules/self/AutoFish.java +++ b/src/main/java/ftbsc/bscv/modules/self/AutoFish.java @@ -10,7 +10,10 @@ import net.minecraft.util.Hand; import net.minecraft.util.SoundEvents; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.eventbus.api.SubscribeEvent; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; +@AutoService(ILoadable.class) public class AutoFish extends AbstractModule implements ICommons { public final ForgeConfigSpec.ConfigValue recast; diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoTool.java b/src/main/java/ftbsc/bscv/modules/self/AutoTool.java index 482ee8b..279002e 100644 --- a/src/main/java/ftbsc/bscv/modules/self/AutoTool.java +++ b/src/main/java/ftbsc/bscv/modules/self/AutoTool.java @@ -13,7 +13,10 @@ import net.minecraft.util.math.BlockRayTraceResult; import net.minecraftforge.client.event.InputEvent; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.eventbus.api.SubscribeEvent; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; +@AutoService(ILoadable.class) public class AutoTool extends AbstractModule implements ICommons { public final ForgeConfigSpec.ConfigValue limit; diff --git a/src/main/java/ftbsc/bscv/modules/self/FastInteract.java b/src/main/java/ftbsc/bscv/modules/self/FastInteract.java index 297e3c0..ce3ebba 100644 --- a/src/main/java/ftbsc/bscv/modules/self/FastInteract.java +++ b/src/main/java/ftbsc/bscv/modules/self/FastInteract.java @@ -13,7 +13,10 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import ftbsc.bscv.modules.QuickModule; import ftbsc.bscv.ICommons; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; +@AutoService(ILoadable.class) public class FastInteract extends QuickModule implements ICommons { @Override protected int getDefaultKey() { diff --git a/src/main/java/ftbsc/bscv/modules/self/Freecam.java b/src/main/java/ftbsc/bscv/modules/self/Freecam.java index bbc8382..0bdbd1e 100644 --- a/src/main/java/ftbsc/bscv/modules/self/Freecam.java +++ b/src/main/java/ftbsc/bscv/modules/self/Freecam.java @@ -17,7 +17,10 @@ import net.minecraft.world.GameType; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; +@AutoService(ILoadable.class) public class Freecam extends QuickModule implements ICommons { public final ForgeConfigSpec.ConfigValue log; diff --git a/src/main/java/ftbsc/bscv/modules/self/PortalGui.java b/src/main/java/ftbsc/bscv/modules/self/PortalGui.java index c900f97..5c035a2 100644 --- a/src/main/java/ftbsc/bscv/modules/self/PortalGui.java +++ b/src/main/java/ftbsc/bscv/modules/self/PortalGui.java @@ -4,7 +4,10 @@ import ftbsc.bscv.ICommons; import ftbsc.bscv.modules.AbstractModule; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; +@AutoService(ILoadable.class) public class PortalGui extends AbstractModule implements ICommons { @SubscribeEvent diff --git a/src/main/java/ftbsc/bscv/modules/vision/Fullbright.java b/src/main/java/ftbsc/bscv/modules/vision/Fullbright.java index 26d0fab..754414d 100644 --- a/src/main/java/ftbsc/bscv/modules/vision/Fullbright.java +++ b/src/main/java/ftbsc/bscv/modules/vision/Fullbright.java @@ -8,7 +8,10 @@ import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import java.awt.event.KeyEvent; +import ftbsc.bscv.api.ILoadable; +import com.google.auto.service.AutoService; +@AutoService(ILoadable.class) public class Fullbright extends QuickModule implements ICommons { @Override protected int getDefaultKey() { diff --git a/src/main/java/ftbsc/bscv/system/ModManager.java b/src/main/java/ftbsc/bscv/system/ModManager.java index d5ce124..b700d0a 100644 --- a/src/main/java/ftbsc/bscv/system/ModManager.java +++ b/src/main/java/ftbsc/bscv/system/ModManager.java @@ -1,37 +1,37 @@ package ftbsc.bscv.system; import com.mojang.brigadier.CommandDispatcher; -import ftbsc.bscv.BoSCoVicino; +import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.api.IModule; -import ftbsc.bscv.modules.AbstractModule; -import ftbsc.bscv.modules.defense.Aura; -import ftbsc.bscv.modules.hud.*; -import ftbsc.bscv.modules.motion.BoatFly; -import ftbsc.bscv.modules.motion.VanillaFlight; -import ftbsc.bscv.modules.self.*; -import ftbsc.bscv.modules.vision.Fullbright; 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 cfgBuilder; private Optional> dispatcher; - public final Set> > mods; + public final Set mods; + public final Set categories; public ModManager(ForgeConfigSpec.Builder cfgBuilder, CommandDispatcher dispatcher) { this.cfgBuilder = Optional.of(cfgBuilder); this.dispatcher = Optional.of(dispatcher); this.mods = new HashSet<>(); - } - - public void registerMod(IModule> mod) { - this.mods.add(mod); - this.cfgBuilder.get().pop(); // TODO solved by AutoService, soon TM + this.categories = new HashSet<>(); + + 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() { diff --git a/src/main/java/ftbsc/bscv/tools/Setting.java b/src/main/java/ftbsc/bscv/tools/Setting.java index 7db1449..19b719a 100644 --- a/src/main/java/ftbsc/bscv/tools/Setting.java +++ b/src/main/java/ftbsc/bscv/tools/Setting.java @@ -4,7 +4,6 @@ import static ftbsc.bscv.BoSCoVicino.log; import java.util.Optional; -import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.DoubleArgumentType; @@ -12,7 +11,6 @@ import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import ftbsc.bscv.api.IModule; -import net.minecraft.command.CommandSource; import net.minecraft.command.Commands; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.server.command.EnumArgument; @@ -51,7 +49,7 @@ public abstract class Setting { abstract Class clazz(); - public ForgeConfigSpec.ConfigValue build(IModule module) { + public ForgeConfigSpec.ConfigValue build(IModule module) { ForgeConfigSpec.ConfigValue conf = this.value(module.getConfigBuilder()); module.getDispatcher().register(