diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/SwarmCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/SwarmCommand.java index 1a174501b5..22fa1aecb2 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/SwarmCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/SwarmCommand.java @@ -87,7 +87,7 @@ public void build(LiteralArgumentBuilder builder) { } Swarm swarm = Modules.get().get(Swarm.class); - if (!swarm.isActive()) swarm.toggle(); + swarm.enable(); swarm.close(); swarm.mode.set(Swarm.Mode.Worker); @@ -307,7 +307,7 @@ else if (swarm.isWorker()) { swarm.host.sendMessage(context.getInput()); } else if (swarm.isWorker()) { Module m = ModuleArgumentType.get(context); - if (!m.isActive()) m.toggle(); + m.enable(); } } else { throw SWARM_NOT_ACTIVE.create(); @@ -321,7 +321,7 @@ else if (swarm.isWorker()) { swarm.host.sendMessage(context.getInput()); } else if (swarm.isWorker()) { Module m = ModuleArgumentType.get(context); - if (m.isActive()) m.toggle(); + m.disable(); } } else { throw SWARM_NOT_ACTIVE.create(); @@ -389,9 +389,9 @@ else if (swarm.isWorker()) { private void runInfinityMiner() { InfinityMiner infinityMiner = Modules.get().get(InfinityMiner.class); - if (infinityMiner.isActive()) infinityMiner.toggle(); + infinityMiner.disable(); // infinityMiner.smartModuleToggle.set(true); - if (!infinityMiner.isActive()) infinityMiner.toggle(); + infinityMiner.enable(); } private void scatter(int radius) { diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/ToggleCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/ToggleCommand.java index 0f58000c0d..c7fdbdd5e6 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/ToggleCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/ToggleCommand.java @@ -26,9 +26,7 @@ public void build(LiteralArgumentBuilder builder) { .then(literal("all") .then(literal("on") .executes(context -> { - new ArrayList<>(Modules.get().getAll()).forEach(module -> { - if (!module.isActive()) module.toggle(); - }); + new ArrayList<>(Modules.get().getAll()).forEach(Module::enable); Hud.get().active = true; return SINGLE_SUCCESS; }) @@ -51,13 +49,13 @@ public void build(LiteralArgumentBuilder builder) { .then(literal("on") .executes(context -> { Module m = ModuleArgumentType.get(context); - if (!m.isActive()) m.toggle(); + m.enable(); return SINGLE_SUCCESS; })) .then(literal("off") .executes(context -> { Module m = ModuleArgumentType.get(context); - if (m.isActive()) m.toggle(); + m.disable(); return SINGLE_SUCCESS; }) ) diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/WaspCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/WaspCommand.java index 1b3fb81e6a..fe9ce8a74a 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/WaspCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/WaspCommand.java @@ -27,7 +27,7 @@ public void build(LiteralArgumentBuilder builder) { AutoWasp wasp = Modules.get().get(AutoWasp.class); builder.then(literal("reset").executes(context -> { - if (wasp.isActive()) wasp.toggle(); + wasp.disable(); return SINGLE_SUCCESS; })); @@ -37,7 +37,7 @@ public void build(LiteralArgumentBuilder builder) { if (player == mc.player) throw CANT_WASP_SELF.create(); wasp.target = player; - if (!wasp.isActive()) wasp.toggle(); + wasp.enable(); info(player.getName().getString() + " set as target."); return SINGLE_SUCCESS; })); diff --git a/src/main/java/meteordevelopment/meteorclient/settings/SettingGroup.java b/src/main/java/meteordevelopment/meteorclient/settings/SettingGroup.java index 073db9d7e6..ab5820d962 100644 --- a/src/main/java/meteordevelopment/meteorclient/settings/SettingGroup.java +++ b/src/main/java/meteordevelopment/meteorclient/settings/SettingGroup.java @@ -34,7 +34,7 @@ public Setting get(String name) { return null; } - public Setting add(Setting setting) { + public > T add(T setting) { settings.add(setting); return setting; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/Module.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/Module.java index 2b20b44d57..de34ac7466 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/Module.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/Module.java @@ -85,6 +85,14 @@ public void toggle() { } } + public void enable() { + if (!isActive()) toggle(); + } + + public void disable() { + if (isActive()) toggle(); + } + public void sendToggledMsg() { if (Config.get().chatFeedback.get() && chatFeedback) { ChatUtils.forceNextPrefixClass(getClass()); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java index c1edf461a6..39294a7186 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java @@ -130,10 +130,16 @@ public static Category getCategoryByHash(int hash) { } @SuppressWarnings("unchecked") + @Nullable public T get(Class klass) { return (T) moduleInstances.get(klass); } + public Optional getOptional(Class klass) { + return Optional.ofNullable(get(klass)); + } + + @Nullable public Module get(String name) { for (Module module : moduleInstances.values()) { if (module.name.equalsIgnoreCase(name)) return module; @@ -164,9 +170,7 @@ public int getCount() { } public List getActive() { - synchronized (active) { - return active; - } + return active; } public Set searchTitles(String text) { @@ -332,7 +336,7 @@ private void onGameLeft(GameLeftEvent event) { public void disableAll() { synchronized (active) { for (Module module : modules) { - if (module.isActive()) module.toggle(); + module.disable(); } } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Surround.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Surround.java index 84e8310273..1f86dc3eeb 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Surround.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Surround.java @@ -282,9 +282,7 @@ public void onActivate() { public void onDeactivate() { if (toggleBack.get() && !toActivate.isEmpty() && mc.world != null && mc.player != null) { for (Module module : toActivate) { - if (!module.isActive()) { - module.toggle(); - } + module.enable(); } } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/Notebot.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/Notebot.java index 0544a13ed3..460481a0bd 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/Notebot.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/Notebot.java @@ -624,7 +624,7 @@ public void play() { } public void pause() { - if (!isActive()) toggle(); + enable(); if (isPlaying) { info("Pausing."); isPlaying = false; @@ -636,7 +636,7 @@ public void pause() { public void stop() { info("Stopping."); - disable(); + disableNotebot(); updateStatus(); } @@ -660,9 +660,9 @@ public void playRandomSong() { } } - public void disable() { + public void disableNotebot() { resetVariables(); - if (!isActive()) toggle(); + enable(); } /** @@ -671,7 +671,7 @@ public void disable() { * @param file Song supported by one of {@link SongDecoder} */ public void loadSong(File file) { - if (!isActive()) toggle(); + enable(); resetVariables(); this.playingMode = PlayingMode.Noteblocks; @@ -688,7 +688,7 @@ public void loadSong(File file) { * @param file Song supported by one of {@link SongDecoder} */ public void previewSong(File file) { - if (!isActive()) toggle(); + enable(); resetVariables(); this.playingMode = PlayingMode.Preview; @@ -829,7 +829,7 @@ private void tune() { private void tuneBlocks() { if (mc.world == null || mc.player == null) { - disable(); + disableNotebot(); } if (swingArm.get()) { diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/AntiVoid.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/AntiVoid.java index aa1cf9b86e..6a697bdb25 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/AntiVoid.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/AntiVoid.java @@ -39,8 +39,8 @@ public void onActivate() { @Override public void onDeactivate() { - if (!wasFlightEnabled && mode.get() == Mode.Flight && Utils.canUpdate() && Modules.get().isActive(Flight.class)) { - Modules.get().get(Flight.class).toggle(); + if (!wasFlightEnabled && mode.get() == Mode.Flight && Utils.canUpdate()) { + Modules.get().get(Flight.class).disable(); } } @@ -49,8 +49,8 @@ private void onPreTick(TickEvent.Pre event) { int minY = mc.world.getBottomY(); if (mc.player.getY() > minY || mc.player.getY() < minY - 15) { - if (hasRun && mode.get() == Mode.Flight && Modules.get().isActive(Flight.class)) { - Modules.get().get(Flight.class).toggle(); + if (hasRun && mode.get() == Mode.Flight) { + Modules.get().get(Flight.class).disable(); hasRun = false; } return; @@ -58,7 +58,7 @@ private void onPreTick(TickEvent.Pre event) { switch (mode.get()) { case Flight -> { - if (!Modules.get().isActive(Flight.class)) Modules.get().get(Flight.class).toggle(); + Modules.get().get(Flight.class).enable(); hasRun = true; } case Jump -> mc.player.jump(); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Blink.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Blink.java index c23b5f6a7f..548744d476 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Blink.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Blink.java @@ -40,7 +40,7 @@ public class Blink extends Module { .defaultValue(Keybind.none()) .action(() -> { cancelled = true; - if (isActive()) toggle(); + disable(); }) .build() ); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java index d41edba613..4c1bc21db1 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java @@ -5,6 +5,7 @@ package meteordevelopment.meteorclient.systems.modules.player; +import it.unimi.dsi.fastutil.objects.ReferenceArrayList; import meteordevelopment.meteorclient.events.entity.player.ItemUseCrosshairTargetEvent; import meteordevelopment.meteorclient.events.world.TickEvent; import meteordevelopment.meteorclient.pathing.PathManagers; @@ -26,7 +27,6 @@ import net.minecraft.item.Item; import net.minecraft.item.Items; -import java.util.ArrayList; import java.util.List; import java.util.function.BiPredicate; @@ -102,7 +102,7 @@ public class AutoEat extends Module { public boolean eating; private int slot, prevSlot; - private final List> wasAura = new ArrayList<>(); + private final List> wasAura = new ReferenceArrayList<>(); private boolean wasBaritone = false; public AutoEat() { @@ -203,10 +203,8 @@ private void stopEating() { // Resume auras if (pauseAuras.get()) { for (Class klass : AURAS) { - Module module = Modules.get().get(klass); - - if (wasAura.contains(klass) && !module.isActive()) { - module.toggle(); + if (wasAura.contains(klass)) { + Modules.get().get(klass).enable(); } } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoGap.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoGap.java index 053e933072..34e085ef6e 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoGap.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoGap.java @@ -5,6 +5,7 @@ package meteordevelopment.meteorclient.systems.modules.player; +import it.unimi.dsi.fastutil.objects.ReferenceArrayList; import meteordevelopment.meteorclient.events.entity.player.ItemUseCrosshairTargetEvent; import meteordevelopment.meteorclient.events.world.TickEvent; import meteordevelopment.meteorclient.pathing.PathManagers; @@ -30,7 +31,6 @@ import net.minecraft.item.Items; import net.minecraft.registry.entry.RegistryEntry; -import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -119,7 +119,7 @@ public class AutoGap extends Module { private boolean eating; private int slot, prevSlot; - private final List> wasAura = new ArrayList<>(); + private final List> wasAura = new ReferenceArrayList<>(); private boolean wasBaritone; public AutoGap() { @@ -219,10 +219,8 @@ private void stopEating() { // Resume auras if (pauseAuras.get()) { for (Class klass : AURAS) { - Module module = Modules.get().get(klass); - - if (wasAura.contains(klass) && !module.isActive()) { - module.toggle(); + if (wasAura.contains(klass)) { + Modules.get().get(klass).enable(); } } }