|
| 1 | +package com.nxyi.addon.modules; |
| 2 | + |
| 3 | +import com.google.common.base.Splitter; |
| 4 | +import com.nxyi.addon.Addon; |
| 5 | +import com.nxyi.addon.Utils.InvUtils; |
| 6 | +import meteordevelopment.meteorclient.events.game.SendMessageEvent; |
| 7 | +import meteordevelopment.meteorclient.events.world.TickEvent; |
| 8 | +import meteordevelopment.meteorclient.settings.BoolSetting; |
| 9 | +import meteordevelopment.meteorclient.settings.Setting; |
| 10 | +import meteordevelopment.meteorclient.settings.SettingGroup; |
| 11 | +import meteordevelopment.meteorclient.settings.StringSetting; |
| 12 | +import meteordevelopment.meteorclient.systems.modules.Module; |
| 13 | +import meteordevelopment.orbit.EventHandler; |
| 14 | +import net.minecraft.entity.player.PlayerEntity; |
| 15 | +import net.minecraft.item.Items; |
| 16 | +import net.minecraft.nbt.NbtCompound; |
| 17 | +import net.minecraft.nbt.NbtElement; |
| 18 | +import net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket; |
| 19 | +import net.minecraft.screen.slot.SlotActionType; |
| 20 | +import net.minecraft.util.Hand; |
| 21 | + |
| 22 | +import java.lang.reflect.Array; |
| 23 | +import java.util.*; |
| 24 | + |
| 25 | +public class Bookchat extends Module { |
| 26 | + |
| 27 | + public Bookchat() { |
| 28 | + super(Addon.CATEGORY, "Bookchat", "Secretly chat using books"); |
| 29 | + } |
| 30 | + |
| 31 | + public String lasttext = null; |
| 32 | + private final SettingGroup sgGeneral = this.settings.getDefaultGroup(); |
| 33 | + private final Setting<String> person = sgGeneral.add(new StringSetting.Builder().name("Person").description("Person your chatting with").defaultValue("").build()); |
| 34 | + |
| 35 | + private final Setting<Boolean> autobook = sgGeneral.add(new BoolSetting.Builder() |
| 36 | + .name("autoswitchbook") |
| 37 | + .description("Automatically hold the book on chat if not in hand") |
| 38 | + .defaultValue(true) |
| 39 | + .build() |
| 40 | + ); |
| 41 | + |
| 42 | + @EventHandler |
| 43 | + private void onchat(SendMessageEvent event){ |
| 44 | + String msg = mc.player.getEntityName() + " : " + event.message; |
| 45 | + event.cancel(); |
| 46 | + if (mc.player.getMainHandStack().getItem().equals(Items.WRITABLE_BOOK)){ |
| 47 | + int index = InvUtils.finditem(Items.WRITABLE_BOOK); |
| 48 | + if (index == -1) { |
| 49 | + info("you are not holding a book"); |
| 50 | + return; |
| 51 | + } |
| 52 | + info(msg); |
| 53 | + mc.player.networkHandler.sendPacket(new BookUpdateC2SPacket(mc.player.getInventory().selectedSlot, Collections.singletonList(msg), Optional.empty())); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public void onActivate() { |
| 59 | + lasttext = ""; |
| 60 | + if (person.get().isEmpty()){ |
| 61 | + toggle(); |
| 62 | + info("please put the username of the person you want to chat with in the module settings"); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + @EventHandler |
| 67 | + private void ontick(TickEvent.Pre event){ |
| 68 | + PlayerEntity playerEntity = null; |
| 69 | + |
| 70 | + if (person.get().isEmpty()) return; |
| 71 | + for (PlayerEntity p : mc.world.getPlayers()){ |
| 72 | + if (p.getEntityName().equalsIgnoreCase(person.get())){ |
| 73 | + playerEntity = p; |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + if (playerEntity == null) return; |
| 78 | + |
| 79 | + if (playerEntity.getMainHandStack().getItem().equals(Items.WRITABLE_BOOK)){ |
| 80 | + String text = playerEntity.getMainHandStack().getNbt().get("pages").toString() |
| 81 | + .replaceAll("\\]", "") |
| 82 | + .replaceAll("\\[", "") |
| 83 | + .replaceAll("\"", "") |
| 84 | + .replaceAll("," , " "); |
| 85 | + |
| 86 | + if (Objects.equals(lasttext, text)) return; |
| 87 | + |
| 88 | + lasttext = text; |
| 89 | + info(text); |
| 90 | + } |
| 91 | + } |
| 92 | +} |
0 commit comments