Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed case where some pests are on plots and some pets are not #143

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class PestsDestroyer implements IFeature {
@Getter
private Optional<Entity> currentEntityTarget = Optional.empty();
@Getter
private int amountOfPests = 0;
private int totalPests = 0;
private boolean enabled = false;
private boolean preparing = false;
@Setter
Expand Down Expand Up @@ -159,7 +159,7 @@ public void resetStatesAfterMacroDisabled() {
pestsPlotMap.clear();
preparing = false;
enabled = false;
amountOfPests = 0;
totalPests = 0;
lastFireworkTime = 0;
rotationType = RotationType.NONE;
state = States.IDLE;
Expand All @@ -180,7 +180,7 @@ public boolean canEnableMacro() {
if (!GameStateHandler.getInstance().inGarden()) return false;
if (!MacroHandler.getInstance().isMacroToggled()) return false;
if (enabled || preparing) return false;
if (amountOfPests < FarmHelperConfig.startKillingPestsAt) return false;
if (totalPests < FarmHelperConfig.startKillingPestsAt) return false;

return PlayerUtils.isStandingOnSpawnPoint() || PlayerUtils.isStandingOnRewarpLocation();
}
Expand Down Expand Up @@ -323,7 +323,7 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
return;
}
int pestsInMap = pestsPlotMap.values().stream().mapToInt(i -> i).sum();
if (pestsInMap < amountOfPests) {
if (pestsInMap == 0) {
state = States.OPEN_DESK;
} else {
state = States.TELEPORT_TO_PLOT;
Expand Down Expand Up @@ -644,11 +644,18 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
}
break;
case CHECK_ANOTHER_PEST:
LogUtils.sendDebug(amountOfPests + " pest" + (amountOfPests == 1 ? "" : "s") + " left");
if (amountOfPests == 0) {
// remove 1 from count because we send message before scoreboard update
LogUtils.sendDebug((totalPests-1) + " pest" + (totalPests == 2 ? "" : "s") + " left");
if (totalPests == 0) {
state = States.GO_BACK;
} else {
state = States.TELEPORT_TO_PLOT;
if (pestsPlotMap.isEmpty())
{
LogUtils.sendDebug("Manually searching for pest");
state = States.GET_LOCATION;
} else {
state = States.TELEPORT_TO_PLOT;
}
}
KeyBindUtils.stopMovement();
delayClock.schedule(1_500 + (long) (Math.random() * 1_000));
Expand Down Expand Up @@ -929,25 +936,25 @@ public void onTick(TickEvent.ClientTickEvent event) {
try {
String pests = split[split.length - 1].replace("x", "").trim();
int pestsAmount = Integer.parseInt(pests);
if (pestsAmount != amountOfPests) {
amountOfPests = pestsAmount;
if (!isRunning() && amountOfPests >= FarmHelperConfig.startKillingPestsAt) {
if (pestsAmount != totalPests) {
totalPests = pestsAmount;
if (!isRunning() && totalPests >= FarmHelperConfig.startKillingPestsAt) {
if (FarmHelperConfig.sendWebhookLogIfPestsDetectionNumberExceeded) {
LogUtils.webhookLog("[Pests Destroyer]\\nThere " + (amountOfPests > 1 ? "are" : "is") + " currently **" + amountOfPests + "** " + (amountOfPests > 1 ? "pests" : "pest") + " in the garden!", FarmHelperConfig.pingEveryoneOnPestsDetectionNumberExceeded);
LogUtils.webhookLog("[Pests Destroyer]\\nThere " + (totalPests > 1 ? "are" : "is") + " currently **" + totalPests + "** " + (totalPests > 1 ? "pests" : "pest") + " in the garden!", FarmHelperConfig.pingEveryoneOnPestsDetectionNumberExceeded);
}
if (FarmHelperConfig.sendNotificationIfPestsDetectionNumberExceeded) {
FailsafeUtils.getInstance().sendNotification("There " + (amountOfPests > 1 ? "are" : "is") + " currently " + amountOfPests + " " + (amountOfPests > 1 ? "pests" : "pest") + " in the garden!", TrayIcon.MessageType.WARNING);
FailsafeUtils.getInstance().sendNotification("There " + (totalPests > 1 ? "are" : "is") + " currently " + totalPests + " " + (totalPests > 1 ? "pests" : "pest") + " in the garden!", TrayIcon.MessageType.WARNING);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (line.contains("Garden") || line.contains("Plot")) {
amountOfPests = 0;
totalPests = 0;
}
}
if (amountOfPests == 0) {
if (totalPests == 0) {
pestsPlotMap.clear();
}
}
Expand Down Expand Up @@ -1014,7 +1021,6 @@ public void onGuiOpen(DrawScreenAfterEvent event) {
} else if (StringUtils.stripControlCodes(slot.getStack().getDisplayName()).equals("The Barn"))
plotCounter++;
}

Slot slot = guiChest.inventorySlots.get(42); // last plot in gui
if (slot != null && slot.getHasStack() && slot.getStack().getDisplayName().contains("Plot")) {
if (pestsPlotMap.isEmpty()) {
Expand All @@ -1032,8 +1038,8 @@ public void onGuiOpen(DrawScreenAfterEvent event) {
}
}
}
int pestsInMap = pestsPlotMap.values().stream().mapToInt(i -> i).sum();
if (pestsInMap < amountOfPests) return;
int foundPests = pestsPlotMap.values().stream().mapToInt(i -> i).sum();
if (foundPests == 0) return;
for (Map.Entry<Integer, Integer> plot : pestsPlotMap.entrySet()) {
if (plot.getValue() > 0) {
LogUtils.sendDebug("Found plot with pests: " + plot.getKey() + " with " + plot.getValue() + " pests");
Expand All @@ -1053,7 +1059,7 @@ public void onGuiOpen(DrawScreenAfterEvent event) {
@SubscribeEvent
public void onWorldUnload(WorldEvent.Unload event) {
pestsPlotMap.clear();
amountOfPests = 0;
totalPests = 0;
}

enum States {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jelly/farmhelperv2/hud/StatusHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ protected void getLines(List<String> lines, boolean example) {
List<String> tempLines = new ArrayList<>();
tempLines.add(getStatusString());

if (PestsDestroyer.getInstance().getAmountOfPests() > 0) {
tempLines.add("Pests in Garden: " + PestsDestroyer.getInstance().getAmountOfPests());
if (PestsDestroyer.getInstance().getTotalPests() > 0) {
tempLines.add("Pests in Garden: " + PestsDestroyer.getInstance().getTotalPests());
}

if (BanInfoWS.getInstance().isRunning() && FarmHelperConfig.banwaveCheckerEnabled && BanInfoWS.getInstance().isConnected()) {
Expand Down