diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/AntiAFK.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/AntiAFK.java index 1ab24dfebe..49a4c6200b 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/AntiAFK.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/AntiAFK.java @@ -6,12 +6,6 @@ package meteordevelopment.meteorclient.systems.modules.movement; import meteordevelopment.meteorclient.events.world.TickEvent; -import meteordevelopment.meteorclient.gui.GuiTheme; -import meteordevelopment.meteorclient.gui.widgets.WWidget; -import meteordevelopment.meteorclient.gui.widgets.containers.WTable; -import meteordevelopment.meteorclient.gui.widgets.input.WTextBox; -import meteordevelopment.meteorclient.gui.widgets.pressable.WMinus; -import meteordevelopment.meteorclient.gui.widgets.pressable.WPlus; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; @@ -19,83 +13,50 @@ import meteordevelopment.meteorclient.utils.player.ChatUtils; import meteordevelopment.meteorclient.utils.player.Rotations; import meteordevelopment.orbit.EventHandler; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtElement; -import net.minecraft.nbt.NbtList; -import net.minecraft.nbt.NbtString; -import java.util.ArrayList; import java.util.List; import java.util.Random; public class AntiAFK extends Module { - public enum SpinMode { - Server, - Client - } - private final SettingGroup sgActions = settings.createGroup("Actions"); private final SettingGroup sgMessages = settings.createGroup("Messages"); // Actions - private final Setting spin = sgActions.add(new BoolSetting.Builder() - .name("spin") - .description("Spins.") - .defaultValue(true) - .build() - ); - - private final Setting spinMode = sgActions.add(new EnumSetting.Builder() - .name("spin-mode") - .description("The method of rotating.") - .defaultValue(SpinMode.Server) - .visible(spin::get) - .build() - ); - - private final Setting spinSpeed = sgActions.add(new IntSetting.Builder() - .name("spin-speed") - .description("The speed to spin you.") - .defaultValue(7) - .visible(spin::get) - .build() - ); - - private final Setting pitch = sgActions.add(new DoubleSetting.Builder() - .name("pitch") - .description("The pitch to set in server mode.") - .defaultValue(-90) - .range(-90, 90) - .sliderRange(-90, 90) - .visible(() -> spin.get() && spinMode.get() == SpinMode.Server) - .build() - ); - private final Setting jump = sgActions.add(new BoolSetting.Builder() .name("jump") - .description("Jumps.") + .description("Jump randomly.") .defaultValue(true) .build() ); - private final Setting click = sgActions.add(new BoolSetting.Builder() - .name("click") - .description("Clicks.") + private final Setting swing = sgActions.add(new BoolSetting.Builder() + .name("swing") + .description("Swings your hand.") .defaultValue(false) .build() ); - private final Setting disco = sgActions.add(new BoolSetting.Builder() - .name("disco") + private final Setting sneak = sgActions.add(new BoolSetting.Builder() + .name("sneak") .description("Sneaks and unsneaks quickly.") .defaultValue(false) .build() ); + private final Setting sneakTime = sgActions.add(new IntSetting.Builder() + .name("sneak-time") + .description("How many ticks to stay sneaked.") + .defaultValue(5) + .min(1) + .sliderMin(1) + .visible(sneak::get) + .build() + ); + private final Setting strafe = sgActions.add(new BoolSetting.Builder() .name("strafe") - .description("Strafe right and left") + .description("Strafe right and left.") .defaultValue(false) .onChanged(aBoolean -> { strafeTimer = 0; @@ -109,6 +70,40 @@ public enum SpinMode { .build() ); + private final Setting spin = sgActions.add(new BoolSetting.Builder() + .name("spin") + .description("Spins the player in place.") + .defaultValue(true) + .build() + ); + + private final Setting spinMode = sgActions.add(new EnumSetting.Builder() + .name("spin-mode") + .description("The method of rotating.") + .defaultValue(SpinMode.Server) + .visible(spin::get) + .build() + ); + + private final Setting spinSpeed = sgActions.add(new IntSetting.Builder() + .name("speed") + .description("The speed to spin you.") + .defaultValue(7) + .visible(spin::get) + .build() + ); + + private final Setting pitch = sgActions.add(new IntSetting.Builder() + .name("pitch") + .description("The pitch to send to the server.") + .defaultValue(0) + .range(-90, 90) + .sliderRange(-90, 90) + .visible(() -> spin.get() && spinMode.get() == SpinMode.Server) + .build() + ); + + // Messages private final Setting sendMessages = sgMessages.add(new BoolSetting.Builder() @@ -118,40 +113,56 @@ public enum SpinMode { .build() ); + private final Setting randomMessage = sgMessages.add(new BoolSetting.Builder() + .name("random") + .description("Selects a random message from your message list.") + .defaultValue(false) + .visible(sendMessages::get) + .build() + ); + private final Setting delay = sgMessages.add(new IntSetting.Builder() .name("delay") .description("The delay between specified messages in seconds.") - .defaultValue(2) + .defaultValue(15) .min(0) - .sliderMax(20) + .sliderMax(30) + .visible(sendMessages::get) .build() ); - private final Setting randomMessage = sgMessages.add(new BoolSetting.Builder() - .name("random") - .description("Selects a random message from your message list.") - .defaultValue(false) + private final Setting> messages = sgMessages.add(new StringListSetting.Builder() + .name("messages") + .description("The messages to choose from.") + .defaultValue( + "Meteor on top!", + "Meteor on crack!" + ) + .visible(sendMessages::get) .build() ); - private final List messages = new ArrayList<>(); - private int timer; - private int messageI; - private int strafeTimer = 0; - private boolean direction = false; + public AntiAFK() { + super(Categories.Player, "anti-afk", "Performs different actions to prevent getting kicked while AFK."); + } private final Random random = new Random(); - + private int messageTimer = 0; + private int messageI = 0; + private int sneakTimer = 0; + private int strafeTimer = 0; + private boolean direction = false; private float prevYaw; - public AntiAFK() { - super(Categories.Player, "anti-afk", "Performs different actions to prevent getting kicked for AFK reasons."); - } - @Override public void onActivate() { + if (sendMessages.get() && messages.get().isEmpty()) { + warning("Message list is empty, disabling messages..."); + sendMessages.set(false); + } + prevYaw = mc.player.getYaw(); - timer = delay.get() * 20; + messageTimer = delay.get() * 20; } @Override @@ -164,127 +175,56 @@ public void onDeactivate() { @EventHandler private void onTick(TickEvent.Pre event) { - if (Utils.canUpdate()) { - //Spin - if (spin.get()) { - prevYaw += spinSpeed.get(); - switch (spinMode.get()) { - case Client -> mc.player.setYaw(prevYaw); - case Server -> Rotations.rotate(prevYaw, pitch.get(), -15, null); - } - } - - //Jump - if (jump.get() && mc.options.jumpKey.isPressed()) mc.options.jumpKey.setPressed(false); - if (jump.get() && mc.options.sneakKey.isPressed()) mc.options.sneakKey.setPressed(false); - else if (jump.get() && random.nextInt(99) + 1 == 50) mc.options.jumpKey.setPressed(true); - - //Click - if (click.get() && random.nextInt(99) + 1 == 45) { - mc.options.attackKey.setPressed(true); - Utils.leftClick(); - mc.options.attackKey.setPressed(false); - } + if (!Utils.canUpdate()) return; - //Disco - if (disco.get() && random.nextInt(24) + 1 == 15) mc.options.sneakKey.setPressed(true); - - //Spam - if (sendMessages.get() && !messages.isEmpty()) - if (timer <= 0) { - int i; - if (randomMessage.get()) { - i = Utils.random(0, messages.size()); - } else { - if (messageI >= messages.size()) messageI = 0; - i = messageI++; - } - - ChatUtils.sendPlayerMsg(messages.get(i)); - - timer = delay.get() * 20; - } else { - timer--; - } - - //Strafe - if (strafe.get() && strafeTimer == 20) { - mc.options.leftKey.setPressed(!direction); - mc.options.rightKey.setPressed(direction); - direction = !direction; - strafeTimer = 0; - } else - strafeTimer++; + // Jump + if (jump.get()) { + if (mc.options.jumpKey.isPressed()) mc.options.jumpKey.setPressed(false); + else if (random.nextInt(99) == 0) mc.options.jumpKey.setPressed(true); } - } - @Override - public WWidget getWidget(GuiTheme theme) { - messages.removeIf(String::isEmpty); + // Swing + if (swing.get() && random.nextInt(99) == 0) { + mc.player.swingHand(mc.player.getActiveHand()); + } - WTable table = theme.table(); - fillTable(theme, table); + // Sneak + if (sneak.get()) { + if (sneakTimer++ >= sneakTime.get()) { + mc.options.sneakKey.setPressed(false); + if (random.nextInt(99) == 0) sneakTimer = 0; // Sneak after ~5 seconds + } else mc.options.sneakKey.setPressed(true); + } - return table; - } + // Strafe + if (strafe.get() && strafeTimer-- <= 0) { + mc.options.leftKey.setPressed(!direction); + mc.options.rightKey.setPressed(direction); + direction = !direction; + strafeTimer = 20; + } - private void fillTable(GuiTheme theme, WTable table) { - table.add(theme.horizontalSeparator("Message List")).expandX(); - table.row(); + // Spin + if (spin.get()) { + prevYaw += spinSpeed.get(); + switch (spinMode.get()) { + case Client -> mc.player.setYaw(prevYaw); + case Server -> Rotations.rotate(prevYaw, pitch.get(), -15); + } + } // Messages - for (int i = 0; i < messages.size(); i++) { - int msgI = i; - String message = messages.get(i); - - WTextBox textBox = table.add(theme.textBox(message)).minWidth(100).expandX().widget(); - textBox.action = () -> messages.set(msgI, textBox.get()); - - WMinus delete = table.add(theme.minus()).widget(); - delete.action = () -> { - messages.remove(msgI); - - table.clear(); - fillTable(theme, table); - }; + if (sendMessages.get() && !messages.get().isEmpty() && messageTimer-- <= 0) { + if (randomMessage.get()) messageI = random.nextInt(messages.get().size()); + else if (++messageI >= messages.get().size()) messageI = 0; - table.row(); + ChatUtils.sendPlayerMsg(messages.get().get(messageI)); + messageTimer = delay.get() * 20; } - - // New Message - WPlus add = table.add(theme.plus()).expandCellX().right().widget(); - add.action = () -> { - messages.add(""); - - table.clear(); - fillTable(theme, table); - }; - } - - @Override - public NbtCompound toTag() { - NbtCompound tag = super.toTag(); - - messages.removeIf(String::isEmpty); - NbtList messagesTag = new NbtList(); - - for (String message : messages) messagesTag.add(NbtString.of(message)); - tag.put("messages", messagesTag); - - return tag; } - @Override - public Module fromTag(NbtCompound tag) { - messages.clear(); - - if (tag.contains("messages")) { - NbtList messagesTag = tag.getList("messages", 8); - for (NbtElement messageTag : messagesTag) messages.add(messageTag.asString()); - } else { - messages.add("This is an AntiAFK message. Meteor on Crack!"); - } - - return super.fromTag(tag); + public enum SpinMode { + Server, + Client } }