v2.0.3 ready
Some checks failed
build-ci / build (push) Has been cancelled

This commit is contained in:
NK 2023-05-21 11:03:28 +01:00
parent 388a6e379a
commit 0eb36bd25c
21 changed files with 541 additions and 499 deletions

10
.github/CHANGELOG.md vendored
View file

@ -44,3 +44,13 @@
- Added many more stuff to debug - Added many more stuff to debug
- v2.0.2 - v2.0.2
- Minor bug fixes - Minor bug fixes
- v2.0.3
- Remove unecessary code
- Added debug option so you can choose to be spammed by debug message or not
- Uses altnative approach to snipe item so it is faster now
- Using lombok so less code is needed
- Added relist delay so you can set the delay between buying and relist
- Using OOP for selling item so less error
- Fixed pricing issue
- Item not found error should be fixed
- Added gui to tell you to update the mod

View file

@ -1,6 +1,6 @@
mod_name = Lilase mod_name = Lilase
mod_id = lilase mod_id = lilase
mod_version = 2.0.2 mod_version = 2.0.3
essential.defaults.loom=0 essential.defaults.loom=0

View file

@ -7,7 +7,6 @@ import me.night0721.lilase.config.AHConfig;
import me.night0721.lilase.config.ConfigHandler; import me.night0721.lilase.config.ConfigHandler;
import me.night0721.lilase.events.SniperFlipperEvents; import me.night0721.lilase.events.SniperFlipperEvents;
import me.night0721.lilase.features.cofl.Cofl; import me.night0721.lilase.features.cofl.Cofl;
import me.night0721.lilase.features.cofl.QueueItem;
import me.night0721.lilase.features.sniper.PageFlipper; import me.night0721.lilase.features.sniper.PageFlipper;
import me.night0721.lilase.features.sniper.Sniper; import me.night0721.lilase.features.sniper.Sniper;
import me.night0721.lilase.gui.ImageRenderer; import me.night0721.lilase.gui.ImageRenderer;
@ -32,7 +31,7 @@ import static me.night0721.lilase.config.AHConfig.RECONNECT_DELAY;
public class Lilase { public class Lilase {
public static final String MOD_NAME = "Lilase"; public static final String MOD_NAME = "Lilase";
public static final String MODID = "Lilase"; public static final String MODID = "Lilase";
public static final String VERSION = "2.0.2"; public static final String VERSION = "2.0.3";
public static final Minecraft mc = Minecraft.getMinecraft(); public static final Minecraft mc = Minecraft.getMinecraft();
public static Sniper sniper; public static Sniper sniper;
public static PageFlipper pageFlipper; public static PageFlipper pageFlipper;
@ -69,7 +68,6 @@ public class Lilase {
tickAmount++; tickAmount++;
if (tickAmount % 20 == 0) Utils.checkFooter(); if (tickAmount % 20 == 0) Utils.checkFooter();
if (pageFlipper != null) pageFlipper.switchStates(); if (pageFlipper != null) pageFlipper.switchStates();
if (QueueItem.flipper != null) QueueItem.flipper.switchStates();
if (mc.currentScreen instanceof GuiDisconnected && clock.passed()) { if (mc.currentScreen instanceof GuiDisconnected && clock.passed()) {
clock.schedule(RECONNECT_DELAY * 1000L); clock.schedule(RECONNECT_DELAY * 1000L);
FMLClientHandler.instance().connectToServer(new GuiMultiplayer(new GuiMainMenu()), new ServerData(" ", "mc.hypixel.net", false)); FMLClientHandler.instance().connectToServer(new GuiMultiplayer(new GuiMainMenu()), new ServerData(" ", "mc.hypixel.net", false));

View file

@ -20,6 +20,8 @@ public class AHConfig extends Config {
addListener("ONLY_SNIPER", () -> Lilase.configHandler.setBoolean("OnlySniper", ONLY_SNIPER)); addListener("ONLY_SNIPER", () -> Lilase.configHandler.setBoolean("OnlySniper", ONLY_SNIPER));
addListener("GUI", () -> Lilase.configHandler.setBoolean("GUI", GUI)); addListener("GUI", () -> Lilase.configHandler.setBoolean("GUI", GUI));
addListener("GUI_COLOR", () -> Lilase.configHandler.setInt("GUI_COLOR", GUI_COLOR.getRGB())); addListener("GUI_COLOR", () -> Lilase.configHandler.setInt("GUI_COLOR", GUI_COLOR.getRGB()));
addListener("RELIST_TIMEOUT", () -> Lilase.configHandler.setInt("RELIST_TIMEOUT", Math.round(RELIST_TIMEOUT)));
addListener("DEBUG", () -> Lilase.configHandler.setBoolean("Debug", DEBUG));
addDependency("WEBHOOK", "SEND_MESSAGE"); addDependency("WEBHOOK", "SEND_MESSAGE");
addDependency("MINIMUM_PROFIT_PERCENTAGE", "CHECK_PERCENTAGE"); addDependency("MINIMUM_PROFIT_PERCENTAGE", "CHECK_PERCENTAGE");
addDependency("MAXIMUM_PROFIT_PERCENTAGE", "CHECK_MAXIMUM_PROFIT"); addDependency("MAXIMUM_PROFIT_PERCENTAGE", "CHECK_MAXIMUM_PROFIT");
@ -32,6 +34,12 @@ public class AHConfig extends Config {
@Slider(name = "Bed Spam Delay (ms)", min = 50, max = 500, step = 50, category = "Auction House", subcategory = "Sniper", description = "Delay between each bed spam") @Slider(name = "Bed Spam Delay (ms)", min = 50, max = 500, step = 50, category = "Auction House", subcategory = "Sniper", description = "Delay between each bed spam")
public static int BED_SPAM_DELAY = 100; public static int BED_SPAM_DELAY = 100;
@Number(name = "Relist timeout", min = 1500, max = 60000, step = 500, category = "Auction House", subcategory = "Sniper", description = "Delay between buying and relisting an item")
public static int RELIST_TIMEOUT = 1500;
@Switch(name = "Debug", category = "Auction House", subcategory = "Sniper", description = "Debug mode")
public static boolean DEBUG = false;
@Switch(name = "Only Sniper", category = "Auction House", subcategory = "Sniper", description = "Only snipe items, stop auto resell") @Switch(name = "Only Sniper", category = "Auction House", subcategory = "Sniper", description = "Only snipe items, stop auto resell")
public static boolean ONLY_SNIPER = false; public static boolean ONLY_SNIPER = false;

View file

@ -28,6 +28,8 @@ public class ConfigHandler {
if (hasNoKey("OnlySniper")) setBoolean("OnlySniper", false); if (hasNoKey("OnlySniper")) setBoolean("OnlySniper", false);
if (hasNoKey("GUI")) setBoolean("GUI", true); if (hasNoKey("GUI")) setBoolean("GUI", true);
if (hasNoKey("GUI_COLOR")) setInt("GUI_COLOR", 0x003153); if (hasNoKey("GUI_COLOR")) setInt("GUI_COLOR", 0x003153);
if (hasNoKey("DEBUG")) setBoolean("DEBUG", false);
if (hasNoKey("RELIST_TIMEOUT")) setInt("RELIST_TIMEOUT", 1500);
} }
public JsonObject readConfigFile() { public JsonObject readConfigFile() {

View file

@ -2,7 +2,6 @@ package me.night0721.lilase.events;
import me.night0721.lilase.Lilase; import me.night0721.lilase.Lilase;
import me.night0721.lilase.config.AHConfig; import me.night0721.lilase.config.AHConfig;
import me.night0721.lilase.features.cofl.Cofl;
import me.night0721.lilase.features.cofl.QueueItem; import me.night0721.lilase.features.cofl.QueueItem;
import me.night0721.lilase.features.flipper.Flipper; import me.night0721.lilase.features.flipper.Flipper;
import me.night0721.lilase.features.flipper.FlipperState; import me.night0721.lilase.features.flipper.FlipperState;
@ -13,102 +12,77 @@ import me.night0721.lilase.utils.*;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.play.client.C12PacketUpdateSign; import net.minecraft.network.play.client.C12PacketUpdateSign;
import net.minecraft.network.play.server.S2DPacketOpenWindow;
import net.minecraft.network.play.server.S2FPacketSetSlot;
import net.minecraft.network.play.server.S33PacketUpdateSign; import net.minecraft.network.play.server.S33PacketUpdateSign;
import net.minecraft.util.IChatComponent; import net.minecraft.util.IChatComponent;
import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent; import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.*;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static me.night0721.lilase.config.AHConfig.GUI_COLOR; import static me.night0721.lilase.config.AHConfig.*;
import static me.night0721.lilase.config.AHConfig.SEND_MESSAGE;
import static me.night0721.lilase.features.flipper.Flipper.*; import static me.night0721.lilase.features.flipper.Flipper.*;
import static me.night0721.lilase.features.flipper.FlipperState.START; import static me.night0721.lilase.features.flipper.FlipperState.START;
import static me.night0721.lilase.utils.PlayerUtils.sendPacketWithoutEvent; import static me.night0721.lilase.utils.PlayerUtils.sendPacketWithoutEvent;
public class SniperFlipperEvents { public class SniperFlipperEvents {
private int windowId = 1, price;
private boolean buying = false, bought = false;
private final Clock clock = new Clock(); private final Clock clock = new Clock();
private final Pattern AUCTION_SOLD_PATTERN = Pattern.compile("^(.*?) bought (.*?) for ([\\d,]+) coins CLICK$"), public static final ArrayList<Flipper> selling_queue = new ArrayList<>();
pattern = Pattern.compile("You purchased (\\w+(?:\\s+\\w+)*) for ([\\d,]+)\\s*(\\w+)|You claimed (.+?) from (.+?)'s auction!|(You (purchased|claimed)( (\\\\d+x))? ([^\\\\s]+(\\\\s+[^\\\\d,]+)*)((,| for) (\\\\d+,?)+ coins?(!)?))?"); private final Pattern AUCTION_SOLD_PATTERN = Pattern.compile("^(.*?) bought (.*?) for ([\\d,]+) coins CLICK$");
public static final List<String> postedNames = new ArrayList<>();
@SubscribeEvent @SubscribeEvent
public void onChat(ClientChatReceivedEvent event) throws InterruptedException { public void onChat(ClientChatReceivedEvent event) throws InterruptedException {
String message = event.message.getUnformattedText(); String message = event.message.getUnformattedText();
if (message.startsWith("§6[Auction]")) {
Matcher matcher = AUCTION_SOLD_PATTERN.matcher(ScoreboardUtils.cleanSB(message));
if (matcher.matches()) {
try {
webhook.setUsername("Lilase");
webhook.setAvatarUrl(icon);
webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setTitle("Someone bought an item!")
.setFooter("Purse: " + format.format(Utils.getPurse()), icon)
.addField("Item:", matcher.group(2), true)
.addField("Price:", matcher.group(3), true)
.addField("Purchaser:", matcher.group(1), true)
.setColor(Color.decode("#003153")));
if (SEND_MESSAGE) webhook.execute();
Utils.debugLog("Notified Webhook");
} catch (Exception e) {
e.printStackTrace();
Utils.debugLog("Failed to send webhook");
}
Lilase.sniper.incrementAuctionsFlipped();
}
}
/*
§6[Auction] §aphiinix_ §ebought §fImplosion Belt §efor §6900,000 coins §lCLICK
*/
Matcher boughtMatcher = pattern.matcher(message);
if (!message.contains(":")) { if (!message.contains(":")) {
if (message.equals("You didn't participate in this auction!")) { if (message.startsWith("§6[Auction]")) {
// §6[Auction] §aphiinix_ §ebought §fImplosion Belt §efor §6900,000 coins §lCLICK
Matcher matcher = AUCTION_SOLD_PATTERN.matcher(ScoreboardUtils.cleanSB(message));
if (matcher.matches()) {
String purchaser;
try {
purchaser = matcher.group(1).split("\\[Auction] ")[1];
} catch (Exception ignored) {
purchaser = message.split("\\[Auction] ")[1].split(" bought")[0];
}
if (SEND_MESSAGE) {
try {
webhook.setUsername("Lilase");
webhook.setAvatarUrl(icon);
webhook.addEmbed(new DiscordWebhook.EmbedObject().setTitle("Someone bought an item!").setFooter("Purse: " + format.format(Utils.getPurse()), icon).addField("Item:", matcher.group(2), true).addField("Price:", matcher.group(3), true).addField("Purchaser:", purchaser, true).setColor(Color.decode("#003153")));
webhook.execute();
Utils.debugLog("Notified Webhook");
} catch (Exception e) {
e.printStackTrace();
Utils.debugLog("Failed to send webhook");
}
}
Lilase.sniper.incrementAuctionsFlipped();
}
} else if (message.equals("You didn't participate in this auction!")) {
Utils.debugLog("Failed to buy item, not fast enough. Closing the menu"); Utils.debugLog("Failed to buy item, not fast enough. Closing the menu");
InventoryUtils.clickOpenContainerSlot(49); InventoryUtils.clickOpenContainerSlot(49);
} else if (message.equals("You don't have enough coins to afford this bid!")) { } else if (message.equals("You don't have enough coins to afford this bid!")) {
Utils.debugLog("Failed to buy item, not enough money. Closing the menu"); Utils.debugLog("Failed to buy item, not enough money. Closing the menu");
InventoryUtils.clickOpenContainerSlot(49); InventoryUtils.clickOpenContainerSlot(49);
} else if (boughtMatcher.matches() && bought) { } else if (message.equals("Your starting bid must be at least 10 coins!") || message.contains("Can't create a BIN auction for this item for a PRICE this LOW!")) {
new Thread(() -> {
bought = false;
Utils.debugLog("Bought an item, starting to sell");
Utils.debugLog("Target price " + Cofl.target);
price = Cofl.target;
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (!AHConfig.ONLY_SNIPER) QueueItem.flipper.sellItem();
}).start();
} else if (message.equals("Your starting bid must be at least 10 coins!")) {
InventoryUtils.clickOpenContainerSlot(13); InventoryUtils.clickOpenContainerSlot(13);
Lilase.mc.thePlayer.closeScreen(); Lilase.mc.thePlayer.closeScreen();
Utils.debugLog("Cannot post item as the cost is too low, stopping fliiper and starting sniper"); Utils.debugLog("Cannot post item as the cost is too low, stopping fliiper and starting sniper");
Lilase.cofl.toggleAuction(); Lilase.cofl.toggleAuction();
Flipper.state = FlipperState.NONE; Flipper.state = FlipperState.NONE;
} else if (message.contains("Can't create a BIN auction for this item for a PRICE this LOW!")) {
Lilase.mc.thePlayer.closeScreen();
Utils.debugLog("Cannot post item as the cost is too low, stopping fliiper and starting sniper");
Lilase.cofl.toggleAuction();
Flipper.state = FlipperState.NONE;
} else if (message.contains("You were spawned in Limbo")) { } else if (message.contains("You were spawned in Limbo")) {
Utils.debugLog("Detected in Limbo, stopping everything for 5 minutes"); Utils.debugLog("Detected in Limbo, stopping everything for 5 minutes");
Utils.addTitle("You got sent to Limbo!"); Utils.addTitle("You got sent to Limbo!");
@ -124,6 +98,15 @@ public class SniperFlipperEvents {
} }
} }
@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent event) {
if (Lilase.mc.thePlayer == null || event.phase != TickEvent.Phase.START) return;
try {
if (selling_queue.get(0) != null) selling_queue.forEach(Flipper::switchStates);
} catch (Exception ignored) {
}
}
private final Runnable bazaarChilling = () -> { private final Runnable bazaarChilling = () -> {
try { try {
rotation.reset(); rotation.reset();
@ -182,7 +165,8 @@ public class SniperFlipperEvents {
if (Flipper.state != FlipperState.NONE) { if (Flipper.state != FlipperState.NONE) {
new Thread(() -> { new Thread(() -> {
Utils.debugLog("Interrupting Flipper selling"); Utils.debugLog("Interrupting Flipper selling");
Flipper.sendInterrupt(); selling_queue.get(0).sendInterrupt();
selling_queue.remove(0);
Lilase.mc.thePlayer.closeScreen(); Lilase.mc.thePlayer.closeScreen();
Flipper.state = FlipperState.NONE; Flipper.state = FlipperState.NONE;
Lilase.cofl.toggleAuction(); Lilase.cofl.toggleAuction();
@ -219,56 +203,78 @@ public class SniperFlipperEvents {
} }
} }
@SubscribeEvent(priority = EventPriority.HIGHEST) private int latestWindowId = -1;
public void onInventoryRendering(GuiScreenEvent.BackgroundDrawnEvent event) {
String windowName = InventoryUtils.getInventoryName(); @SubscribeEvent
public void onPacketReceive(PacketReceivedEvent event) {
if (event.packet instanceof S2FPacketSetSlot) {
S2FPacketSetSlot packetSetSlot = (S2FPacketSetSlot) event.packet;
ItemStack stack = packetSetSlot.func_149174_e();
if (stack != null && packetSetSlot.func_149175_c() == 0) {
try {
String uuid = stack.getTagCompound().getCompoundTag("ExtraAttributes").getString("uuid");
String uid = uuid.split("-")[4];
QueueItem item = Lilase.cofl.getQueue().getHistoryByUID(uid);
if (item != null) {
String unFormattedName = ScoreboardUtils.cleanSB(stack.getDisplayName());
int slot = packetSetSlot.func_149173_d();
NBTTagCompound tag = stack.getTagCompound();
System.out.println("Slot: " + slot + "\nStack Name: " + unFormattedName + " \nStack NBT: " + tag);
new Thread(() -> {
if (!ONLY_SNIPER) {
item.flipper = new Flipper(item.name, item.price, item.target, uuid);
item.flipper.sendBought();
Utils.debugLog("Bought an item, starting to sell");
System.out.println("Item Name: " + item.flipper.name);
System.out.println("Item Price: " + item.flipper.price);
System.out.println("Target Price: " + item.flipper.target);
selling_queue.add(item.flipper);
item.flipper.sellItem();
} else {
Utils.debugLog("Bought an item, not selling because only sniper is enabled");
}
}).start();
}
} catch (Exception ignored) {
}
}
}
if (AHConfig.BED_SPAM && (Lilase.pageFlipper.getOpen() || Lilase.cofl.getOpen())) { if (AHConfig.BED_SPAM && (Lilase.pageFlipper.getOpen() || Lilase.cofl.getOpen())) {
if ("BIN Auction View".equals(windowName)) { if (event.packet instanceof S2DPacketOpenWindow && ((S2DPacketOpenWindow) event.packet).getGuiId().equals("minecraft:chest")) {
ItemStack is = InventoryUtils.getStackInOpenContainerSlot(31); S2DPacketOpenWindow packetOpenWindow = (S2DPacketOpenWindow) event.packet;
if (is != null) { if (packetOpenWindow.getWindowTitle().getUnformattedText().equals("BIN Auction View"))
System.out.println("Slot 31: " + is.getItem().getRegistryName()); latestWindowId = packetOpenWindow.getWindowId();
buying = true; }
windowId = Lilase.mc.thePlayer.openContainer.windowId; if (event.packet instanceof S2FPacketSetSlot) {
if (is.getItem() == Items.bed && clock.passed()) { S2FPacketSetSlot packetSetSlot = (S2FPacketSetSlot) event.packet;
Lilase.mc.playerController.windowClick(windowId, 31, 0, 0, Lilase.mc.thePlayer); if (packetSetSlot.func_149173_d() == 31 && packetSetSlot.func_149174_e() != null && packetSetSlot.func_149175_c() == latestWindowId) {
ItemStack itemStack = packetSetSlot.func_149174_e();
Utils.debugLog("Slot 31: " + itemStack.getItem().getRegistryName());
if (itemStack.getItem() == Items.bed && clock.passed()) {
clickWindow(latestWindowId, 31);
clickWindow(latestWindowId + 1, 11);
clock.schedule(AHConfig.BED_SPAM_DELAY); clock.schedule(AHConfig.BED_SPAM_DELAY);
} else if (is.getItem() == Items.gold_nugget) } else if (itemStack.getItem() == Items.gold_nugget || Item.getItemFromBlock(Blocks.gold_block) == itemStack.getItem()) {
Lilase.mc.playerController.windowClick(windowId, 31, 0, 0, Lilase.mc.thePlayer); clickWindow(latestWindowId, 31);
else if (is.getItem() == Items.potato) { clickWindow(latestWindowId + 1, 11);
buying = false;
Lilase.mc.thePlayer.closeScreen();
} else if (is.getItem() == Items.feather) {
buying = false;
Lilase.mc.thePlayer.closeScreen();
} else { } else {
System.out.println("Not potato, not bed, not nugget, not feather??"); Utils.debugLog("Auction was bought by someone else, closing window");
buying = false;
Lilase.mc.thePlayer.closeScreen(); Lilase.mc.thePlayer.closeScreen();
} }
} }
} }
if (buying && "Confirm Purchase".equals(windowName)) {
System.out.println("Window ID: " + Lilase.mc.thePlayer.openContainer.windowId);
Lilase.mc.playerController.windowClick(windowId + 1, 11, 0, 0, Lilase.mc.thePlayer);
buying = false;
if (Lilase.cofl.getQueue().isRunning()) bought = true;
}
} }
}
@SubscribeEvent
public void onPacketReceive(PacketReceivedEvent event) {
if (event.packet instanceof S33PacketUpdateSign && (Flipper.state.equals(START) || Lilase.cofl.getQueue().isRunning())) { if (event.packet instanceof S33PacketUpdateSign && (Flipper.state.equals(START) || Lilase.cofl.getQueue().isRunning())) {
if (Utils.cookie == EffectState.ON || (Utils.cookie == EffectState.OFF && Utils.checkInHub())) if (Utils.cookie == EffectState.ON || (Utils.cookie == EffectState.OFF && Utils.checkInHub()))
new Thread(() -> { new Thread(() -> {
try { try {
S33PacketUpdateSign packetUpdateSign = (S33PacketUpdateSign) event.packet; S33PacketUpdateSign packetUpdateSign = (S33PacketUpdateSign) event.packet;
IChatComponent[] lines = packetUpdateSign.getLines(); IChatComponent[] lines = packetUpdateSign.getLines();
Utils.debugLog("Item price should be " + price); Utils.debugLog("Target Price: " + selling_queue.get(0).target);
Thread.sleep(300); Thread.sleep(300);
lines[0] = IChatComponent.Serializer.jsonToComponent("{\"text\":\"" + price + "\"}"); lines[0] = IChatComponent.Serializer.jsonToComponent("{\"text\":\"" + selling_queue.get(0).target + "\"}");
C12PacketUpdateSign packetUpdateSign1 = new C12PacketUpdateSign(packetUpdateSign.getPos(), lines); sendPacketWithoutEvent(new C12PacketUpdateSign(packetUpdateSign.getPos(), lines));
sendPacketWithoutEvent(packetUpdateSign1);
} catch (RuntimeException | InterruptedException e) { } catch (RuntimeException | InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -276,8 +282,7 @@ public class SniperFlipperEvents {
} }
} }
@SubscribeEvent public void clickWindow(int window, int slot) {
public void onWorldChange(WorldEvent.Unload event) { Lilase.mc.playerController.windowClick(window, slot, 0, 0, Lilase.mc.thePlayer);
buying = false;
} }
} }

View file

@ -10,17 +10,14 @@ import me.night0721.lilase.utils.UngrabUtils;
import me.night0721.lilase.utils.Utils; import me.night0721.lilase.utils.Utils;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.concurrent.ThreadLocalRandom; import java.util.Random;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static me.night0721.lilase.config.AHConfig.SEND_MESSAGE; import static me.night0721.lilase.config.AHConfig.SEND_MESSAGE;
public class Cofl { public class Cofl {
private final Queue queue = new Queue(); public final Queue queue = new Queue();
private boolean open = false; private boolean open = false;
public static int price = 0;
public static int target = 0;
private final ThreadLocalRandom random = ThreadLocalRandom.current();
public final Thread thread = new Thread(() -> { public final Thread thread = new Thread(() -> {
while (true) { while (true) {
try { try {
@ -54,20 +51,20 @@ public class Cofl {
try { try {
if (!getOpen() || !str.startsWith("Received:")) return; if (!getOpen() || !str.startsWith("Received:")) return;
if (pattern.matcher(str).find()) { if (pattern.matcher(str).find()) {
// Utils.debugLog("Doing some motion as we don't want to be AFK"); Random random = new Random();
Lilase.mc.thePlayer.inventory.currentItem = random.nextInt(9); Lilase.mc.thePlayer.inventory.currentItem = random.nextInt(9);
String[] split = str.split("Received: "); String[] split = str.split("Received: ");
JsonObject auction = new JsonParser().parse(new JsonParser().parse(split[1]).getAsJsonObject().get("data").getAsString()).getAsJsonObject(); JsonObject received = new JsonParser().parse(split[1]).getAsJsonObject();
if (!received.get("type").getAsString().equals("flip")) return;
JsonObject auction = new JsonParser().parse(received.get("data").getAsString()).getAsJsonObject();
String itemName = auction.get("auction").getAsJsonObject().get("itemName").getAsString(); String itemName = auction.get("auction").getAsJsonObject().get("itemName").getAsString();
String id = auction.get("auction").getAsJsonObject().get("uuid").getAsString(); String id = auction.get("auction").getAsJsonObject().get("uuid").getAsString();
price = auction.get("auction").getAsJsonObject().get("startingBid").getAsInt(); int price = auction.get("auction").getAsJsonObject().get("startingBid").getAsInt();
target = auction.get("target").getAsInt(); String uid = auction.get("auction").getAsJsonObject().get("flatNbt").getAsJsonObject().get("uid").getAsString();
// Utils.debugLog("Item Name: " + itemName); int target = auction.get("target").getAsInt();
// Utils.debugLog("ID: " + id); if (itemName != null && id != null && price != 0 && target != 0 && uid != null) {
// Utils.debugLog("Price: " + price); Utils.debugLog("Adding auction to queue: " + id, "Price: " + price, "Target Price: " + target, "Name: " + itemName, "UID: " + uid);
if (itemName != null && id != null && price != 0 && target != 0) { getQueue().add(new QueueItem(id, itemName, price, target, uid));
Utils.debugLog("Adding auction to queue: " + id, "Price: " + price, "Target Price: " + target, "Name: " + itemName);
getQueue().add(new QueueItem(id, itemName, price, target));
getQueue().scheduleClear(); getQueue().scheduleClear();
} }
} }

View file

@ -1,15 +1,26 @@
package me.night0721.lilase.features.cofl; package me.night0721.lilase.features.cofl;
import lombok.Getter;
import me.night0721.lilase.utils.Utils; import me.night0721.lilase.utils.Utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Queue { public class Queue {
private final List<QueueItem> queue = new ArrayList<>(); public final List<QueueItem> queue = new ArrayList<>();
private final @Getter List<QueueItem> history = new ArrayList<>();
private boolean running = false, clearTaskRunning = false; private boolean running = false, clearTaskRunning = false;
public void add(QueueItem item) { public void add(QueueItem item) {
this.queue.add(item); this.queue.add(item);
this.history.add(item);
}
public QueueItem getHistoryByUID(String uid) {
for (QueueItem item : this.history) {
if (uid.contains(item.uid)) return item;
}
return null;
} }
public QueueItem get() { public QueueItem get() {
@ -29,6 +40,7 @@ public class Queue {
public boolean isRunning() { public boolean isRunning() {
return this.running; return this.running;
} }
public void clear() { public void clear() {
this.queue.clear(); this.queue.clear();
} }

View file

@ -1,25 +1,30 @@
package me.night0721.lilase.features.cofl; package me.night0721.lilase.features.cofl;
import lombok.Getter;
import me.night0721.lilase.features.flipper.Flipper; import me.night0721.lilase.features.flipper.Flipper;
import me.night0721.lilase.utils.Utils; import me.night0721.lilase.utils.Utils;
// TODO: Implement Lombok Library for clean code // TODO: Implement Lombok Library for clean code
public class QueueItem { public class QueueItem {
private final String command, name; public @Getter
private final int price; final String command, name;
private final int target; public @Getter
public static Flipper flipper = null; final int price;
public @Getter
final int target;
public @Getter String uid;
public Flipper flipper;
public QueueItem(String command, String name, int price, int target) { public QueueItem(String command, String name, int price, int target, String uid) {
this.command = command; this.command = command;
this.name = name; this.name = name;
this.price = price; this.price = price;
this.target = target; this.target = target;
this.uid = uid;
} }
public void openAuction() { public void openAuction() {
Utils.debugLog("Executing: " + command); Utils.debugLog("Executing: " + command);
Utils.sendServerMessage("/viewauction " + command); Utils.sendServerMessage("/viewauction " + command);
flipper = new Flipper(name, price, target);
} }
} }

View file

@ -1,7 +1,6 @@
package me.night0721.lilase.features.flipper; package me.night0721.lilase.features.flipper;
import me.night0721.lilase.Lilase; import me.night0721.lilase.Lilase;
import me.night0721.lilase.events.SniperFlipperEvents;
import me.night0721.lilase.player.EffectState; import me.night0721.lilase.player.EffectState;
import me.night0721.lilase.player.Rotation; import me.night0721.lilase.player.Rotation;
import me.night0721.lilase.utils.*; import me.night0721.lilase.utils.*;
@ -16,13 +15,16 @@ import java.text.DecimalFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.Locale; import java.util.Locale;
import static me.night0721.lilase.config.AHConfig.RELIST_TIMEOUT;
import static me.night0721.lilase.config.AHConfig.SEND_MESSAGE; import static me.night0721.lilase.config.AHConfig.SEND_MESSAGE;
import static me.night0721.lilase.events.SniperFlipperEvents.selling_queue;
// TODO: Fix repeating code (I will do it soon) // TODO: Fix repeating code (I will do it soon)
public class Flipper { public class Flipper {
private static String itemname = ""; public String name;
private static int itemprice = 0; public int price;
private static int target = 0; public int target;
public String uuid;
public static FlipperState state = FlipperState.NONE; public static FlipperState state = FlipperState.NONE;
public static final Rotation rotation = new Rotation(); public static final Rotation rotation = new Rotation();
private final Clock buyWait = new Clock(); private final Clock buyWait = new Clock();
@ -32,10 +34,11 @@ public class Flipper {
public static final String icon = "https://camo.githubusercontent.com/57a8295f890970d2173b895c7a0f6c60527fb3bec4489b233b221ab45cb9fa42/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3834323031343930393236343935333335342f313038323337333237353033383030333231302f6c696c6173652e706e67"; public static final String icon = "https://camo.githubusercontent.com/57a8295f890970d2173b895c7a0f6c60527fb3bec4489b233b221ab45cb9fa42/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3834323031343930393236343935333335342f313038323337333237353033383030333231302f6c696c6173652e706e67";
public Flipper(String name, int price, int targetprice) { public Flipper(String name, int price, int target, String uuid) {
itemname = name; this.name = name;
itemprice = price; this.price = price;
target = targetprice; this.target = target;
this.uuid = uuid;
webhook.setUsername("Lilase"); webhook.setUsername("Lilase");
webhook.setAvatarUrl(icon); webhook.setAvatarUrl(icon);
} }
@ -48,22 +51,10 @@ public class Flipper {
if (Lilase.cofl.getOpen()) Lilase.cofl.toggleAuction(); if (Lilase.cofl.getOpen()) Lilase.cofl.toggleAuction();
UngrabUtils.ungrabMouse(); UngrabUtils.ungrabMouse();
Utils.debugLog("Cookie: " + (Utils.cookie == EffectState.ON ? "ON" : "OFF")); Utils.debugLog("Cookie: " + (Utils.cookie == EffectState.ON ? "ON" : "OFF"));
Utils.debugLog("Have screen: " + (Lilase.mc.currentScreen != null ? "Yes" : "No")); System.out.println("Slot in inventory: " + InventoryUtils.getSlotForItemm(this.uuid));
Utils.debugLog("Profit Percentage: " + target / itemprice);
try { try {
webhook.addEmbed(new DiscordWebhook.EmbedObject() Thread.sleep(RELIST_TIMEOUT);
.setTitle("Just purchased an item!") } catch (InterruptedException ignored) {
.setFooter("Purse: " + format.format(Utils.getPurse()), icon)
.addField("Item:", itemname, true)
.addField("Price:", format.format(itemprice), true)
.addField("Target Price:", format.format(target), true)
.addField("Profit Percentage:", df.format(target / itemprice * 100L) + "%", true)
.setColor(Color.decode("#003153")));
if (SEND_MESSAGE) webhook.execute();
Utils.debugLog("Notified Webhook");
} catch (Exception e) {
e.printStackTrace();
Utils.debugLog("Failed to send webhook");
} }
if (Utils.cookie != EffectState.ON) { if (Utils.cookie != EffectState.ON) {
Utils.sendServerMessage("/hub"); Utils.sendServerMessage("/hub");
@ -80,11 +71,11 @@ public class Flipper {
if (Lilase.mc.currentScreen != null) { if (Lilase.mc.currentScreen != null) {
Lilase.mc.thePlayer.closeScreen(); Lilase.mc.thePlayer.closeScreen();
} else if (distanceToFirstPoint() < 0.7f) { } else if (distanceToFirstPoint() < 0.7f) {
System.out.println("Moving to auction house"); // System.out.println("Moving to auction house");
KeyBindingManager.updateKeys(false, false, false, false, false); KeyBindingManager.updateKeys(false, false, false, false, false);
state = FlipperState.WALKING_INTO_AUCTION_HOUSE; state = FlipperState.WALKING_INTO_AUCTION_HOUSE;
} else if (distanceToFirstPoint() < 5f) { } else if (distanceToFirstPoint() < 5f) {
System.out.println("Crouching to point 1"); // System.out.println("Crouching to point 1");
KeyBindingManager.updateKeys(true, false, false, false, false, true, false); KeyBindingManager.updateKeys(true, false, false, false, false, true, false);
} else { } else {
KeyBindingManager.updateKeys(true, false, false, false, false); KeyBindingManager.updateKeys(true, false, false, false, false);
@ -94,14 +85,14 @@ public class Flipper {
if (Lilase.mc.currentScreen != null) { if (Lilase.mc.currentScreen != null) {
Lilase.mc.thePlayer.closeScreen(); Lilase.mc.thePlayer.closeScreen();
} else if (AngleUtils.smallestAngleDifference(AngleUtils.get360RotationYaw(), 88f) > 1.2) { } else if (AngleUtils.smallestAngleDifference(AngleUtils.get360RotationYaw(), 88f) > 1.2) {
System.out.println("Rotating to Auction Master"); // System.out.println("Rotating to Auction Master");
rotation.easeTo(88f, Lilase.mc.thePlayer.rotationPitch, 500); rotation.easeTo(88f, Lilase.mc.thePlayer.rotationPitch, 500);
} else if (distanceToAuctionMaster() < 0.7f) { } else if (distanceToAuctionMaster() < 0.7f) {
Utils.debugLog("At Auction Master, opening shop"); Utils.debugLog("At Auction Master, opening shop");
KeyBindingManager.updateKeys(false, false, false, false, false); KeyBindingManager.updateKeys(false, false, false, false, false);
state = FlipperState.BUYING; state = FlipperState.BUYING;
} else if (distanceToAuctionMaster() < 5f) { } else if (distanceToAuctionMaster() < 5f) {
System.out.println("Crouching to Auction Master"); // System.out.println("Crouching to Auction Master");
KeyBindingManager.updateKeys(true, false, false, false, false, true, false); KeyBindingManager.updateKeys(true, false, false, false, false, true, false);
} else { } else {
KeyBindingManager.updateKeys(true, false, false, false, false); KeyBindingManager.updateKeys(true, false, false, false, false);
@ -122,83 +113,84 @@ public class Flipper {
buyWait.schedule(1500); buyWait.schedule(1500);
} else if (InventoryUtils.inventoryNameContains("Create BIN Auction")) { } else if (InventoryUtils.inventoryNameContains("Create BIN Auction")) {
if (InventoryUtils.isStoneButton() && buyWait.passed()) { if (InventoryUtils.isStoneButton() && buyWait.passed()) {
if (InventoryUtils.getSlotForItem(itemname) == -1) { if (InventoryUtils.getSlotForItemm(this.uuid) == -1) {
Utils.debugLog("Cannot find item in inventory, stopping flipper"); Utils.debugLog("Cannot find item in inventory, stopping flipper");
selling_queue.remove(0);
if (SEND_MESSAGE) {
try {
webhook.addEmbed(embed("Failed to post an item!", "Could not find item in inventory, sending so you can post it manually", "#ff0000"));
webhook.execute();
Utils.debugLog("Notified Webhook");
} catch (Exception e) {
e.printStackTrace();
Utils.debugLog("Failed to send webhook");
}
}
Lilase.mc.thePlayer.closeScreen();
state = FlipperState.NONE;
Lilase.cofl.toggleAuction();
return;
}
InventoryUtils.clickOpenContainerSlot(InventoryUtils.getSlotForItemm(this.uuid) + 81);
buyWait.schedule(1000);
} else if (!InventoryUtils.isStoneButton() && InventoryUtils.isToAuctionItem(this.uuid) && buyWait.passed()) {
InventoryUtils.clickOpenContainerSlot(31);
state = FlipperState.START;
buyWait.schedule(1000);
} else if (!InventoryUtils.isStoneButton() && !InventoryUtils.isToAuctionItem(this.uuid) && buyWait.passed()) {
InventoryUtils.clickOpenContainerSlot(13);
buyWait.schedule(1000);
} // TODO: Ternary Expression
} else if (InventoryUtils.inventoryNameContains("Manage Auctions") && buyWait.passed()) {
ItemStack slot24 = InventoryUtils.getStackInOpenContainerSlot(24);
ItemStack slot33 = InventoryUtils.getStackInOpenContainerSlot(33);
if (slot24 != null && slot24.getItem() == Items.golden_horse_armor) {
InventoryUtils.clickOpenContainerSlot(24);
buyWait.schedule(1000);
} else if (slot33 != null) {
if (slot33.getSubCompound("display", false).getString("Name").startsWith("§c")) {
Utils.debugLog("Auction slots full, stopping sniper for a while");
selling_queue.remove(0);
if (SEND_MESSAGE) {
try {
webhook.addEmbed(embed("Auction slots are full!", "Could not create more auctions as slots are full already, sending you here so you could create it manually", "#ff0000"));
webhook.execute();
Utils.debugLog("Notified Webhook");
} catch (Exception e) {
e.printStackTrace();
Utils.debugLog("Failed to send webhook");
}
}
Lilase.mc.thePlayer.closeScreen();
state = FlipperState.NONE;
// Lilase.cofl.toggleAuction();
return;
} else if (slot33.getItem() == Items.golden_horse_armor) {
InventoryUtils.clickOpenContainerSlot(33);
buyWait.schedule(1000);
}
} else {
Utils.debugLog("Can't find create auction button, stopping flipper");
selling_queue.remove(0);
if (SEND_MESSAGE) {
try { try {
webhook.addEmbed(new DiscordWebhook.EmbedObject() webhook.addEmbed(embed("Failed to post an item!", "Could not find create auction button, sending so you can post it manually", "#ff0000"));
.setTitle("Failed to post an item!") webhook.execute();
.setDescription("Could not find item in inventory, sending so you can post it manually")
.setFooter("Purse: " + format.format(Utils.getPurse()), icon)
.addField("Item:", itemname, true)
.addField("Price:", format.format(itemprice), true)
.addField("Target Price:", format.format(target), true)
.addField("Profit Percentage:", Float.parseFloat(df.format(target / itemprice * 100L)) + "%", true)
.setColor(Color.decode("#ff0000")));
if (SEND_MESSAGE) webhook.execute();
Utils.debugLog("Notified Webhook"); Utils.debugLog("Notified Webhook");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Utils.debugLog("Failed to send webhook"); Utils.debugLog("Failed to send webhook");
} }
Lilase.mc.thePlayer.closeScreen();
state = FlipperState.NONE;
Lilase.cofl.setOpen(true);
return;
}
InventoryUtils.clickOpenContainerSlot(InventoryUtils.getSlotForItem(itemname));
buyWait.schedule(1000);
} else if (!InventoryUtils.isStoneButton() && InventoryUtils.isToAuctionItem(itemname) && buyWait.passed()) {
InventoryUtils.clickOpenContainerSlot(31);
buyWait.schedule(1000);
state = FlipperState.START;
} 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()) {
ItemStack slot24 = InventoryUtils.getStackInOpenContainerSlot(24);
ItemStack slot33 = InventoryUtils.getStackInOpenContainerSlot(33);
ItemStack slot42 = InventoryUtils.getStackInOpenContainerSlot(42);
ItemStack slot51 = InventoryUtils.getStackInOpenContainerSlot(51);
if (slot24 != null && slot24.getItem() == Items.golden_horse_armor) {
InventoryUtils.clickOpenContainerSlot(24);
buyWait.schedule(1000);
} else if (slot33 != null && slot33.getItem() == Items.golden_horse_armor) {
InventoryUtils.clickOpenContainerSlot(33);
buyWait.schedule(1000);
} else if (slot42 != null && slot42.getItem() == Items.golden_horse_armor) {
InventoryUtils.clickOpenContainerSlot(42);
buyWait.schedule(1000);
} else if (slot51 != null && slot51.getItem() == Items.golden_horse_armor) {
InventoryUtils.clickOpenContainerSlot(51);
buyWait.schedule(1000);
} else {
Utils.debugLog("Can't find create auction button, stopping flipper");
try {
webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setTitle("Failed to post an item!")
.setDescription("Could not find create auction button, sending so you can post it manually")
.setFooter("Purse: " + format.format(Utils.getPurse()), icon)
.addField("Item:", itemname, true)
.addField("Price:", format.format(itemprice), true)
.addField("Target Price:", format.format(target), true)
.addField("Profit Percentage:", Float.parseFloat(df.format(target / itemprice * 100L)) + "%", true)
.setColor(Color.decode("#ff0000")));
if (SEND_MESSAGE) webhook.execute();
Utils.debugLog("Notified Webhook");
} catch (Exception e) {
e.printStackTrace();
Utils.debugLog("Failed to send webhook");
} }
Lilase.mc.thePlayer.closeScreen(); Lilase.mc.thePlayer.closeScreen();
state = FlipperState.NONE; state = FlipperState.NONE;
Lilase.cofl.setOpen(true); Lilase.cofl.toggleAuction();
return; return;
} }
} }
case START: case START:
if (!InventoryUtils.isStoneButton() && InventoryUtils.isToAuctionItem(itemname) && InventoryUtils.inventoryNameStartsWith("Create BIN Auction") && buyWait.passed()) { if (!InventoryUtils.isStoneButton() && InventoryUtils.isToAuctionItem(this.uuid) && InventoryUtils.inventoryNameStartsWith("Create BIN Auction") && buyWait.passed()) {
InventoryUtils.clickOpenContainerSlot(29); InventoryUtils.clickOpenContainerSlot(29);
buyWait.schedule(1000); buyWait.schedule(1000);
} else if (InventoryUtils.inventoryNameContains("Confirm BIN Auction") && buyWait.passed()) { } else if (InventoryUtils.inventoryNameContains("Confirm BIN Auction") && buyWait.passed()) {
@ -207,36 +199,45 @@ public class Flipper {
} else if (InventoryUtils.inventoryNameContains("BIN Auction View") && buyWait.passed()) { } else if (InventoryUtils.inventoryNameContains("BIN Auction View") && buyWait.passed()) {
InventoryUtils.clickOpenContainerSlot(49); InventoryUtils.clickOpenContainerSlot(49);
Lilase.sniper.incrementAuctionsPosted(); Lilase.sniper.incrementAuctionsPosted();
SniperFlipperEvents.postedNames.add(itemname);
buyWait.schedule(500); buyWait.schedule(500);
Lilase.mc.thePlayer.closeScreen(); Lilase.mc.thePlayer.closeScreen();
buyWait.schedule(500); buyWait.schedule(500);
Utils.sendMessage("Posted item on Auction House, continue sniping now"); Utils.sendMessage("Posted item on Auction House, continue sniping now");
state = FlipperState.NONE; state = FlipperState.NONE;
Lilase.cofl.toggleAuction(); Lilase.cofl.toggleAuction();
selling_queue.remove(0);
} }
case NONE: case NONE:
break; break;
} }
} }
public static void sendInterrupt() {
try { public void sendInterrupt() {
webhook.addEmbed(new DiscordWebhook.EmbedObject() if (SEND_MESSAGE) {
.setTitle("Failed to post an item!") try {
.setDescription("Could not find create as interruption, sending so you can post it manually") webhook.addEmbed(embed("Could not find create as interruption", "Could not find create as interruption, sending so you can post it manually", "#ff0000"));
.setFooter("Purse: " + format.format(Utils.getPurse()), icon) webhook.execute();
.addField("Item:", itemname, true) Utils.debugLog("Notified Webhook");
.addField("Price:", format.format(itemprice), true) } catch (Exception e) {
.addField("Target Price:", format.format(target), true) e.printStackTrace();
.addField("Profit Percentage:", Float.parseFloat(df.format(target / itemprice * 100L)) + "%", true) Utils.debugLog("Failed to send webhook");
.setColor(Color.decode("#ff0000"))); }
if (SEND_MESSAGE) webhook.execute();
Utils.debugLog("Notified Webhook");
} catch (Exception e) {
e.printStackTrace();
Utils.debugLog("Failed to send webhook");
} }
} }
public void sendBought() {
if (SEND_MESSAGE) {
try {
webhook.addEmbed(embed("Just purchased an item!", "", "#003153"));
webhook.execute();
Utils.debugLog("Notified Webhook");
} catch (Exception e) {
e.printStackTrace();
Utils.debugLog("Failed to send webhook");
}
}
}
public static float distanceToFirstPoint() { public static float distanceToFirstPoint() {
return (float) Math.sqrt(Math.pow(Lilase.mc.thePlayer.posX - (-2.5), 2) + Math.pow(Lilase.mc.thePlayer.posZ - (-91.5), 2)); return (float) Math.sqrt(Math.pow(Lilase.mc.thePlayer.posX - (-2.5), 2) + Math.pow(Lilase.mc.thePlayer.posZ - (-91.5), 2));
} }
@ -248,5 +249,17 @@ public class Flipper {
public static Entity getAuctionMaster() { public static Entity getAuctionMaster() {
return Lilase.mc.theWorld.loadedEntityList.stream().filter(e -> e instanceof EntityArmorStand && StringUtils.stripControlCodes(e.getDisplayName().getUnformattedText()).startsWith("Auction Master")).findFirst().orElse(null); return Lilase.mc.theWorld.loadedEntityList.stream().filter(e -> e instanceof EntityArmorStand && StringUtils.stripControlCodes(e.getDisplayName().getUnformattedText()).startsWith("Auction Master")).findFirst().orElse(null);
} }
public DiscordWebhook.EmbedObject embed(String title, String description, String color) {
return new DiscordWebhook.EmbedObject()
.setTitle(title)
.setDescription(description)
.setFooter("Purse: " + format.format(Utils.getPurse()), icon)
.addField("Item:", name, true)
.addField("Price:", format.format(price), true)
.addField("Target Price:", format.format(target), true)
.addField("Profit Percentage:", df.format((double) (target - price) / price * 100f) + "%", true)
.setColor(Color.decode(color));
}
} }

View file

@ -0,0 +1,134 @@
package me.night0721.lilase.gui;
import com.google.gson.JsonParser;
import me.night0721.lilase.Lilase;
import me.night0721.lilase.utils.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiScreen;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
/*
Credits: FarmHelper
*/
public class UpdateGUI extends GuiScreen {
private static final Minecraft mc = Minecraft.getMinecraft();
private static boolean shownGui = false;
public static boolean outdated = false;
private static String[] message;
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawBackground(0);
float scale = 3;
GL11.glScalef(scale, scale, 0.0F);
this.drawCenteredString(mc.fontRendererObj, "Outdated version of Lilase", (int) (this.width / 2f / scale), (int) (this.height / 6f / scale), Color.RED.darker().getRGB());
GL11.glScalef(1.0F / scale, 1.0F / scale, 0.0F);
scale = 1.5f;
GL11.glScalef(scale, scale, 0.0F);
this.drawString(mc.fontRendererObj, "What's new? ➤", (int) (this.width / 2f / scale - 180), (int) (this.height / 6 / scale + 25), Color.GREEN.getRGB());
GL11.glScalef(1.0F / scale, 1.0F / scale, 0.0F);
if (message != null) {
int y = 40;
for (String s : message) {
this.drawString(mc.fontRendererObj, s, this.width / 2 - 160, this.height / 6 + y, Color.WHITE.getRGB());
y += 15;
}
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
@Override
public void initGui() {
super.initGui();
registerButtons();
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
super.keyTyped(typedChar, keyCode);
if (keyCode == Keyboard.KEY_ESCAPE) {
mc.displayGuiScreen(new GuiMainMenu());
}
}
@Override
protected void actionPerformed(GuiButton button) {
switch (button.id) {
case 1: // closebtn
mc.displayGuiScreen(new GuiMainMenu());
break;
case 2: // downloadbtn
Utils.openURL("https://github.com/night0721/Lilase/releases/latest");
mc.displayGuiScreen(new GuiMainMenu());
break;
}
}
private void registerButtons() {
GuiButton closeBtn = new GuiButton(1, this.width / 2, this.height / 2 + 100, 150, 20, "Close");
this.buttonList.add(closeBtn);
GuiButton downloadBtn = new GuiButton(2, this.width / 2 - 150, this.height / 2 + 100, 150, 20, "Download new version");
this.buttonList.add(downloadBtn);
}
public static void showGUI() {
if (!shownGui && isOutdated()) {
mc.displayGuiScreen(new UpdateGUI());
shownGui = true;
outdated = isOutdated();
message = getReleaseMessage().replaceAll("\r", "").replace("+ ", "§a+ ").replace("= ", "§f= ").replace("- ", "§c- ").split("\n");
}
}
private static boolean isOutdated() {
try {
StringBuilder result = new StringBuilder();
URL url = new URL("https://api.github.com/repos/night0721/Lilase/releases/latest");
HttpURLConnection conn = ((HttpURLConnection)url.openConnection());
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36");
conn.setRequestMethod("GET");
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(conn.getInputStream()))) {
for (String line; (line = reader.readLine()) != null; ) {
result.append(line);
}
}
String latestversion = new JsonParser().parse(result.toString()).getAsJsonObject().get("tag_name").getAsString().replace("v", "");
return !Lilase.VERSION.contains(latestversion);
} catch (Exception e) {
return false;
}
}
private static String getReleaseMessage() {
try {
StringBuilder result = new StringBuilder();
URL url = new URL("https://api.github.com/repos/night0721/Lilase/releases/latest");
HttpURLConnection conn = ((HttpURLConnection)url.openConnection());
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36");
conn.setRequestMethod("GET");
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(conn.getInputStream()))) {
for (String line; (line = reader.readLine()) != null; ) {
result.append(line);
}
}
return new JsonParser().parse(result.toString()).getAsJsonObject().get("body").getAsString();
} catch (Exception e) {
return "No release message was found.";
}
}
}

View file

@ -23,8 +23,8 @@ public class MixinGuiIngame {
@ModifyArg(method = "renderScoreboard", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawString(Ljava/lang/String;III)I")) @ModifyArg(method = "renderScoreboard", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawString(Ljava/lang/String;III)I"))
public String a(String text) { public String a(String text) {
String txt = keepScoreboardCharacters(stripColor(text)).trim(); String txt = keepScoreboardCharacters(stripColor(text)).trim();
if (txt.startsWith("www")) return "§4w§cw§6w§e.§2n§ai§bg§3h§1t§90§d7§42§c1§6.§em§2e"; if (txt.startsWith("www")) return " §4w§cw§6w§e.§2n§ai§bg§3h§1t§90§d7§42§c1§6.§em§2e ";
if (txt.startsWith("SKY")) return "§d§lLILASE"; if (txt.startsWith("SKY")) return " §d§lLILASE ";
if (Pattern.compile("\\d{2}/\\d{2}/\\d{2}").matcher(txt).find()) return txt.split(" ")[0]; if (Pattern.compile("\\d{2}/\\d{2}/\\d{2}").matcher(txt).find()) return txt.split(" ")[0];
if (text.startsWith(String.valueOf(EnumChatFormatting.RED)) && Pattern.compile("\\d+").matcher(txt).matches()) return ""; if (text.startsWith(String.valueOf(EnumChatFormatting.RED)) && Pattern.compile("\\d+").matcher(txt).matches()) return "";
else return text; else return text;

View file

@ -0,0 +1,29 @@
package me.night0721.lilase.mixins;
import me.night0721.lilase.gui.UpdateGUI;
import net.minecraft.client.gui.GuiMainMenu;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GuiMainMenu.class)
public class MixinGuiMainMenu {
@Shadow
private String splashText;
private static boolean done = false;
@Final
@Inject(method = "updateScreen", at = @At("RETURN"))
private void initGui(CallbackInfo ci) {
if (!done) {
UpdateGUI.showGUI();
done = true;
}
if (UpdateGUI.outdated) {
this.splashText = "Update Lilase <3";
}
}
}

View file

@ -13,6 +13,6 @@ import static me.night0721.lilase.Lilase.VERSION;
public class MixinMinecraft { public class MixinMinecraft {
@Inject(method = {"startGame"}, at = {@At("RETURN")}) @Inject(method = {"startGame"}, at = {@At("RETURN")})
private void startGame(CallbackInfo ci) { private void startGame(CallbackInfo ci) {
Display.setTitle("Lilase v" + VERSION + " | night0721"); Display.setTitle("Lilase v" + VERSION);
} }
} }

View file

@ -1,11 +1,10 @@
package me.night0721.lilase.player; package me.night0721.lilase.player;
import me.night0721.lilase.Lilase;
import me.night0721.lilase.utils.AngleUtils; import me.night0721.lilase.utils.AngleUtils;
import net.minecraft.client.Minecraft;
import org.apache.commons.lang3.tuple.MutablePair; import org.apache.commons.lang3.tuple.MutablePair;
public class Rotation { public class Rotation {
private final static Minecraft mc = Minecraft.getMinecraft();
public boolean rotating; public boolean rotating;
public boolean completed; public boolean completed;
@ -21,36 +20,36 @@ public class Rotation {
rotating = true; rotating = true;
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
endTime = System.currentTimeMillis() + time; endTime = System.currentTimeMillis() + time;
start.setLeft(mc.thePlayer.rotationYaw); start.setLeft(Lilase.mc.thePlayer.rotationYaw);
start.setRight(mc.thePlayer.rotationPitch); start.setRight(Lilase.mc.thePlayer.rotationPitch);
target.setLeft(AngleUtils.get360RotationYaw(yaw)); target.setLeft(AngleUtils.get360RotationYaw(yaw));
target.setRight(pitch); target.setRight(pitch);
getDifference(); getDifference();
} }
public void lockAngle(float yaw, float pitch) { public void lockAngle(float yaw, float pitch) {
if (mc.thePlayer.rotationYaw != yaw || mc.thePlayer.rotationPitch != pitch && !rotating) if (Lilase.mc.thePlayer.rotationYaw != yaw || Lilase.mc.thePlayer.rotationPitch != pitch && !rotating)
easeTo(yaw, pitch, 1000); easeTo(yaw, pitch, 1000);
} }
public void update() { public void update() {
if (System.currentTimeMillis() <= endTime) { if (System.currentTimeMillis() <= endTime) {
if (shouldRotateClockwise()) { if (shouldRotateClockwise()) {
mc.thePlayer.rotationYaw = start.left + interpolate(difference.left); Lilase.mc.thePlayer.rotationYaw = start.left + interpolate(difference.left);
} else { } else {
mc.thePlayer.rotationYaw = start.left - interpolate(difference.left); Lilase.mc.thePlayer.rotationYaw = start.left - interpolate(difference.left);
} }
mc.thePlayer.rotationPitch = start.right + interpolate(difference.right); Lilase.mc.thePlayer.rotationPitch = start.right + interpolate(difference.right);
} else if (!completed) { } else if (!completed) {
if (shouldRotateClockwise()) { if (shouldRotateClockwise()) {
System.out.println("Rotation final st - " + start.left + ", " + mc.thePlayer.rotationYaw); System.out.println("Rotation final st - " + start.left + ", " + Lilase.mc.thePlayer.rotationYaw);
mc.thePlayer.rotationYaw = target.left; Lilase.mc.thePlayer.rotationYaw = target.left;
System.out.println("Rotation final - " + start.left + difference.left); System.out.println("Rotation final - " + start.left + difference.left);
} else { } else {
mc.thePlayer.rotationYaw = target.left; Lilase.mc.thePlayer.rotationYaw = target.left;
System.out.println("Rotation final - " + (start.left - difference.left)); System.out.println("Rotation final - " + (start.left - difference.left));
} }
mc.thePlayer.rotationPitch = start.right + difference.right; Lilase.mc.thePlayer.rotationPitch = start.right + difference.right;
completed = true; completed = true;
rotating = false; rotating = false;
} }

View file

@ -1,16 +1,15 @@
package me.night0721.lilase.utils; package me.night0721.lilase.utils;
import net.minecraft.client.Minecraft; import me.night0721.lilase.Lilase;
public class AngleUtils { public class AngleUtils {
private static final Minecraft mc = Minecraft.getMinecraft();
public static float get360RotationYaw(float yaw) { public static float get360RotationYaw(float yaw) {
return (yaw % 360 + 360) % 360; return (yaw % 360 + 360) % 360;
} }
public static float get360RotationYaw() { public static float get360RotationYaw() {
return get360RotationYaw(mc.thePlayer.rotationYaw); return get360RotationYaw(Lilase.mc.thePlayer.rotationYaw);
} }
public static float clockwiseDifference(float initialYaw360, float targetYaw360) { public static float clockwiseDifference(float initialYaw360, float targetYaw360) {

View file

@ -1,19 +1,11 @@
package me.night0721.lilase.utils; package me.night0721.lilase.utils;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockCarpet;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.util.BlockPos; import net.minecraft.util.BlockPos;
import net.minecraft.util.Vec3i;
import java.util.Arrays;
public class BlockUtils { public class BlockUtils {
private static final Minecraft mc = Minecraft.getMinecraft(); private static final Minecraft mc = Minecraft.getMinecraft();
private static final Block[] walkables = { Blocks.air, Blocks.water, Blocks.flowing_water, Blocks.dark_oak_fence_gate, Blocks.acacia_fence_gate, Blocks.birch_fence_gate, Blocks.oak_fence_gate, Blocks.jungle_fence_gate, Blocks.spruce_fence_gate, Blocks.wall_sign, Blocks.reeds };
public static int getUnitX() { public static int getUnitX() {
double modYaw = (mc.thePlayer.rotationYaw % 360 + 360) % 360; double modYaw = (mc.thePlayer.rotationYaw % 360 + 360) % 360;
@ -42,67 +34,6 @@ public class BlockUtils {
} }
public static Block getRelativeBlock(float x, float y, float z) { public static Block getRelativeBlock(float x, float y, float z) {
return (mc.theWorld.getBlockState( return (mc.theWorld.getBlockState(new BlockPos(mc.thePlayer.posX + (getUnitX() * z) + (getUnitZ() * -1 * x), mc.thePlayer.posY + y, mc.thePlayer.posZ + (getUnitZ() * z) + (getUnitX() * x))).getBlock());
new BlockPos(
mc.thePlayer.posX + (getUnitX() * z) + (getUnitZ() * -1 * x),
mc.thePlayer.posY + y,
mc.thePlayer.posZ + (getUnitZ() * z) + (getUnitX() * x)
)).getBlock());
}
public static BlockPos getRelativeBlockPos(float x, float y, float z) {
return new BlockPos(
mc.thePlayer.posX + (getUnitX() * z) + (getUnitZ() * -1 * x),
mc.thePlayer.posY + y,
mc.thePlayer.posZ + (getUnitZ() * z) + (getUnitX() * x)
);
}
public static int countCarpet() {
int r = 2;
int count = 0;
BlockPos playerPos = mc.thePlayer.getPosition();
playerPos.add(0, 1, 0);
Vec3i vec3i = new Vec3i(r, r, r);
Vec3i vec3i2 = new Vec3i(r, r, r);
for (BlockPos blockPos : BlockPos.getAllInBox(playerPos.add(vec3i), playerPos.subtract(vec3i2))) {
IBlockState blockState = mc.theWorld.getBlockState(blockPos);
if (blockState.getBlock() == Blocks.carpet && blockState.getValue(BlockCarpet.COLOR) == EnumDyeColor.BROWN) {
System.out.println("Carpet color: " + blockState.getValue(BlockCarpet.COLOR));
count++;
}
}
return count;
}
public static int bedrockCount() {
int r = 4;
int count = 0;
BlockPos playerPos = Minecraft.getMinecraft().thePlayer.getPosition();
playerPos.add(0, 1, 0);
Vec3i vec3i = new Vec3i(r, r, r);
Vec3i vec3i2 = new Vec3i(r, r, r);
for (BlockPos blockPos : BlockPos.getAllInBox(playerPos.add(vec3i), playerPos.subtract(vec3i2))) {
IBlockState blockState = Minecraft.getMinecraft().theWorld.getBlockState(blockPos);
if (blockState.getBlock() == Blocks.bedrock) {
count++;
}
}
return count;
}
public static Block getLeftBlock(){
return getRelativeBlock(-1, 0, 0);
}
public static Block getRightBlock(){
return getRelativeBlock(1, 0, 0);
}
public static Block getBackBlock(){
return getRelativeBlock(0, 0, -1);
}
public static Block getFrontBlock(){
return getRelativeBlock(0, 0, 1);
}
public static boolean isWalkable(Block block) {
return Arrays.asList(walkables).contains(block);
} }
} }

View file

@ -1,5 +1,8 @@
package me.night0721.lilase.utils; package me.night0721.lilase.utils;
import lombok.Getter;
import lombok.Setter;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import java.awt.*; import java.awt.*;
import java.io.IOException; import java.io.IOException;
@ -16,10 +19,10 @@ import java.util.*;
public class DiscordWebhook { public class DiscordWebhook {
private final String url; private final String url;
private String content; private @Setter String content;
private String username; private @Setter String username;
private String avatarUrl; private @Setter String avatarUrl;
private boolean tts; private @Setter boolean tts;
private final List<EmbedObject> embeds = new ArrayList<>(); private final List<EmbedObject> embeds = new ArrayList<>();
/** /**
@ -31,22 +34,6 @@ public class DiscordWebhook {
this.url = url; this.url = url;
} }
public void setContent(String content) {
this.content = content;
}
public void setUsername(String username) {
this.username = username;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
public void setTts(boolean tts) {
this.tts = tts;
}
public void addEmbed(EmbedObject embed) { public void addEmbed(EmbedObject embed) {
this.embeds.add(embed); this.embeds.add(embed);
} }
@ -143,52 +130,15 @@ public class DiscordWebhook {
// TODO: Lombok! I'm gonna add it soon. The code looks bad right now :/ // TODO: Lombok! I'm gonna add it soon. The code looks bad right now :/
public static class EmbedObject { public static class EmbedObject {
private String title; private @Getter String title;
private String description; private @Getter String description;
private String url; private @Getter String url;
private Color color; private @Getter Color color;
private @Getter Footer footer;
private Footer footer; private @Getter Thumbnail thumbnail;
private Thumbnail thumbnail; private @Getter Image image;
private Image image; private @Getter Author author;
private Author author; private final @Getter List<Field> fields = new ArrayList<>();
private final List<Field> fields = new ArrayList<>();
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public String getUrl() {
return url;
}
public Color getColor() {
return color;
}
public Footer getFooter() {
return footer;
}
public Thumbnail getThumbnail() {
return thumbnail;
}
public Image getImage() {
return image;
}
public Author getAuthor() {
return author;
}
public List<Field> getFields() {
return fields;
}
public EmbedObject setTitle(String title) { public EmbedObject setTitle(String title) {
this.title = title; this.title = title;
@ -236,93 +186,53 @@ public class DiscordWebhook {
} }
private static class Footer { private static class Footer {
private final String text; private @Getter final String text;
private final String iconUrl; private @Getter final String iconUrl;
private Footer(String text, String iconUrl) { private Footer(String text, String iconUrl) {
this.text = text; this.text = text;
this.iconUrl = iconUrl; this.iconUrl = iconUrl;
} }
private String getText() {
return text;
}
private String getIconUrl() {
return iconUrl;
}
} }
private static class Thumbnail { private static class Thumbnail {
private final String url; private @Getter final String url;
private Thumbnail(String url) { private Thumbnail(String url) {
this.url = url; this.url = url;
} }
private String getUrl() {
return url;
}
} }
private static class Image { private static class Image {
private final String url; private @Getter final String url;
private Image(String url) { private Image(String url) {
this.url = url; this.url = url;
} }
private String getUrl() {
return url;
}
} }
private static class Author { private static class Author {
private final String name; private @Getter final String name;
private final String url; private @Getter final String url;
private final String iconUrl; private @Getter final String iconUrl;
private Author(String name, String url, String iconUrl) { private Author(String name, String url, String iconUrl) {
this.name = name; this.name = name;
this.url = url; this.url = url;
this.iconUrl = iconUrl; this.iconUrl = iconUrl;
} }
private String getName() {
return name;
}
private String getUrl() {
return url;
}
private String getIconUrl() {
return iconUrl;
}
} }
private static class Field { private static class Field {
private final String name; private @Getter final String name;
private final String value; private @Getter final String value;
private final boolean inline; private @Getter final boolean inline;
private Field(String name, String value, boolean inline) { private Field(String name, String value, boolean inline) {
this.name = name; this.name = name;
this.value = value; this.value = value;
this.inline = inline; this.inline = inline;
} }
private String getName() {
return name;
}
private String getValue() {
return value;
}
private boolean isInline() {
return inline;
}
} }
} }

View file

@ -1,6 +1,6 @@
package me.night0721.lilase.utils; package me.night0721.lilase.utils;
import net.minecraft.client.Minecraft; import me.night0721.lilase.Lilase;
import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.ContainerChest;
@ -17,27 +17,16 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class InventoryUtils { public class InventoryUtils { public static boolean isToAuctionItem(String uuid) {
private static final Minecraft mc = Minecraft.getMinecraft(); ItemStack stack = Lilase.mc.thePlayer.openContainer.getSlot(13).getStack();
public static boolean isToAuctionItem(String name) {
final ItemStack stack = mc.thePlayer.openContainer.getSlot(13).getStack();
if (stack != null && stack.hasTagCompound()) { if (stack != null && stack.hasTagCompound()) {
final NBTTagCompound tag = stack.getTagCompound(); return stack.getTagCompound().getCompoundTag("ExtraAttributes").getString("uuid").equals(uuid);
final Pattern pattern = Pattern.compile(name, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(tag.toString());
while (matcher.find()) {
if (matcher.group(0) != null) {
return true;
}
}
} }
return false; return false;
} }
public static boolean isStoneButton() { public static boolean isStoneButton() {
final ItemStack stack = mc.thePlayer.openContainer.getSlot(13).getStack(); final ItemStack stack = Lilase.mc.thePlayer.openContainer.getSlot(13).getStack();
if (stack != null && stack.hasTagCompound()) { if (stack != null && stack.hasTagCompound()) {
final NBTTagCompound tag = stack.getTagCompound(); final NBTTagCompound tag = stack.getTagCompound();
final Pattern pattern = Pattern.compile("Click an item in your inventory!", Pattern.MULTILINE); final Pattern pattern = Pattern.compile("Click an item in your inventory!", Pattern.MULTILINE);
@ -52,8 +41,8 @@ public class InventoryUtils {
} }
public static String getInventoryName() { public static String getInventoryName() {
if (InventoryUtils.mc.currentScreen instanceof GuiChest) { if (Lilase.mc.currentScreen instanceof GuiChest) {
final ContainerChest chest = (ContainerChest) InventoryUtils.mc.thePlayer.openContainer; final ContainerChest chest = (ContainerChest) Lilase.mc.thePlayer.openContainer;
final IInventory inv = chest.getLowerChestInventory(); final IInventory inv = chest.getLowerChestInventory();
return inv.hasCustomName() ? inv.getName() : null; return inv.hasCustomName() ? inv.getName() : null;
} }
@ -61,46 +50,39 @@ public class InventoryUtils {
} }
public static boolean inventoryNameStartsWith(String startsWithString) { public static boolean inventoryNameStartsWith(String startsWithString) {
return InventoryUtils.getInventoryName() != null && InventoryUtils.getInventoryName().startsWith(startsWithString); return getInventoryName() != null && getInventoryName().startsWith(startsWithString);
} }
public static boolean inventoryNameContains(String startsWithString) { public static boolean inventoryNameContains(String startsWithString) {
return InventoryUtils.getInventoryName() != null && InventoryUtils.getInventoryName().contains(startsWithString); return getInventoryName() != null && getInventoryName().contains(startsWithString);
} }
public static void openInventory() { public static void openInventory() {
mc.displayGuiScreen(new GuiInventory(mc.thePlayer)); Lilase.mc.displayGuiScreen(new GuiInventory(Lilase.mc.thePlayer));
} }
public static ItemStack getStackInSlot(final int slot) { public static ItemStack getStackInSlot(final int slot) {
return InventoryUtils.mc.thePlayer.inventory.getStackInSlot(slot); return Lilase.mc.thePlayer.inventory.getStackInSlot(slot);
} }
public static ItemStack getStackInOpenContainerSlot(final int slot) { public static ItemStack getStackInOpenContainerSlot(final int slot) {
if (InventoryUtils.mc.thePlayer.openContainer.inventorySlots.get(slot).getHasStack()) { if (Lilase.mc.thePlayer.openContainer.inventorySlots.get(slot).getHasStack())
return InventoryUtils.mc.thePlayer.openContainer.inventorySlots.get(slot).getStack(); return Lilase.mc.thePlayer.openContainer.inventorySlots.get(slot).getStack();
}
return null; return null;
} }
public static int getSlotForItem(final String itemName) { public static int getSlotForItemm(String id) {
for (final Slot slot : mc.thePlayer.openContainer.inventorySlots) { for (final Slot slot : Lilase.mc.thePlayer.inventoryContainer.inventorySlots) {
if (slot.getHasStack()) { if (slot.getHasStack()) {
final ItemStack is = slot.getStack(); final ItemStack is = slot.getStack();
if (is.getDisplayName().contains(itemName)) { if (is.getTagCompound().getCompoundTag("ExtraAttributes").getString("uuid").equals(id)) return slot.getSlotIndex();
return slot.slotNumber;
}
} }
} }
return -1; return -1;
} }
public static void clickOpenContainerSlot(final int slot, final int button, final int clickType) { public static void clickOpenContainerSlot(final int slot, final int button, final int clickType) {
mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, slot, button, clickType, mc.thePlayer); Lilase.mc.playerController.windowClick(Lilase.mc.thePlayer.openContainer.windowId, slot, button, clickType, Lilase.mc.thePlayer);
}
public static void clickOpenContainerSlot(final int slot, final int button) {
clickOpenContainerSlot(slot, button, 0);
} }
public static void clickOpenContainerSlot(final int slot) { public static void clickOpenContainerSlot(final int slot) {
@ -110,7 +92,7 @@ public class InventoryUtils {
public static int getAvailableHotbarSlot(final String name) { public static int getAvailableHotbarSlot(final String name) {
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
final ItemStack is = mc.thePlayer.inventory.getStackInSlot(i); final ItemStack is = Lilase.mc.thePlayer.inventory.getStackInSlot(i);
if (is == null || is.getDisplayName().contains(name)) { if (is == null || is.getDisplayName().contains(name)) {
return i; return i;
} }
@ -121,7 +103,7 @@ public class InventoryUtils {
public static List<Integer> getAllSlots(final String name) { public static List<Integer> getAllSlots(final String name) {
final List<Integer> ret = new ArrayList<>(); final List<Integer> ret = new ArrayList<>();
for (int i = 9; i < 44; ++i) { for (int i = 9; i < 44; ++i) {
final ItemStack is = mc.thePlayer.inventoryContainer.inventorySlots.get(i).getStack(); final ItemStack is = Lilase.mc.thePlayer.inventoryContainer.inventorySlots.get(i).getStack();
if (is != null && is.getDisplayName().contains(name)) { if (is != null && is.getDisplayName().contains(name)) {
ret.add(i); ret.add(i);
} }
@ -131,7 +113,7 @@ public class InventoryUtils {
public static int getAmountInHotbar(final String item) { public static int getAmountInHotbar(final String item) {
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
final ItemStack is = InventoryUtils.mc.thePlayer.inventory.getStackInSlot(i); final ItemStack is = Lilase.mc.thePlayer.inventory.getStackInSlot(i);
if (is != null && StringUtils.stripControlCodes(is.getDisplayName()).equals(item)) { if (is != null && StringUtils.stripControlCodes(is.getDisplayName()).equals(item)) {
return is.stackSize; return is.stackSize;
} }
@ -141,7 +123,7 @@ public class InventoryUtils {
public static int getItemInHotbar(final String itemName) { public static int getItemInHotbar(final String itemName) {
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
final ItemStack is = InventoryUtils.mc.thePlayer.inventory.getStackInSlot(i); final ItemStack is = Lilase.mc.thePlayer.inventory.getStackInSlot(i);
if (is != null && StringUtils.stripControlCodes(is.getDisplayName()).contains(itemName)) { if (is != null && StringUtils.stripControlCodes(is.getDisplayName()).contains(itemName)) {
return i; return i;
} }
@ -152,7 +134,7 @@ public class InventoryUtils {
public static List<ItemStack> getInventoryStacks() { public static List<ItemStack> getInventoryStacks() {
final List<ItemStack> ret = new ArrayList<>(); final List<ItemStack> ret = new ArrayList<>();
for (int i = 9; i < 44; ++i) { for (int i = 9; i < 44; ++i) {
final Slot slot = InventoryUtils.mc.thePlayer.inventoryContainer.getSlot(i); final Slot slot = Lilase.mc.thePlayer.inventoryContainer.getSlot(i);
if (slot != null) { if (slot != null) {
final ItemStack stack = slot.getStack(); final ItemStack stack = slot.getStack();
if (stack != null) { if (stack != null) {
@ -166,7 +148,7 @@ public class InventoryUtils {
public static List<Slot> getInventorySlots() { public static List<Slot> getInventorySlots() {
final List<Slot> ret = new ArrayList<>(); final List<Slot> ret = new ArrayList<>();
for (int i = 9; i < 44; ++i) { for (int i = 9; i < 44; ++i) {
final Slot slot = InventoryUtils.mc.thePlayer.inventoryContainer.getSlot(i); final Slot slot = Lilase.mc.thePlayer.inventoryContainer.getSlot(i);
if (slot != null) { if (slot != null) {
final ItemStack stack = slot.getStack(); final ItemStack stack = slot.getStack();
if (stack != null) { if (stack != null) {
@ -178,17 +160,6 @@ public class InventoryUtils {
} }
public static NBTTagCompound getExtraAttributes(ItemStack item) {
if (item == null) {
throw new NullPointerException("The item cannot be null!");
}
if (!item.hasTagCompound()) {
return null;
}
return item.getSubCompound("ExtraAttributes", false);
}
public static NBTTagList getLore(ItemStack item) { public static NBTTagList getLore(ItemStack item) {
if (item == null) { if (item == null) {
throw new NullPointerException("The item cannot be null!"); throw new NullPointerException("The item cannot be null!");

View file

@ -7,12 +7,15 @@ import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent; import net.minecraft.util.IChatComponent;
import java.awt.*;
import java.net.URI;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static me.night0721.lilase.Lilase.mc; import static me.night0721.lilase.Lilase.mc;
import static me.night0721.lilase.config.AHConfig.DEBUG;
public class Utils { public class Utils {
public static IChatComponent header = null, footer = null; public static IChatComponent header = null, footer = null;
@ -42,9 +45,10 @@ public class Utils {
public static void checkFooter() { public static void checkFooter() {
if (footer != null) { if (footer != null) {
for (String line : footer.getFormattedText().split("\n")) { for (String line : footer.getUnformattedText().split("\n")) {
if (line.contains("Not active! Obtain")) { if (line.contains("Not active! Obtain")) {
cookie = EffectState.OFF; cookie = EffectState.OFF;
return;
} else { } else {
cookie = EffectState.ON; cookie = EffectState.ON;
} }
@ -54,16 +58,10 @@ public class Utils {
public static int getPurse() { public static int getPurse() {
String purse = ""; String purse = "";
List<String> matches = ScoreboardUtils.getSidebarLines().stream() List<String> matches = ScoreboardUtils.getSidebarLines().stream().map(ScoreboardUtils::cleanSB).map(PATTERN_PURSE::matcher).filter(Matcher::find).map(Matcher::group).collect(Collectors.toList());
.map(ScoreboardUtils::cleanSB)
.map(PATTERN_PURSE::matcher)
.filter(Matcher::find)
.map(Matcher::group)
.collect(Collectors.toList());
String purseline = matches.get(0); String purseline = matches.get(0);
Matcher matcher = PATTERN_PURSE.matcher(purseline); Matcher matcher = PATTERN_PURSE.matcher(purseline);
if (matcher.find()) { if (matcher.find()) {
System.out.println("Group: " + matcher.group());
purse = matcher.group(2); purse = matcher.group(2);
purse = purse.replace(",", ""); purse = purse.replace(",", "");
purse = purse.replaceAll("\\..*", ""); purse = purse.replaceAll("\\..*", "");
@ -74,13 +72,33 @@ public class Utils {
} }
public static void openURL(String url) {
String os = System.getProperty("os.name").toLowerCase();
try {
if (Desktop.isDesktopSupported()) { // Probably Windows
Desktop desktop = Desktop.getDesktop();
desktop.browse(new URI(url));
} else { // Definitely Non-windows
Runtime runtime = Runtime.getRuntime();
if (os.contains("mac")) { // Apple
runtime.exec("open " + url);
} else if (os.contains("nix") || os.contains("nux")) { // Linux
runtime.exec("xdg-open " + url);
}
}
} catch (Exception ignored) {
}
}
public static void sendMessage(String message) { public static void sendMessage(String message) {
mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.LIGHT_PURPLE + String.valueOf(EnumChatFormatting.BOLD) + "[Lilase] " + EnumChatFormatting.RESET + EnumChatFormatting.GREEN + EnumChatFormatting.BOLD + message)); mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.LIGHT_PURPLE + String.valueOf(EnumChatFormatting.BOLD) + "[Lilase] " + EnumChatFormatting.RESET + EnumChatFormatting.GREEN + EnumChatFormatting.BOLD + message));
} }
public static void debugLog(String message) { public static void debugLog(String message) {
mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.LIGHT_PURPLE + "[Lilase] " + EnumChatFormatting.RESET + EnumChatFormatting.WHITE + message)); if (DEBUG)
mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.LIGHT_PURPLE + "[Lilase] " + EnumChatFormatting.RESET + EnumChatFormatting.WHITE + message));
else System.out.println("[Lilase] " + message);
} }
public static void debugLog(String... messages) { public static void debugLog(String... messages) {

View file

@ -9,6 +9,7 @@
], ],
"client": [ "client": [
"MixinGuiIngame", "MixinGuiIngame",
"MixinGuiMainMenu",
"MixinMinecraft", "MixinMinecraft",
"MixinNetHandlerPlayClient" "MixinNetHandlerPlayClient"
] ]