refactoring AuctionHouse to Sniper as it is more readable

This commit is contained in:
NK 2023-03-08 11:57:14 +00:00
parent 49271e9d49
commit 4896221d19
5 changed files with 32 additions and 32 deletions

View file

@ -3,12 +3,12 @@ package me.night0721.lilase;
import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.events.event.InitializationEvent;
import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
import me.night0721.lilase.events.SniperFlipperEvents;
import me.night0721.lilase.config.AHConfig;
import me.night0721.lilase.features.sniper.AuctionHouse;
import me.night0721.lilase.config.ConfigUtils;
import me.night0721.lilase.events.SniperFlipperEvents;
import me.night0721.lilase.features.sniper.Sniper;
import me.night0721.lilase.gui.ImageRenderer;
import me.night0721.lilase.utils.Clock;
import me.night0721.lilase.config.ConfigUtils;
import me.night0721.lilase.utils.KeyBindingManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiDisconnected;
@ -33,7 +33,7 @@ public class Lilase {
public static final String MODID = "Lilase";
public static final String VERSION = "1.0.26";
public static final Minecraft mc = Minecraft.getMinecraft();
public static AuctionHouse auctionHouse;
public static Sniper sniper;
public static AHConfig config;
private int tickAmount;
private final Clock clock = new Clock();
@ -47,7 +47,7 @@ public class Lilase {
MinecraftForge.EVENT_BUS.register(new SniperFlipperEvents());
MinecraftForge.EVENT_BUS.register(new ImageRenderer());
EventManager.INSTANCE.register(this);
auctionHouse = new AuctionHouse();
sniper = new Sniper();
keyBindingManager.registerKeyBindings();
}
@ -60,9 +60,9 @@ public class Lilase {
public void onTick(TickEvent.ClientTickEvent event) throws IOException {
if (mc.thePlayer == null || event.phase != TickEvent.Phase.START) return;
tickAmount++;
if (tickAmount % (20 * AUCTION_HOUSE_DELAY) == 0) auctionHouse.getItem();
if (tickAmount % (20 * AUCTION_HOUSE_DELAY) == 0) sniper.getItem();
if (tickAmount % 2400 == 0) ConfigUtils.checkWebhookAndAPI();
if (AuctionHouse.flipper != null) AuctionHouse.flipper.switchStates();
if (Sniper.flipper != null) Sniper.flipper.switchStates();
if (mc.currentScreen instanceof GuiDisconnected) {
if (clock.passed()) {
clock.schedule(RECONNECT_DELAY * 1000L);

View file

@ -35,7 +35,7 @@ import static me.night0721.lilase.config.AHConfig.GUI_COLOR;
import static me.night0721.lilase.config.AHConfig.SEND_MESSAGE;
import static me.night0721.lilase.features.flipper.Flipper.rotation;
import static me.night0721.lilase.features.flipper.FlipperState.START;
import static me.night0721.lilase.features.sniper.AuctionHouse.flipper;
import static me.night0721.lilase.features.sniper.Sniper.flipper;
import static me.night0721.lilase.utils.PlayerUtils.sendPacketWithoutEvent;
public class SniperFlipperEvents {
@ -74,7 +74,7 @@ public class SniperFlipperEvents {
bought = false;
Utils.debugLog("[Sniper] Bought an item, starting to sell");
try {
if (SEND_MESSAGE) Lilase.auctionHouse.webhook.execute();
if (SEND_MESSAGE) Lilase.sniper.webhook.execute();
} catch (Exception e) {
System.out.println("Failed to send webhook");
}
@ -90,18 +90,18 @@ public class SniperFlipperEvents {
InventoryUtils.clickOpenContainerSlot(13);
Lilase.mc.thePlayer.closeScreen();
Utils.debugLog("[Flipper] Cannot post item as the cost is too low, stopping fliiper and starting sniper");
Lilase.auctionHouse.toggleAuction();
Lilase.sniper.toggleAuction();
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("[Flipper] Cannot post item as the cost is too low, stopping fliiper and starting sniper");
Lilase.auctionHouse.toggleAuction();
Lilase.sniper.toggleAuction();
Flipper.state = FlipperState.NONE;
} else if (message.contains("You were spawned in Limbo")) {
Utils.sendMessage("Detected in Limbo, stopping everything for 5 minutes");
Utils.addTitle("You got sent to Limbo!");
Flipper.state = FlipperState.NONE;
if (Lilase.auctionHouse.getOpen()) Lilase.auctionHouse.toggleAuction();
if (Lilase.sniper.getOpen()) Lilase.sniper.toggleAuction();
Thread.sleep(5000);
Utils.sendServerMessage("/lobby");
Thread.sleep(5000);
@ -109,7 +109,7 @@ public class SniperFlipperEvents {
Thread bzchillingthread = new Thread(bazaarChilling);
bzchillingthread.start();
} else if (matcher.matches() && postedNames.contains(matcher.group(2))) {
Lilase.auctionHouse.incrementAuctionsFlipped();
Lilase.sniper.incrementAuctionsFlipped();
}
}
}
@ -152,7 +152,7 @@ public class SniperFlipperEvents {
}
Lilase.mc.thePlayer.sendChatMessage("/hub");
Thread.sleep(6000);
Lilase.auctionHouse.toggleAuction();
Lilase.sniper.toggleAuction();
} catch (Exception ignore) {
}
@ -175,7 +175,7 @@ public class SniperFlipperEvents {
Thread.sleep(500);
Lilase.mc.thePlayer.closeScreen();
Flipper.state = FlipperState.NONE;
Lilase.auctionHouse.toggleAuction();
Lilase.sniper.toggleAuction();
} catch (InterruptedException e) {
e.printStackTrace();
}
@ -195,7 +195,7 @@ public class SniperFlipperEvents {
int minute = cal.get(Calendar.MINUTE);
String time = String.format("%02d:%02d", hour, minute);
int days = (int) (Lilase.mc.theWorld.getWorldTime() / 24000);
String lines = "X: " + Math.round(Lilase.mc.thePlayer.posX) + "\n" + "Y: " + Math.round(Lilase.mc.thePlayer.posY) + "\n" + "Z: " + Math.round(Lilase.mc.thePlayer.posZ) + "\n" + time + "\n" + "FPS: " + Minecraft.getDebugFPS() + "\n" + "Day: " + days + "\n" + "Auctions Sniped: " + Lilase.auctionHouse.getAuctionsSniped() + "\n" + "Auctions Posted: " + Lilase.auctionHouse.getAuctionsPosted() + "\n" + "Auctions Flipped: " + Lilase.auctionHouse.getAuctionsFlipped() + "\n";
String lines = "X: " + Math.round(Lilase.mc.thePlayer.posX) + "\n" + "Y: " + Math.round(Lilase.mc.thePlayer.posY) + "\n" + "Z: " + Math.round(Lilase.mc.thePlayer.posZ) + "\n" + time + "\n" + "FPS: " + Minecraft.getDebugFPS() + "\n" + "Day: " + days + "\n" + "Auctions Sniped: " + Lilase.sniper.getAuctionsSniped() + "\n" + "Auctions Posted: " + Lilase.sniper.getAuctionsPosted() + "\n" + "Auctions Flipped: " + Lilase.sniper.getAuctionsFlipped() + "\n";
TextRenderer.drawString(lines, 0, 0, 0.9, GUI_COLOR.getRGB());
}
}
@ -231,7 +231,7 @@ public class SniperFlipperEvents {
if (buying && "Confirm Purchase".equals(windowName)) {
Lilase.mc.playerController.windowClick(windowId + 1, 11, 0, 0, Lilase.mc.thePlayer);
buying = false;
if (Lilase.auctionHouse.buying) bought = true;
if (Lilase.sniper.buying) bought = true;
}
}
}

View file

@ -46,9 +46,9 @@ public class Flipper {
}
public void sellItem() {
Lilase.auctionHouse.incrementAuctionsSniped();
Lilase.sniper.incrementAuctionsSniped();
Utils.sendMessage("Flipper is running, stopping, will resume when flipper is done");
if (Lilase.auctionHouse.getOpen()) Lilase.auctionHouse.toggleAuction();
if (Lilase.sniper.getOpen()) Lilase.sniper.toggleAuction();
UngrabUtils.ungrabMouse();
Utils.sendServerMessage("/hub");
state = FlipperState.WALKING_TO_FIRST_POINT;
@ -105,7 +105,7 @@ public class Flipper {
if (InventoryUtils.getSlotForItem(itemname) == -1) {
Utils.debugLog("[Flipper] Cannot find item in inventory, stopping flipper");
state = FlipperState.NONE;
Lilase.auctionHouse.setOpen(true);
Lilase.sniper.setOpen(true);
return;
}
InventoryUtils.clickOpenContainerSlot(InventoryUtils.getSlotForItem(itemname));
@ -131,14 +131,14 @@ public class Flipper {
buyWait.schedule(1000);
} else if (InventoryUtils.inventoryNameContains("BIN Auction View") && buyWait.passed()) {
InventoryUtils.clickOpenContainerSlot(49);
Lilase.auctionHouse.incrementAuctionsPosted();
Lilase.sniper.incrementAuctionsPosted();
SniperFlipperEvents.postedNames.add(itemname);
buyWait.schedule(500);
Lilase.mc.thePlayer.closeScreen();
buyWait.schedule(500);
Utils.sendMessage("Posted item on Auction House, continue sniping now");
state = FlipperState.NONE;
Lilase.auctionHouse.toggleAuction();
Lilase.sniper.toggleAuction();
}
case NONE:
break;

View file

@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit;
import static me.night0721.lilase.config.AHConfig.SEND_MESSAGE;
public class AuctionHouse {
public class Sniper {
private Boolean open = false;
public Boolean buying = false;
private int auctionsSniped = 0;
@ -39,7 +39,7 @@ public class AuctionHouse {
private final ThreadLocalRandom randomSlot;
public static Flipper flipper;
public AuctionHouse() {
public Sniper() {
for (int i = 1; i <= 99; i++) {
if (!ConfigUtils.getString("item" + i, "Name").equals("") && !ConfigUtils.getString("item" + i, "Type").equals("") && !ConfigUtils.getString("item" + i, "Tier").equals("") && ConfigUtils.getInt("item" + i, "Price") != 0){
try {
@ -84,27 +84,27 @@ public class AuctionHouse {
Utils.checkFooter();
if (Utils.cookie != EffectState.ON && !Utils.checkInHub()) {
Utils.sendMessage("You have no cookie but you are not in hub, stopping");
open = false;
setOpen(false);
return;
}
if (items.size() == 0) {
Utils.sendMessage("No Item queued, stopping");
open = false;
setOpen(false);
return;
}
if (ConfigUtils.getString("main", "APIKey").equals("") || ConfigUtils.getString("main", "Webhook").equals("")) {
Utils.sendMessage("Missing APIKey, stopping");
open = false;
setOpen(false);
return;
}
if (SEND_MESSAGE && ConfigUtils.getString("main", "Webhook").equals("")) {
Utils.sendMessage("Sending message to Webhook is on but Webhook is missing, stopping");
open = false;
setOpen(false);
return;
}
if (Flipper.state != FlipperState.NONE) {
Utils.sendMessage("Flipper is running, stopping");
open = false;
setOpen(false);
return;
}
if (Lilase.mc.currentScreen != null) Lilase.mc.thePlayer.closeScreen();
@ -239,12 +239,12 @@ public class AuctionHouse {
public void toggleAuction() {
if (open) {
Utils.sendMessage("Stopped AH Sniper");
open = false;
setOpen(false);
UngrabUtils.regrabMouse();
} else {
if (Utils.checkInHub()) {
Utils.sendMessage("Started AH Sniper");
open = true;
setOpen(true);
UngrabUtils.ungrabMouse();
} else Utils.sendMessage("Detected not in hub, please go to hub to start");
}

View file

@ -21,7 +21,7 @@ public class KeyBindingManager {
@SubscribeEvent
public void onKeyPress(InputEvent.KeyInputEvent event) {
if (keyBindings[0].isPressed()) {
Lilase.auctionHouse.toggleAuction();
Lilase.sniper.toggleAuction();
}
if (keyBindings[1].isPressed()) {
Lilase.config.openGui();