Skip to content

Commit b334135

Browse files
authored
Add new Module util methods (#4730)
1 parent a744772 commit b334135

13 files changed

Lines changed: 52 additions & 46 deletions

File tree

src/main/java/meteordevelopment/meteorclient/MeteorClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void onInitializeClient() {
9797
if (!FOLDER.exists()) {
9898
FOLDER.getParentFile().mkdirs();
9999
FOLDER.mkdir();
100-
Systems.addPreLoadTask(() -> Modules.get().get(DiscordPresence.class).toggle());
100+
Systems.addPreLoadTask(() -> Modules.get().get(DiscordPresence.class).enable());
101101
}
102102

103103
// Register addons

src/main/java/meteordevelopment/meteorclient/commands/commands/SwarmCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
8686
}
8787

8888
Swarm swarm = Modules.get().get(Swarm.class);
89-
if (!swarm.isActive()) swarm.toggle();
89+
swarm.enable();
9090

9191
swarm.close();
9292
swarm.mode.set(Swarm.Mode.Worker);
@@ -306,7 +306,7 @@ else if (swarm.isWorker()) {
306306
swarm.host.sendMessage(context.getInput());
307307
} else if (swarm.isWorker()) {
308308
Module m = ModuleArgumentType.get(context);
309-
if (!m.isActive()) m.toggle();
309+
m.enable();
310310
}
311311
} else {
312312
throw SWARM_NOT_ACTIVE.create();
@@ -320,7 +320,7 @@ else if (swarm.isWorker()) {
320320
swarm.host.sendMessage(context.getInput());
321321
} else if (swarm.isWorker()) {
322322
Module m = ModuleArgumentType.get(context);
323-
if (m.isActive()) m.toggle();
323+
m.disable();
324324
}
325325
} else {
326326
throw SWARM_NOT_ACTIVE.create();
@@ -388,9 +388,9 @@ else if (swarm.isWorker()) {
388388

389389
private void runInfinityMiner() {
390390
InfinityMiner infinityMiner = Modules.get().get(InfinityMiner.class);
391-
if (infinityMiner.isActive()) infinityMiner.toggle();
391+
infinityMiner.disable();
392392
// infinityMiner.smartModuleToggle.set(true);
393-
if (!infinityMiner.isActive()) infinityMiner.toggle();
393+
infinityMiner.enable();
394394
}
395395

396396
private void scatter(int radius) {

src/main/java/meteordevelopment/meteorclient/commands/commands/ToggleCommand.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
2626
.then(literal("all")
2727
.then(literal("on")
2828
.executes(context -> {
29-
new ArrayList<>(Modules.get().getAll()).forEach(module -> {
30-
if (!module.isActive()) module.toggle();
31-
});
29+
new ArrayList<>(Modules.get().getAll()).forEach(Module::enable);
3230
Hud.get().active = true;
3331
return SINGLE_SUCCESS;
3432
})
@@ -51,13 +49,13 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
5149
.then(literal("on")
5250
.executes(context -> {
5351
Module m = ModuleArgumentType.get(context);
54-
if (!m.isActive()) m.toggle();
52+
m.enable();
5553
return SINGLE_SUCCESS;
5654
}))
5755
.then(literal("off")
5856
.executes(context -> {
5957
Module m = ModuleArgumentType.get(context);
60-
if (m.isActive()) m.toggle();
58+
m.disable();
6159
return SINGLE_SUCCESS;
6260
})
6361
)

src/main/java/meteordevelopment/meteorclient/commands/commands/WaspCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
2727
AutoWasp wasp = Modules.get().get(AutoWasp.class);
2828

2929
builder.then(literal("reset").executes(context -> {
30-
if (wasp.isActive()) wasp.toggle();
30+
wasp.disable();
3131
return SINGLE_SUCCESS;
3232
}));
3333

@@ -37,7 +37,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
3737
if (player == mc.player) throw CANT_WASP_SELF.create();
3838

3939
wasp.target = player;
40-
if (!wasp.isActive()) wasp.toggle();
40+
wasp.enable();
4141
info(player.getName().getString() + " set as target.");
4242
return SINGLE_SUCCESS;
4343
}));

src/main/java/meteordevelopment/meteorclient/settings/SettingGroup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Setting<?> get(String name) {
3434
return null;
3535
}
3636

37-
public <T> Setting<T> add(Setting<T> setting) {
37+
public <T extends Setting<?>> T add(T setting) {
3838
settings.add(setting);
3939

4040
return setting;

src/main/java/meteordevelopment/meteorclient/systems/modules/Module.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ public void toggle() {
106106
}
107107
}
108108

109+
public void enable() {
110+
if (!isActive()) toggle();
111+
}
112+
113+
public void disable() {
114+
if (isActive()) toggle();
115+
}
116+
109117
public void sendToggledMsg() {
110118
if (Config.get().chatFeedback.get() && chatFeedback) {
111119
ChatUtils.forceNextPrefixClass(getClass());

src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import net.minecraft.nbt.NbtCompound;
4343
import net.minecraft.nbt.NbtElement;
4444
import net.minecraft.nbt.NbtList;
45+
import org.jetbrains.annotations.Nullable;
4546
import org.lwjgl.glfw.GLFW;
4647

4748
import java.io.File;
@@ -106,10 +107,17 @@ public static Iterable<Category> loopCategories() {
106107
}
107108

108109
@SuppressWarnings("unchecked")
110+
@Nullable
109111
public <T extends Module> T get(Class<T> klass) {
110112
return (T) moduleInstances.get(klass);
111113
}
112114

115+
@SuppressWarnings("unused")
116+
public <T extends Module> Optional<T> getOptional(Class<T> klass) {
117+
return Optional.ofNullable(get(klass));
118+
}
119+
120+
@Nullable
113121
public Module get(String name) {
114122
for (Module module : moduleInstances.values()) {
115123
if (module.name.equalsIgnoreCase(name)) return module;
@@ -137,9 +145,7 @@ public int getCount() {
137145
}
138146

139147
public List<Module> getActive() {
140-
synchronized (active) {
141-
return active;
142-
}
148+
return active;
143149
}
144150

145151
public Set<Module> searchTitles(String text) {
@@ -311,7 +317,7 @@ private void onGameLeft(GameLeftEvent event) {
311317
public void disableAll() {
312318
synchronized (active) {
313319
for (Module module : getAll()) {
314-
if (module.isActive()) module.toggle();
320+
module.disable();
315321
}
316322
}
317323
}

src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Surround.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,7 @@ public void onActivate() {
297297
public void onDeactivate() {
298298
if (toggleBack.get() && !toActivate.isEmpty() && mc.world != null && mc.player != null) {
299299
for (Module module : toActivate) {
300-
if (!module.isActive()) {
301-
module.toggle();
302-
}
300+
module.enable();
303301
}
304302
}
305303
}

src/main/java/meteordevelopment/meteorclient/systems/modules/misc/Notebot.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ public void play() {
626626
}
627627

628628
public void pause() {
629-
if (!isActive()) toggle();
629+
enable();
630630
if (isPlaying) {
631631
info("Pausing.");
632632
isPlaying = false;
@@ -638,7 +638,7 @@ public void pause() {
638638

639639
public void stop() {
640640
info("Stopping.");
641-
disable();
641+
disableNotebot();
642642
updateStatus();
643643
}
644644

@@ -662,9 +662,9 @@ public void playRandomSong() {
662662
}
663663
}
664664

665-
public void disable() {
665+
public void disableNotebot() {
666666
resetVariables();
667-
if (!isActive()) toggle();
667+
enable();
668668
}
669669

670670
/**
@@ -673,7 +673,7 @@ public void disable() {
673673
* @param file Song supported by one of {@link SongDecoder}
674674
*/
675675
public void loadSong(File file) {
676-
if (!isActive()) toggle();
676+
enable();
677677
resetVariables();
678678

679679
this.playingMode = PlayingMode.Noteblocks;
@@ -690,7 +690,7 @@ public void loadSong(File file) {
690690
* @param file Song supported by one of {@link SongDecoder}
691691
*/
692692
public void previewSong(File file) {
693-
if (!isActive()) toggle();
693+
enable();
694694
resetVariables();
695695

696696
this.playingMode = PlayingMode.Preview;
@@ -831,7 +831,7 @@ private void tune() {
831831

832832
private void tuneBlocks() {
833833
if (mc.world == null || mc.player == null) {
834-
disable();
834+
disableNotebot();
835835
}
836836

837837
if (swingArm.get()) {

src/main/java/meteordevelopment/meteorclient/systems/modules/movement/AntiVoid.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public void onActivate() {
3939

4040
@Override
4141
public void onDeactivate() {
42-
if (!wasFlightEnabled && mode.get() == Mode.Flight && Utils.canUpdate() && Modules.get().isActive(Flight.class)) {
43-
Modules.get().get(Flight.class).toggle();
42+
if (!wasFlightEnabled && mode.get() == Mode.Flight && Utils.canUpdate()) {
43+
Modules.get().get(Flight.class).disable();
4444
}
4545
}
4646

@@ -49,16 +49,16 @@ private void onPreTick(TickEvent.Pre event) {
4949
int minY = mc.world.getBottomY();
5050

5151
if (mc.player.getY() > minY || mc.player.getY() < minY - 15) {
52-
if (hasRun && mode.get() == Mode.Flight && Modules.get().isActive(Flight.class)) {
53-
Modules.get().get(Flight.class).toggle();
52+
if (hasRun && mode.get() == Mode.Flight) {
53+
Modules.get().get(Flight.class).disable();
5454
hasRun = false;
5555
}
5656
return;
5757
}
5858

5959
switch (mode.get()) {
6060
case Flight -> {
61-
if (!Modules.get().isActive(Flight.class)) Modules.get().get(Flight.class).toggle();
61+
Modules.get().get(Flight.class).enable();
6262
hasRun = true;
6363
}
6464
case Jump -> mc.player.jump();

0 commit comments

Comments
 (0)