Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Module util methods #4730

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
}

Swarm swarm = Modules.get().get(Swarm.class);
if (!swarm.isActive()) swarm.toggle();
swarm.enable();

swarm.close();
swarm.mode.set(Swarm.Mode.Worker);
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public void build(LiteralArgumentBuilder<CommandSource> 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;
})
Expand All @@ -51,13 +49,13 @@ public void build(LiteralArgumentBuilder<CommandSource> 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;
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
AutoWasp wasp = Modules.get().get(AutoWasp.class);

builder.then(literal("reset").executes(context -> {
if (wasp.isActive()) wasp.toggle();
wasp.disable();
return SINGLE_SUCCESS;
}));

Expand All @@ -37,7 +37,7 @@ public void build(LiteralArgumentBuilder<CommandSource> 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;
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Setting<?> get(String name) {
return null;
}

public <T> Setting<T> add(Setting<T> setting) {
public <T extends Setting<?>> T add(T setting) {
settings.add(setting);

return setting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,16 @@ public static Category getCategoryByHash(int hash) {
}

@SuppressWarnings("unchecked")
@Nullable
public <T extends Module> T get(Class<T> klass) {
return (T) moduleInstances.get(klass);
}

public <T extends Module> Optional<T> getOptional(Class<T> klass) {
return Optional.ofNullable(get(klass));
}

@Nullable
public Module get(String name) {
for (Module module : moduleInstances.values()) {
if (module.name.equalsIgnoreCase(name)) return module;
Expand Down Expand Up @@ -164,9 +170,7 @@ public int getCount() {
}

public List<Module> getActive() {
synchronized (active) {
return active;
}
return active;
}

public Set<Module> searchTitles(String text) {
Expand Down Expand Up @@ -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();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public void play() {
}

public void pause() {
if (!isActive()) toggle();
enable();
if (isPlaying) {
info("Pausing.");
isPlaying = false;
Expand All @@ -636,7 +636,7 @@ public void pause() {

public void stop() {
info("Stopping.");
disable();
disableNotebot();
updateStatus();
}

Expand All @@ -660,9 +660,9 @@ public void playRandomSong() {
}
}

public void disable() {
public void disableNotebot() {
resetVariables();
if (!isActive()) toggle();
enable();
}

/**
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -829,7 +829,7 @@ private void tune() {

private void tuneBlocks() {
if (mc.world == null || mc.player == null) {
disable();
disableNotebot();
}

if (swingArm.get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -49,16 +49,16 @@ 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;
}

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Blink extends Module {
.defaultValue(Keybind.none())
.action(() -> {
cancelled = true;
if (isActive()) toggle();
disable();
})
.build()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -102,7 +102,7 @@ public class AutoEat extends Module {
public boolean eating;
private int slot, prevSlot;

private final List<Class<? extends Module>> wasAura = new ArrayList<>();
private final List<Class<? extends Module>> wasAura = new ReferenceArrayList<>();
private boolean wasBaritone = false;

public AutoEat() {
Expand Down Expand Up @@ -203,10 +203,8 @@ private void stopEating() {
// Resume auras
if (pauseAuras.get()) {
for (Class<? extends Module> 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();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -119,7 +119,7 @@ public class AutoGap extends Module {
private boolean eating;
private int slot, prevSlot;

private final List<Class<? extends Module>> wasAura = new ArrayList<>();
private final List<Class<? extends Module>> wasAura = new ReferenceArrayList<>();
private boolean wasBaritone;

public AutoGap() {
Expand Down Expand Up @@ -219,10 +219,8 @@ private void stopEating() {
// Resume auras
if (pauseAuras.get()) {
for (Class<? extends Module> 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();
}
}
}
Expand Down
Loading