diff --git a/src/main/java/me/night0721/lilase/Lilase.java b/src/main/java/me/night0721/lilase/Lilase.java index 3449bfc..7f66bc8 100644 --- a/src/main/java/me/night0721/lilase/Lilase.java +++ b/src/main/java/me/night0721/lilase/Lilase.java @@ -45,19 +45,18 @@ public class Lilase { @Mod.EventHandler public void init(FMLInitializationEvent event) { - configHandler = new ConfigHandler(); - configHandler.init(); + (configHandler = new ConfigHandler()).init(); KeyBindingManager keyBindingManager = new KeyBindingManager(); - MinecraftForge.EVENT_BUS.register(this); - MinecraftForge.EVENT_BUS.register(keyBindingManager); - MinecraftForge.EVENT_BUS.register(new SniperFlipperEvents()); - MinecraftForge.EVENT_BUS.register(new ImageRenderer()); + addToEventBus(this, keyBindingManager, new SniperFlipperEvents(), new ImageRenderer()); EventManager.INSTANCE.register(this); sniper = new Sniper(); pageFlipper = new PageFlipper(); keyBindingManager.registerKeyBindings(); - cofl = new Cofl(); - cofl.onOpen(); + (cofl = new Cofl()).onOpen(); + } + + private void addToEventBus(Object... objects) { + for (Object object : objects) MinecraftForge.EVENT_BUS.register(object); } @Subscribe diff --git a/src/main/java/me/night0721/lilase/config/ConfigHandler.java b/src/main/java/me/night0721/lilase/config/ConfigHandler.java index efd5c43..9d19ac9 100644 --- a/src/main/java/me/night0721/lilase/config/ConfigHandler.java +++ b/src/main/java/me/night0721/lilase/config/ConfigHandler.java @@ -19,6 +19,7 @@ public class ConfigHandler { } public void reloadConfig() { + // TODO: Fix if (hasNoKey("APIKey")) setString("APIKey", ""); if (hasNoKey("SendMessageToWebhook")) setBoolean("SendMessageToWebhook", true); if (hasNoKey("Webhook")) setString("Webhook", ""); diff --git a/src/main/java/me/night0721/lilase/events/PacketReceivedEvent.java b/src/main/java/me/night0721/lilase/events/PacketReceivedEvent.java index 9c33e96..7976d80 100644 --- a/src/main/java/me/night0721/lilase/events/PacketReceivedEvent.java +++ b/src/main/java/me/night0721/lilase/events/PacketReceivedEvent.java @@ -5,6 +5,7 @@ import net.minecraft.network.Packet; import net.minecraftforge.fml.common.eventhandler.Cancelable; import net.minecraftforge.fml.common.eventhandler.Event; +// TODO: Implement Lombok Library for clean code @Cancelable public class PacketReceivedEvent extends Event { public final Packet packet; diff --git a/src/main/java/me/night0721/lilase/events/PacketSentEvent.java b/src/main/java/me/night0721/lilase/events/PacketSentEvent.java index 7c9f6d4..7cece64 100644 --- a/src/main/java/me/night0721/lilase/events/PacketSentEvent.java +++ b/src/main/java/me/night0721/lilase/events/PacketSentEvent.java @@ -4,6 +4,7 @@ import net.minecraft.network.Packet; import net.minecraftforge.fml.common.eventhandler.Cancelable; import net.minecraftforge.fml.common.eventhandler.Event; +// TODO: Implement Lombok Library for clean code @Cancelable public class PacketSentEvent extends Event { private final Packet packet; diff --git a/src/main/java/me/night0721/lilase/events/ScoreboardRenderEvent.java b/src/main/java/me/night0721/lilase/events/ScoreboardRenderEvent.java index aced6ce..0e7175c 100644 --- a/src/main/java/me/night0721/lilase/events/ScoreboardRenderEvent.java +++ b/src/main/java/me/night0721/lilase/events/ScoreboardRenderEvent.java @@ -5,6 +5,7 @@ import net.minecraft.scoreboard.ScoreObjective; import net.minecraftforge.fml.common.eventhandler.Cancelable; import net.minecraftforge.fml.common.eventhandler.Event; +// TODO: Implement Lombok Library for clean code @Cancelable public class ScoreboardRenderEvent extends Event { public ScoreObjective objective; diff --git a/src/main/java/me/night0721/lilase/events/SniperFlipperEvents.java b/src/main/java/me/night0721/lilase/events/SniperFlipperEvents.java index 1a7bf08..574a2f6 100644 --- a/src/main/java/me/night0721/lilase/events/SniperFlipperEvents.java +++ b/src/main/java/me/night0721/lilase/events/SniperFlipperEvents.java @@ -40,24 +40,24 @@ import static me.night0721.lilase.features.sniper.Sniper.flipper; import static me.night0721.lilase.utils.PlayerUtils.sendPacketWithoutEvent; public class SniperFlipperEvents { - private int windowId = 1; - private int price; - private boolean buying = false; - private boolean bought = false; + private int windowId = 1, price; + private boolean buying = false, bought = false; private final Clock clock = new Clock(); - private final Pattern auctionSoldPattern = Pattern.compile("^(.*?) bought (.*?) for ([\\d,]+) coins CLICK$"); - private final Pattern boughtPattern = Pattern.compile("You purchased (\\w+(?:\\s+\\w+)*) for ([\\d,]+)\\s*(\\w+)!"); - private final Pattern boughtPattern2 = Pattern.compile("You claimed (.+?) from (.+?)'s auction!"); - private final Pattern boughtPattern3 = Pattern.compile("You (purchased|claimed)( (\\\\d+x))? ([^\\\\s]+(\\\\s+[^\\\\d,]+)*)((,| for) (\\\\d+,?)+ coins?(!)?)?"); + private final Pattern + AUCTION_SOLD_PATTERN = Pattern.compile("^(.*?) bought (.*?) for ([\\d,]+) coins CLICK$"), + BOUGHT_PATTERN = Pattern.compile("You purchased (\\w+(?:\\s+\\w+)*) for ([\\d,]+)\\s*(\\w+)!"), + BOUGHT_PATTERN_2 = Pattern.compile("You claimed (.+?) from (.+?)'s auction!"), + BOUGHT_PATTERN_3 = Pattern.compile("You (purchased|claimed)( (\\\\d+x))? ([^\\\\s]+(\\\\s+[^\\\\d,]+)*)((,| for) (\\\\d+,?)+ coins?(!)?)?"); + // TODO: Split into one pattern public static final List postedNames = new ArrayList<>(); @SubscribeEvent public void onChat(ClientChatReceivedEvent event) throws InterruptedException { String message = event.message.getUnformattedText(); - Matcher matcher = auctionSoldPattern.matcher(message); - Matcher boughtMatcher = boughtPattern.matcher(message); - Matcher boughtMatcher2 = boughtPattern2.matcher(message); - Matcher boughtMatcher3 = boughtPattern3.matcher(message); + Matcher matcher = AUCTION_SOLD_PATTERN.matcher(message); + Matcher boughtMatcher = BOUGHT_PATTERN.matcher(message); + Matcher boughtMatcher2 = BOUGHT_PATTERN_2.matcher(message); + Matcher boughtMatcher3 = BOUGHT_PATTERN_3.matcher(message); if (!message.contains(":")) { if (message.equals("You didn't participate in this auction!")) { Utils.debugLog("Failed to buy item, not fast enough. Closing the menu"); @@ -148,6 +148,7 @@ public class SniperFlipperEvents { Thread.sleep(3000); InventoryUtils.clickOpenContainerSlot(10); Thread.sleep(3000); + // TODO: Remove duplication Lilase.mc.thePlayer.closeScreen(); } } else { diff --git a/src/main/java/me/night0721/lilase/features/cofl/Cofl.java b/src/main/java/me/night0721/lilase/features/cofl/Cofl.java index 64932ee..c55a55f 100644 --- a/src/main/java/me/night0721/lilase/features/cofl/Cofl.java +++ b/src/main/java/me/night0721/lilase/features/cofl/Cofl.java @@ -42,27 +42,23 @@ public class Cofl { }); } - Pattern pattern = Pattern.compile("type[\":]*flip"); - Pattern commandPattern = Pattern.compile("/viewauction \\w+"); - Pattern pricePattern = Pattern.compile("§7Med: §b(\\d{1,3}(?:,\\d{3})*)"); + private final Pattern pattern = Pattern.compile("type[\":]*flip"); + private final Pattern commandPattern = Pattern.compile("/viewauction \\w+"); + private final Pattern pricePattern = Pattern.compile("§7Med: §b(\\d{1,3}(?:,\\d{3})*)"); public void handleMessage(String str) { try { - if (AHConfig.SNIPER_MODE != 2) return; - if (!getOpen()) return; - if (!str.startsWith("Received:")) return; - Matcher matcher = pattern.matcher(str); - if (matcher.find()) { + if (AHConfig.SNIPER_MODE != 2 || !getOpen() || !str.startsWith("Received:")) return; + if (pattern.matcher(str).find()) { Matcher commandMacther = commandPattern.matcher(str); Matcher priceMatcher = pricePattern.matcher(str); String[] split = str.split("Received: "); - JsonObject strJson = new JsonParser().parse(split[1]).getAsJsonObject(); - String itemName = new JsonParser().parse(strJson.get("data").getAsString()).getAsJsonObject().get("auction").getAsJsonObject().get("itemName").getAsString(); + String itemName = new JsonParser().parse(new JsonParser().parse(split[1]).getAsJsonObject().get("data").getAsString()).getAsJsonObject().get("auction").getAsJsonObject().get("itemName").getAsString(); if (commandMacther.find() && priceMatcher.find() && itemName != null) { String command = commandMacther.group(); - Utils.debugLog("Adding auction to queue: " + command); - Utils.debugLog("Price: " + Integer.parseInt(priceMatcher.group(1).replaceAll(",", ""))); - Utils.debugLog("Name: " + itemName); + Utils.debugLog("Adding auction to queue: " + command, + "Price: " + Integer.parseInt(priceMatcher.group(1).replaceAll(",", "")), + "Name: " + itemName); price = Integer.parseInt(priceMatcher.group(1).replaceAll(",", "")); getQueue().add(new QueueItem(command, itemName, price)); getQueue().scheduleClear(); @@ -78,22 +74,16 @@ public class Cofl { if (getOpen()) { Utils.sendMessage("Stopped COFL Sniper"); Lilase.mc.thePlayer.closeScreen(); - if (thread.isAlive()) { - queue.clear(); - queue.setRunning(false); - thread.interrupt(); - } + stopThread(); setOpen(false); UngrabUtils.regrabMouse(); } else { if (Utils.checkInHub()) { Utils.sendMessage("Started COFL Sniper"); setOpen(true); - if (thread.isAlive()) { - queue.clear(); - queue.setRunning(false); - thread.interrupt(); - } else { + boolean threadStatus = !thread.isAlive(); + stopThread(); + if (!threadStatus) { thread.start(); } UngrabUtils.ungrabMouse(); @@ -101,6 +91,13 @@ public class Cofl { } } + private void stopThread() { + if (thread.isAlive()) { + queue.clear(); + queue.setRunning(false); + thread.interrupt(); + } + } public boolean getOpen() { return open; } diff --git a/src/main/java/me/night0721/lilase/features/cofl/Queue.java b/src/main/java/me/night0721/lilase/features/cofl/Queue.java index f810dd9..9f9f250 100644 --- a/src/main/java/me/night0721/lilase/features/cofl/Queue.java +++ b/src/main/java/me/night0721/lilase/features/cofl/Queue.java @@ -7,11 +7,7 @@ import java.util.List; public class Queue { private final List queue = new ArrayList<>(); - private boolean running = false; - - private boolean clearTaskRunning = false; - - + private boolean running = false, clearTaskRunning = false; public void add(QueueItem item) { this.queue.add(item); } @@ -40,7 +36,6 @@ public class Queue { public void scheduleClear() { if (!this.clearTaskRunning) { this.clearTaskRunning = true; - new Thread(() -> { try { Thread.sleep(30000); diff --git a/src/main/java/me/night0721/lilase/features/cofl/QueueItem.java b/src/main/java/me/night0721/lilase/features/cofl/QueueItem.java index fcaefe2..a302269 100644 --- a/src/main/java/me/night0721/lilase/features/cofl/QueueItem.java +++ b/src/main/java/me/night0721/lilase/features/cofl/QueueItem.java @@ -3,9 +3,9 @@ package me.night0721.lilase.features.cofl; import me.night0721.lilase.features.flipper.Flipper; import me.night0721.lilase.utils.Utils; +// TODO: Implement Lombok Library for clean code public class QueueItem { - private final String command; - private final String name; + private final String command, name; private final int price; public QueueItem(String command, String name, int price) { diff --git a/src/main/java/me/night0721/lilase/features/flipper/Flipper.java b/src/main/java/me/night0721/lilase/features/flipper/Flipper.java index 26f2489..c82745d 100644 --- a/src/main/java/me/night0721/lilase/features/flipper/Flipper.java +++ b/src/main/java/me/night0721/lilase/features/flipper/Flipper.java @@ -18,7 +18,7 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.URL; - +// TODO: Fix repeating code (I will do it soon) public class Flipper { private final String itemname; private static String bytedata; @@ -100,13 +100,13 @@ public class Flipper { case BUYING: if (Utils.cookie != EffectState.ON && Lilase.mc.currentScreen == null && buyWait.passed()) { final Entity auctionMaster = getAuctionMaster(); - if (auctionMaster == null) { - Utils.debugLog("Cannot find shop NPC, retrying"); - buyWait.schedule(500); - } else { + boolean auctionMasterExists = auctionMaster != null; + if (auctionMasterExists) { Lilase.mc.playerController.interactWithEntitySendPacket(Lilase.mc.thePlayer, auctionMaster); - buyWait.schedule(1500); + } else { + Utils.debugLog("Cannot find shop NPC, retrying"); } + buyWait.schedule(auctionMasterExists ? 1500 : 500); } else if (InventoryUtils.inventoryNameContains("Auction House") && buyWait.passed()) { InventoryUtils.clickOpenContainerSlot(15); buyWait.schedule(1500); @@ -127,7 +127,7 @@ public class Flipper { } else if (!InventoryUtils.isStoneButton() && !InventoryUtils.isToAuctionItem(itemname) && buyWait.passed()) { InventoryUtils.clickOpenContainerSlot(13); buyWait.schedule(1000); - } + } // TODO: Ternary Expression } else if (InventoryUtils.inventoryNameContains("Manage Auction") && buyWait.passed()) { InventoryUtils.clickOpenContainerSlot(24); buyWait.schedule(1500); @@ -167,14 +167,13 @@ public class Flipper { BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String inputLine; StringBuilder content = new StringBuilder(); - while ((inputLine = in.readLine()) != null) { + while ((inputLine = in.readLine()) != null) content.append(inputLine); - } in.close(); connection.disconnect(); object = (JsonObject) new JsonParser().parse(content.toString()); System.out.println("Price" + object.get("price")); - return (JsonObject) new JsonParser().parse(content.toString()); + return object; } public static float distanceToFirstPoint() { @@ -186,15 +185,7 @@ public class Flipper { } public static Entity getAuctionMaster() { - for (final Entity e : Lilase.mc.theWorld.loadedEntityList) { - if (e instanceof EntityArmorStand) { - final String name = StringUtils.stripControlCodes(e.getDisplayName().getUnformattedText()); - if (name.startsWith("Auction Master")) { - return e; - } - } - } - return null; + return Lilase.mc.theWorld.loadedEntityList.stream().filter(e -> e instanceof EntityArmorStand && StringUtils.stripControlCodes(e.getDisplayName().getUnformattedText()).startsWith("Auction Master")).findFirst().orElse(null); } } diff --git a/src/main/java/me/night0721/lilase/gui/ImageRenderer.java b/src/main/java/me/night0721/lilase/gui/ImageRenderer.java index 4c4e0e8..4c4663e 100644 --- a/src/main/java/me/night0721/lilase/gui/ImageRenderer.java +++ b/src/main/java/me/night0721/lilase/gui/ImageRenderer.java @@ -8,15 +8,11 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import static me.night0721.lilase.Lilase.mc; public class ImageRenderer { - public void draw() { - mc.getTextureManager().bindTexture(new ResourceLocation("lilase:textures/images/crab.png")); - Gui.drawModalRectWithCustomSizedTexture(100, 0, 0, 0, 100, 100, 100, 100); - } - @SubscribeEvent public void onRender(RenderGameOverlayEvent.Post e) { if (e.type == RenderGameOverlayEvent.ElementType.ALL) { - draw(); + mc.getTextureManager().bindTexture(new ResourceLocation("lilase:textures/images/crab.png")); + Gui.drawModalRectWithCustomSizedTexture(100, 0, 0, 0, 100, 100, 100, 100); } } } diff --git a/src/main/java/me/night0721/lilase/gui/TextRenderer.java b/src/main/java/me/night0721/lilase/gui/TextRenderer.java index 0eb34a7..9c892f8 100644 --- a/src/main/java/me/night0721/lilase/gui/TextRenderer.java +++ b/src/main/java/me/night0721/lilase/gui/TextRenderer.java @@ -6,6 +6,7 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.GlStateManager; import org.lwjgl.opengl.GL11; +// TODO: Generify repeating code. public class TextRenderer { public static void drawString(String text, int x, int y, double scale) { double scaleReset = Math.pow(scale, -1); diff --git a/src/main/java/me/night0721/lilase/mixins/MixinNetHandlerPlayClient.java b/src/main/java/me/night0721/lilase/mixins/MixinNetHandlerPlayClient.java index ea5ef7b..fcd098e 100644 --- a/src/main/java/me/night0721/lilase/mixins/MixinNetHandlerPlayClient.java +++ b/src/main/java/me/night0721/lilase/mixins/MixinNetHandlerPlayClient.java @@ -3,6 +3,7 @@ package me.night0721.lilase.mixins; import me.night0721.lilase.utils.Utils; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.network.play.server.S47PacketPlayerListHeaderFooter; +import net.minecraft.util.IChatComponent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -12,7 +13,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class MixinNetHandlerPlayClient { @Inject(method = "handlePlayerListHeaderFooter", at = @At("HEAD")) public void handlePlayerListHeaderFooter(S47PacketPlayerListHeaderFooter packetIn, CallbackInfo ci) { - Utils.header = packetIn.getHeader().getFormattedText().length() == 0 ? null : packetIn.getHeader(); - Utils.footer = packetIn.getFooter().getFormattedText().length() == 0 ? null : packetIn.getFooter(); + Utils.header = nullIfEmpty(packetIn.getHeader()); + Utils.footer = nullIfEmpty(packetIn.getFooter()); + } + + private IChatComponent nullIfEmpty(IChatComponent element){ + return (element.getFormattedText().length() == 0) ? null : element; } } diff --git a/src/main/java/me/night0721/lilase/mixins/MixinNetworkManager.java b/src/main/java/me/night0721/lilase/mixins/MixinNetworkManager.java index e592e37..f3e1fac 100644 --- a/src/main/java/me/night0721/lilase/mixins/MixinNetworkManager.java +++ b/src/main/java/me/night0721/lilase/mixins/MixinNetworkManager.java @@ -16,19 +16,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class MixinNetworkManager { @Inject(method = {"channelRead0*"}, at = {@At(value = "HEAD")}, cancellable = true) private void read(ChannelHandlerContext context, Packet packet, CallbackInfo ci) { - if (MinecraftForge.EVENT_BUS.post(new PacketReceivedEvent(packet, context))) { + if (MinecraftForge.EVENT_BUS.post(new PacketReceivedEvent(packet, context))) ci.cancel(); - } } @Inject(method = {"sendPacket(Lnet/minecraft/network/Packet;)V"}, at = {@At(value = "HEAD")}, cancellable = true) private void onSendPacket(Packet packet, CallbackInfo ci) { - if (!PlayerUtils.packets.contains(packet)) { - if (MinecraftForge.EVENT_BUS.post(new PacketSentEvent(packet))) { + if (!PlayerUtils.packets.remove(packet)) { + if (MinecraftForge.EVENT_BUS.post(new PacketSentEvent(packet))) ci.cancel(); - } - } else { - PlayerUtils.packets.remove(packet); } } } diff --git a/src/main/java/me/night0721/lilase/utils/CurrentColor.java b/src/main/java/me/night0721/lilase/utils/CurrentColor.java index 5dc2056..d565121 100644 --- a/src/main/java/me/night0721/lilase/utils/CurrentColor.java +++ b/src/main/java/me/night0721/lilase/utils/CurrentColor.java @@ -6,6 +6,7 @@ import java.awt.*; * @author Gabagooooooooooool (ily) * @version 1.1 * Basic utility for aurora theming engine. + * <3 */ public class CurrentColor { @@ -31,24 +32,6 @@ public class CurrentColor { return Color.WHITE.getRGB(); } - public static float getFloatValue(float offset, int color) { - Color tempC = new Color(CurrentColor.currentColorGet(offset)); - int tempC_ = 0; - switch (color) { - case 0: - tempC_ = tempC.getRed(); - break; - case 1: - tempC_ = tempC.getGreen(); - break; - case 2: - tempC_ = tempC.getBlue(); - break; - - } - return (((float) tempC_) / 255F); - } - /** * Following method has been circulating in Minecraft Hacking Community for a while, making it impossible to trace original author. */ @@ -69,7 +52,6 @@ public class CurrentColor { * Following method has been circulating in Minecraft Hacking Community for a while, making it impossible to trace original author. */ protected static Color getRainbow(final int speed, final int offset) { - float hue = (System.currentTimeMillis() + offset) % speed; - return Color.getHSBColor(hue / speed, 0.9f, 1f); + return Color.getHSBColor(((System.currentTimeMillis() + offset) % speed) / speed, 0.9f, 1f); } } \ No newline at end of file diff --git a/src/main/java/me/night0721/lilase/utils/DiscordWebhook.java b/src/main/java/me/night0721/lilase/utils/DiscordWebhook.java index d6c0420..cf8bc35 100644 --- a/src/main/java/me/night0721/lilase/utils/DiscordWebhook.java +++ b/src/main/java/me/night0721/lilase/utils/DiscordWebhook.java @@ -135,6 +135,7 @@ public class DiscordWebhook { this.embeds.clear(); } + // TODO: Lombok! I'm gonna add it soon. The code looks bad right now :/ public static class EmbedObject { private String title; private String description; diff --git a/src/main/java/me/night0721/lilase/utils/KeyBindingManager.java b/src/main/java/me/night0721/lilase/utils/KeyBindingManager.java index 3daf319..2837724 100644 --- a/src/main/java/me/night0721/lilase/utils/KeyBindingManager.java +++ b/src/main/java/me/night0721/lilase/utils/KeyBindingManager.java @@ -14,14 +14,13 @@ public class KeyBindingManager { public void registerKeyBindings() { keyBindings[0] = new KeyBinding("Sniper Toggle", Keyboard.KEY_END, Lilase.MOD_NAME); keyBindings[1] = new KeyBinding("Config", Keyboard.KEY_MULTIPLY, Lilase.MOD_NAME); - for (KeyBinding keyBinding : keyBindings) { - ClientRegistry.registerKeyBinding(keyBinding); - } + for (KeyBinding keyBinding : keyBindings) ClientRegistry.registerKeyBinding(keyBinding); } @SubscribeEvent public void onKeyPress(InputEvent.KeyInputEvent event) { if (keyBindings[0].isPressed()) { + // TODO: Add sniper interface and use nested switch loop to prevent .toggleAuction(); repeating switch (AHConfig.SNIPER_MODE) { case 0: Lilase.sniper.toggleAuction(); @@ -34,9 +33,8 @@ public class KeyBindingManager { break; } } - if (keyBindings[1].isPressed()) { + if (keyBindings[1].isPressed()) Lilase.config.openGui(); - } } public static void rightClick() { @@ -68,6 +66,8 @@ public class KeyBindingManager { KeyBinding.setKeyBindState(Lilase.mc.gameSettings.keyBindAttack.getKeyCode(), attack); KeyBinding.setKeyBindState(Lilase.mc.gameSettings.keyBindSneak.getKeyCode(), crouch); KeyBinding.setKeyBindState(Lilase.mc.gameSettings.keyBindJump.getKeyCode(), space); + + // TODO: Will fix it. Just give time. } public static void stopMovement() { diff --git a/src/main/java/me/night0721/lilase/utils/UngrabUtils.java b/src/main/java/me/night0721/lilase/utils/UngrabUtils.java index f7143cd..d48c38a 100644 --- a/src/main/java/me/night0721/lilase/utils/UngrabUtils.java +++ b/src/main/java/me/night0721/lilase/utils/UngrabUtils.java @@ -5,9 +5,8 @@ import net.minecraft.util.MouseHelper; import org.lwjgl.input.Mouse; public class UngrabUtils { - public static boolean isUngrabbed = false; + public static boolean doesGameWantUngrabbed, isUngrabbed = false; private static MouseHelper oldMouseHelper; - private static boolean doesGameWantUngrabbed; public static void ungrabMouse() { Minecraft m = Minecraft.getMinecraft(); diff --git a/src/main/java/me/night0721/lilase/utils/Utils.java b/src/main/java/me/night0721/lilase/utils/Utils.java index 1d48fbc..a4ad3db 100644 --- a/src/main/java/me/night0721/lilase/utils/Utils.java +++ b/src/main/java/me/night0721/lilase/utils/Utils.java @@ -7,18 +7,16 @@ import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; -import java.util.List; -import java.util.regex.Matcher; import java.util.regex.Pattern; +import static me.night0721.lilase.Lilase.mc; + public class Utils { - public static boolean inHub = false; - public static IChatComponent header = null; - public static IChatComponent footer = null; - private static final Pattern PATTERN_ACTIVE_EFFECTS = Pattern.compile( - "§r§r§7You have a §r§cGod Potion §r§7active! §r§d([0-9]*?:?[0-9]*?:?[0-9]*)§r"); - public static EffectState cookie; - public static EffectState godPot; + public static IChatComponent header = null, footer = null; + private static final Pattern + PATTERN_ACTIVE_EFFECTS = Pattern.compile("§r§r§7You have a §r§cGod Potion §r§7active! §r§d([0-9]*?:?[0-9]*?:?[0-9]*)§r"), + PATTERN_HUB_LOCATIONS = Pattern.compile("(forest|village|farm|mountain|wilderness|community|graveyard|bazaar|auction)"); + public static EffectState cookie, godPot; public static String translateAlternateColorCodes(String text) { char[] b = text.toCharArray(); @@ -32,65 +30,44 @@ public class Utils { } public static void addTitle(String title) { - S45PacketTitle p1 = new S45PacketTitle(0, 20, 0); - S45PacketTitle p2 = new S45PacketTitle(S45PacketTitle.Type.TITLE, new ChatComponentText(Utils.translateAlternateColorCodes(title))); - Lilase.mc.thePlayer.sendQueue.handleTitle(p1); - Lilase.mc.thePlayer.sendQueue.handleTitle(p2); + Lilase.mc.thePlayer.sendQueue.handleTitle(new S45PacketTitle(0, 20, 0)); + Lilase.mc.thePlayer.sendQueue.handleTitle(new S45PacketTitle(S45PacketTitle.Type.TITLE, new ChatComponentText(Utils.translateAlternateColorCodes(title)))); } public static boolean checkInHub() { - List scoreboard = ScoreboardUtils.getSidebarLines(); - for (String s : scoreboard) { - String sCleaned = ScoreboardUtils.cleanSB(s); - if (sCleaned.contains("Forest") || sCleaned.contains("Village") || sCleaned.contains("Farm") || sCleaned.contains("Mountain") || sCleaned.contains("Wilderness") || sCleaned.contains("Community") || sCleaned.contains("Graveyard") || sCleaned.contains("Bazaar") || sCleaned.contains("Auction")) - inHub = true; - } - return inHub; + return ScoreboardUtils.getSidebarLines().stream().map(ScoreboardUtils::cleanSB).anyMatch(line -> PATTERN_HUB_LOCATIONS.matcher(line).find()); } public static void checkFooter() { - // - boolean foundGodPot = false; - boolean foundCookieText = false; - boolean loaded = false; - if (footer != null) { - String formatted = footer.getFormattedText(); - for (String line : formatted.split("\n")) { - Matcher activeEffectsMatcher = PATTERN_ACTIVE_EFFECTS.matcher(line); - if (activeEffectsMatcher.matches()) { - foundGodPot = true; - } else if (line.contains("§d§lCookie Buff")) { - foundCookieText = true; - } else if (foundCookieText && line.contains("Not active! Obtain")) { - foundCookieText = false; - cookie = EffectState.OFF; - } else if (foundCookieText) { - foundCookieText = false; - cookie = EffectState.ON; + for (String line : footer.getFormattedText().split("\n")) { + boolean foundGodPot = PATTERN_ACTIVE_EFFECTS.matcher(line).matches(); + godPot = (foundGodPot) ? EffectState.ON : EffectState.OFF; + if (!foundGodPot) { + cookie = (line.contains("Not active! Obtain")) ? EffectState.OFF : EffectState.ON; + if (!line.contains("Active")) { + godPot = EffectState.INDETERMINABLE; + cookie = EffectState.INDETERMINABLE; + } } - if (line.contains("Active")) { - loaded = true; - } - } - godPot = foundGodPot ? EffectState.ON : EffectState.OFF; - if (!loaded) { - godPot = EffectState.INDETERMINABLE; - cookie = EffectState.INDETERMINABLE; } } } public static void sendMessage(String message) { - Lilase.mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.LIGHT_PURPLE + "" + EnumChatFormatting.BOLD + "[Lilase] " + EnumChatFormatting.RESET + EnumChatFormatting.GREEN + EnumChatFormatting.BOLD + message)); + mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.LIGHT_PURPLE + "" + EnumChatFormatting.BOLD + "[Lilase] " + EnumChatFormatting.RESET + EnumChatFormatting.GREEN + EnumChatFormatting.BOLD + message)); } public static void debugLog(String message) { - Lilase.mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.LIGHT_PURPLE + "" + "[Lilase] " + message)); + mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.LIGHT_PURPLE + "" + "[Lilase] " + message)); + } + + public static void debugLog(String... messages){ + for (String message : messages) debugLog(message); } public static void sendServerMessage(String message) { - Lilase.mc.thePlayer.sendChatMessage(message); + mc.thePlayer.sendChatMessage(message); } }