Skip to content

Commit

Permalink
Fixed State Typo and Null Check when reading Chat Messages
Browse files Browse the repository at this point in the history
  • Loading branch information
May2Beez authored Dec 22, 2023
2 parents 7a34dc7 + 20241d6 commit 214fced
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 11 additions & 9 deletions src/main/java/com/jelly/farmhelperv2/feature/impl/AutoBazaar.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public boolean shouldCheckForFailsafes() {
return false;
}

public void buy(String itemName, int amount){
public void buy(String itemName, int amount) {
this.buy(itemName, amount, 0);
}

Expand Down Expand Up @@ -165,7 +165,9 @@ public void onTick(TickEvent.ClientTickEvent event) {
@SubscribeEvent
public void onChatReceive(ClientChatReceivedEvent event) {
if (event.type != 0 || !this.enabled) return;
String message = StringUtils.stripControlCodes(event.message.getUnformattedText());
if (event.message == null) return;

String message = StringUtils.stripControlCodes(event.message.getUnformattedTextForChat());
String boughtMessage = String.format("[Bazaar] Bought %dx %s for", this.buyAmount, this.itemToBuy);

if (message.startsWith(boughtMessage) && this.buyState == BuyState.BUY_VERIFY) {
Expand Down Expand Up @@ -235,10 +237,10 @@ private void handleBuyFromBz() {
return;
}
InventoryUtils.clickContainerSlot(buyInstantlySlot, InventoryUtils.ClickType.LEFT, InventoryUtils.ClickMode.PICKUP);
this.buyState = BuyState.BUY_INSTANTLY_VERIY;
this.buyState = BuyState.BUY_INSTANTLY_VERIFY;
this.timer.schedule(2000);
break;
case BUY_INSTANTLY_VERIY:
case BUY_INSTANTLY_VERIFY:
if (this.openedChestGuiNameStartsWith(this.itemToBuy + " ➜ Instant Buy")) {
log("Opened instant buy page");
this.timer.schedule(500);
Expand All @@ -261,7 +263,7 @@ private void handleBuyFromBz() {
return;
}
if (lore.contains("Loading...")) { // Makes more sense down here
this.buyState = BuyState.BUY_INSTANTLY_VERIY;
this.buyState = BuyState.BUY_INSTANTLY_VERIFY;
return;
}
}
Expand Down Expand Up @@ -377,14 +379,14 @@ private void handleSellToBz() {
if (this.openedChestGuiNameStartsWith("Bazaar ➜ ")) {
log("Opened Bz.");
this.timer.schedule(500);
this.sellState = SellState.CLICK_INSTASELLL;
this.sellState = SellState.CLICK_INSTASELL;
}

if (this.hasTimerEnded()) {
this.disable("Cannot open bz");
}
break;
case CLICK_INSTASELLL:
case CLICK_INSTASELL:
if (!this.hasTimerEnded()) return;

int sellType = this.sellTypes.get(0);
Expand Down Expand Up @@ -498,11 +500,11 @@ enum MainState {

// Insta Buy
enum BuyState {
STARTING, OPEN_BZ, BZ_VERIFY, CLICK_ON_PRODUCT, PRODUCT_VERIFY, CLICK_BUY_INSTANTLY, BUY_INSTANTLY_VERIY, OPEN_SIGN, OPEN_SIGN_VERIFY, EDIT_SIGN, VERIFY_CONFIRM_PAGE, CLICK_BUY, BUY_VERIFY, DISABLE
STARTING, OPEN_BZ, BZ_VERIFY, CLICK_ON_PRODUCT, PRODUCT_VERIFY, CLICK_BUY_INSTANTLY, BUY_INSTANTLY_VERIFY, OPEN_SIGN, OPEN_SIGN_VERIFY, EDIT_SIGN, VERIFY_CONFIRM_PAGE, CLICK_BUY, BUY_VERIFY, DISABLE
}

// Insta Sell
enum SellState {
STARTING, OPEN_BZ, BZ_VERIFY, CLICK_INSTASELLL, INSTASELL_VERIFY, CLICK_CONFIRM_INSTASELL, CONFIRM_INSTASELL_VERIFY, DISABLE
STARTING, OPEN_BZ, BZ_VERIFY, CLICK_INSTASELL, INSTASELL_VERIFY, CLICK_CONFIRM_INSTASELL, CONFIRM_INSTASELL_VERIFY, DISABLE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void onTickMainState(TickEvent.ClientTickEvent event) {
case NONE:
break;
case STARTING:
// Remove these varialbes if u need
// Remove these variables if u need
Plot currentPlot = this.plots[GameStateHandler.getInstance().getCurrentPlot()];
boolean shouldCheckPlots = Arrays.stream(this.plots).noneMatch(Objects::nonNull);
boolean sprayonatorItemNotInInventory = !InventoryUtils.hasItemInInventory(this.SPRAYONATOR_ITEM[FarmHelperConfig.autoSprayonatorType]);
Expand Down Expand Up @@ -193,7 +193,9 @@ public void onTickMainState(TickEvent.ClientTickEvent event) {
@SubscribeEvent
public void onChatReceive(ClientChatReceivedEvent event) {
if (event.type != 0 || !this.enabled) return;
String message = StringUtils.stripControlCodes(event.message.getUnformattedText());
if (event.message == null) return;

String message = StringUtils.stripControlCodes(event.message.getUnformattedTextForChat());
if (message.startsWith("SPRAYONATOR! Your selected material is now ") && this.sprayState == SprayState.SPRAYONATOR_TYPE_VERIFY) {
log("Sprayonator Material Changed");
String itemName = SPRAYONATOR_ITEM[FarmHelperConfig.autoSprayonatorType];
Expand Down

0 comments on commit 214fced

Please sign in to comment.