diff --git a/src/main/java/cloudburst/rejects/MeteorRejectsAddon.java b/src/main/java/cloudburst/rejects/MeteorRejectsAddon.java index 8e55ba6..e04155c 100644 --- a/src/main/java/cloudburst/rejects/MeteorRejectsAddon.java +++ b/src/main/java/cloudburst/rejects/MeteorRejectsAddon.java @@ -51,6 +51,7 @@ public class MeteorRejectsAddon extends MeteorAddon { modules.add(new BlockIn()); modules.add(new BoatPhase()); modules.add(new Boost()); + modules.add(new ChatBot()); modules.add(new ColorSigns()); modules.add(new Confuse()); modules.add(new CoordLogger()); diff --git a/src/main/java/cloudburst/rejects/gui/themes/rounded/widgets/WMeteorModule.java b/src/main/java/cloudburst/rejects/gui/themes/rounded/widgets/WMeteorModule.java index 0328c01..98859d9 100644 --- a/src/main/java/cloudburst/rejects/gui/themes/rounded/widgets/WMeteorModule.java +++ b/src/main/java/cloudburst/rejects/gui/themes/rounded/widgets/WMeteorModule.java @@ -55,7 +55,7 @@ public class WMeteorModule extends WPressable implements MeteorWidget { @Override protected void onPressed(int button) { - if (button == GLFW_MOUSE_BUTTON_LEFT) module.toggle(Utils.canUpdate()); + if (button == GLFW_MOUSE_BUTTON_LEFT) module.toggle(); else if (button == GLFW_MOUSE_BUTTON_RIGHT) mc.setScreen(theme.moduleScreen(module)); } diff --git a/src/main/java/cloudburst/rejects/modules/ChatBot.java b/src/main/java/cloudburst/rejects/modules/ChatBot.java new file mode 100644 index 0000000..e71ef7c --- /dev/null +++ b/src/main/java/cloudburst/rejects/modules/ChatBot.java @@ -0,0 +1,157 @@ +package cloudburst.rejects.modules; + +import java.util.HashMap; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtString; +import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket; + +import cloudburst.rejects.MeteorRejectsAddon; +import meteordevelopment.meteorclient.events.game.ReceiveMessageEvent; +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.BoolSetting; +import meteordevelopment.meteorclient.settings.Setting; +import meteordevelopment.meteorclient.settings.SettingGroup; +import meteordevelopment.meteorclient.settings.StringSetting; +import meteordevelopment.meteorclient.systems.modules.Module; +import meteordevelopment.meteorclient.utils.misc.MeteorStarscript; +import meteordevelopment.orbit.EventHandler; +import meteordevelopment.starscript.Script; +import meteordevelopment.starscript.compiler.Compiler; +import meteordevelopment.starscript.compiler.Parser; +import meteordevelopment.starscript.utils.StarscriptError; + +public class ChatBot extends Module { + + public final HashMap commands = new HashMap<>() {{ + put("ping", "Pong!"); + put("tps", "Current TPS: {server.tps}"); + put("time", "It's currently {server.time}"); + put("time", "It's currently {server.time}"); + put("pos", "I am @ {player.pos}"); + }}; + + private final SettingGroup sgGeneral = settings.getDefaultGroup(); + + private final Setting prefix = sgGeneral.add(new StringSetting.Builder() + .name("prefix") + .description("Command prefix for the bot.") + .defaultValue("!") + .build() + ); + + private final Setting help = sgGeneral.add(new BoolSetting.Builder() + .name("help") + .description("Add help command.") + .defaultValue(true) + .build() + ); + + public ChatBot() { + super(MeteorRejectsAddon.CATEGORY, "chat-bot", "Bot which automatically responds to chat messages."); + } + + private String currMsgK = "", currMsgV = ""; + + @EventHandler + private void onMessageRecieve(ReceiveMessageEvent event) { + String msg = event.message.getString(); + if (help.get() && msg.endsWith(prefix.get()+"help")) { + mc.getNetworkHandler().sendPacket(new ChatMessageC2SPacket("Avaliable commands: " + String.join(", ", commands.keySet()))); + return; + } + for (String cmd : commands.keySet()) { + if (msg.endsWith(prefix.get()+cmd)) { + Script script = compile(commands.get(cmd)); + if (script == null) mc.player.sendChatMessage("An error occurred"); + try { + mc.player.sendChatMessage(MeteorStarscript.ss.run(script)); + } catch (StarscriptError e) { + MeteorStarscript.printChatError(e); + mc.player.sendChatMessage("An error occurred"); + } + return; + } + } + } + + @Override + public WWidget getWidget(GuiTheme theme) { + WTable table = theme.table(); + fillTable(theme, table); + return table; + } + + private void fillTable(GuiTheme theme, WTable table) { + table.clear(); + commands.keySet().forEach((key) -> { + table.add(theme.label(key)).expandCellX(); + table.add(theme.label(commands.get(key))).expandCellX(); + WMinus delete = table.add(theme.minus()).widget(); + delete.action = () -> { + commands.remove(key); + fillTable(theme,table); + }; + table.row(); + }); + WTextBox textBoxK = table.add(theme.textBox(currMsgK)).minWidth(100).expandX().widget(); + textBoxK.action = () -> { + currMsgK = textBoxK.get(); + }; + WTextBox textBoxV = table.add(theme.textBox(currMsgV)).minWidth(100).expandX().widget(); + textBoxV.action = () -> { + currMsgV = textBoxV.get(); + }; + WPlus add = table.add(theme.plus()).widget(); + add.action = () -> { + if (currMsgK != "" && currMsgV != "") { + commands.put(currMsgK, currMsgV); + currMsgK = ""; currMsgV = ""; + fillTable(theme,table); + } + }; + table.row(); + } + + @Override + public NbtCompound toTag() { + NbtCompound tag = super.toTag(); + + NbtCompound messTag = new NbtCompound(); + commands.keySet().forEach((key) -> { + messTag.put(key, NbtString.of(commands.get(key))); + }); + + tag.put("commands", messTag); + return tag; + } + + @Override + public Module fromTag(NbtCompound tag) { + + commands.clear(); + if (tag.contains("commands")) { + NbtCompound msgs = tag.getCompound("commands"); + msgs.getKeys().forEach((key) -> { + commands.put(key, msgs.getString(key)); + }); + } + + return super.fromTag(tag); + } + + private static Script compile(String script) { + if (script == null) return null; + Parser.Result result = Parser.parse(script); + if (result.hasErrors()) { + MeteorStarscript.printChatError(result.errors.get(0)); + return null; + } + return Compiler.compile(result); + } +} diff --git a/src/main/java/cloudburst/rejects/modules/InteractionMenu.java b/src/main/java/cloudburst/rejects/modules/InteractionMenu.java index 2459d22..7661a3b 100644 --- a/src/main/java/cloudburst/rejects/modules/InteractionMenu.java +++ b/src/main/java/cloudburst/rejects/modules/InteractionMenu.java @@ -145,6 +145,7 @@ public class InteractionMenu extends Module { @Override public Module fromTag(NbtCompound tag) { + messages.clear(); if (tag.contains("messages")) { NbtCompound msgs = tag.getCompound("messages"); msgs.getKeys().forEach((key) -> { diff --git a/src/main/java/cloudburst/rejects/modules/PacketFly.java b/src/main/java/cloudburst/rejects/modules/PacketFly.java index 518cf93..4ca5e1a 100644 --- a/src/main/java/cloudburst/rejects/modules/PacketFly.java +++ b/src/main/java/cloudburst/rejects/modules/PacketFly.java @@ -21,12 +21,12 @@ import java.util.Set; public class PacketFly extends Module { private final Set packets = new ConcurrentSet(); - private final SettingGroup sgMovement = settings.createGroup("Movement"); - private final SettingGroup sgClient = settings.createGroup("Client"); - private final SettingGroup sgBypass = settings.createGroup("Bypass"); + private final SettingGroup sgMovement = settings.createGroup("movement"); + private final SettingGroup sgClient = settings.createGroup("client"); + private final SettingGroup sgBypass = settings.createGroup("bypass"); private final Setting horizontalSpeed = sgMovement.add(new DoubleSetting.Builder() - .name("Horizontal Speed") + .name("horizontal-speed") .description("Horizontal speed in blocks per second.") .defaultValue(5.2) .min(0.0) @@ -37,7 +37,7 @@ public class PacketFly extends Module { ); private final Setting verticalSpeed = sgMovement.add(new DoubleSetting.Builder() - .name("Vertical Speed") + .name("vertical-speed") .description("Vertical speed in blocks per second.") .defaultValue(1.24) .min(0.0) @@ -48,49 +48,49 @@ public class PacketFly extends Module { ); private final Setting sendTeleport = sgMovement.add(new BoolSetting.Builder() - .name("Teleport") + .name("teleport") .description("Sends teleport packets.") .defaultValue(true) .build() ); private final Setting setYaw = sgClient.add(new BoolSetting.Builder() - .name("Set Yaw") + .name("set-yaw") .description("Sets yaw client side.") .defaultValue(true) .build() ); private final Setting setMove = sgClient.add(new BoolSetting.Builder() - .name("Set Move") + .name("set-move") .description("Sets movement client side.") .defaultValue(false) .build() ); private final Setting setPos = sgClient.add(new BoolSetting.Builder() - .name("Set Pos") + .name("set-pos") .description("Sets position client side.") .defaultValue(false) .build() ); private final Setting setID = sgClient.add(new BoolSetting.Builder() - .name("Set ID") + .name("set-id") .description("Updates teleport id when a position packet is received.") .defaultValue(false) .build() ); private final Setting antiKick = sgBypass.add(new BoolSetting.Builder() - .name("Anti Kick") + .name("anti-kick") .description("Moves down occasionally to prevent kicks.") .defaultValue(true) .build() ); private final Setting downDelay = sgBypass.add(new IntSetting.Builder() - .name("Down Delay") + .name("down-delay") .description("How often you move down when not flying upwards. (ticks)") .defaultValue(4) .sliderMin(1) @@ -101,7 +101,7 @@ public class PacketFly extends Module { ); private final Setting downDelayFlying = sgBypass.add(new IntSetting.Builder() - .name("Down Delay (Flying)") + .name("flying-down-delay") .description("How often you move down when flying upwards. (ticks)") .defaultValue(10) .sliderMin(1) @@ -112,7 +112,7 @@ public class PacketFly extends Module { ); private final Setting invalidPacket = sgBypass.add(new BoolSetting.Builder() - .name("Invalid Packet") + .name("invalid-packet") .description("Sends invalid movement packets.") .defaultValue(false) .build()