Skip to content

Commit

Permalink
Added guest visit failsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
onixiya1337 committed Dec 23, 2023
1 parent 4b56ed2 commit 44b2a47
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 10 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ baseGroup=com.jelly.farmhelperv2
mcVersion=1.8.9
modid=farmhelperv2
modName=FarmHelper
version=2.2.9-pre3
shouldRelease=true
version=2.2.9-pre4
shouldRelease=false
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ public class FailsafeNotificationsPage {
)
public static boolean notifyOnLowerAverageBPS = false;

@Switch(
name = "Guest Visit Notifications",
description = "Whether or not to send a notification when a guest visits your island.",
category = "Failsafe Notifications"
)
public static boolean notifyOnGuestVisit = true;

@Switch(
name = "Rotation Check Sound Alert",
description = "Whether or not to play a sound when the rotation check failsafe is triggered.",
Expand Down Expand Up @@ -171,6 +178,13 @@ public class FailsafeNotificationsPage {
)
public static boolean alertOnLowerAverageBPS = false;

@Switch(
name = "Guest Visit Alert",
description = "Whether or not to play a sound when a guest visits your island.",
category = "Failsafe Sound Alerts"
)
public static boolean alertOnGuestVisit = false;


@Switch(
name = "Rotation Check Tag Everyone",
Expand Down Expand Up @@ -256,6 +270,13 @@ public class FailsafeNotificationsPage {
)
public static boolean tagEveryoneOnLowerAverageBPS = false;

@Switch(
name = "Guest Visit Tag Everyone",
description = "Whether or not to tag everyone in the webhook message when a guest visits your island.",
category = "Failsafe Tag Everyone"
)
public static boolean tagEveryoneOnGuestVisit = false;

@Switch(
name = "Rotation Check Auto Alt-tab",
description = "Whether or not to automatically alt-tab when the rotation check failsafe is triggered.",
Expand Down Expand Up @@ -339,4 +360,10 @@ public class FailsafeNotificationsPage {
category = "Failsafe Auto Alt-tab"
)
public static boolean autoAltTabOnLowerAverageBPS = false;
@Switch(
name = "Guest Visit Alt-tab",
description = "Whether or not to automatically alt-tab when a guest visits your island.",
category = "Failsafe Auto Alt-tab"
)
public static boolean autoAltTabOnGuestVisit = false;
}
79 changes: 71 additions & 8 deletions src/main/java/com/jelly/farmhelperv2/feature/impl/Failsafe.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public void stop() {
resetWorldChangeCheck();
resetBedrockCageCheck();
resetLowerBPS();
resetGuestVisit();
sendingFailsafeInfo = false;
}

Expand Down Expand Up @@ -283,6 +284,9 @@ public void onTickFailsafe(TickEvent.ClientTickEvent event) {
case LOWER_AVERAGE_BPS:
onLowerBPS();
break;
case GUEST_VISIT:
onGuestVisit();
break;
}
}

Expand Down Expand Up @@ -1453,7 +1457,6 @@ private void onLowerBPS() {
}
Multithreading.schedule(() -> {
InventoryUtils.openInventory();
LogUtils.sendDebug("[Failsafe] Finished playing custom movement recording");
if (FarmHelperConfig.enableRestartAfterFailSafe) {
LogUtils.sendDebug("[Failsafe] Restarting the macro in " + FarmHelperConfig.restartAfterFailSafeDelay + " minutes.");
restartMacroAfterFailsafeDelay.schedule(FarmHelperConfig.restartAfterFailSafeDelay * 1_000L * 60L);
Expand All @@ -1467,6 +1470,60 @@ public void resetLowerBPS() {
lowerBPSState = LowerBPSState.NONE;
}

@SubscribeEvent
public void onChatReceived(ClientChatReceivedEvent event) {
if (firstCheckReturn()) return;
String message = StringUtils.stripControlCodes(event.message.getUnformattedText());
if (message.contains(":")) return;
if (message.contains("is visiting Your Garden") && (!GameStateHandler.getInstance().isGuestOnGarden()) && !wasGuestOnGarden) {
lastGuestName = message.replace("[SkyBlock] ", "").replace(" is visiting Your Garden!", "");
wasGuestOnGarden = true;
tabListCheckDelay.schedule(5000L);
addEmergency(EmergencyType.GUEST_VISIT);
if (!FarmHelperConfig.pauseWhenGuestArrives)
Multithreading.schedule(() -> {
if (emergency == EmergencyType.GUEST_VISIT) {
Failsafe.getInstance().stop();
MacroHandler.getInstance().resumeMacro();
}
}, chooseEmergencyDelay.getRemainingTime() + 100L, TimeUnit.MILLISECONDS);
}
}

public void onGuestVisit() {
tabListCheckDelay.schedule(5000L);
if (FarmHelperConfig.pauseWhenGuestArrives) {
if (!MacroHandler.getInstance().isCurrentMacroPaused()) {
LogUtils.sendFailsafeMessage("[Failsafe] Paused the macro because of guest visit!", false);
MacroHandler.getInstance().pauseMacro();
}
}
}

private final Clock tabListCheckDelay = new Clock();
private boolean wasGuestOnGarden = false;
private String lastGuestName = "";

public void resetGuestVisit() {
tabListCheckDelay.reset();
wasGuestOnGarden = false;
lastGuestName = "";
}

@SubscribeEvent
public void onTickCheckGuests(TickEvent.ClientTickEvent event) {
if (mc.thePlayer == null || mc.theWorld == null) return;
if (!isEmergency()) return;
if (tabListCheckDelay.isScheduled() && !tabListCheckDelay.passed()) return;
if (!GameStateHandler.getInstance().isGuestOnGarden()
&& GameStateHandler.getInstance().getLocation() == GameStateHandler.Location.GARDEN
&& wasGuestOnGarden) {
LogUtils.sendFailsafeMessage("[Failsafe] Resuming the macro because guest visit is over!", false);
Failsafe.getInstance().stop();
MacroHandler.getInstance().resumeMacro();
}
}

private boolean firstCheckReturn() {
if (mc.thePlayer == null || mc.theWorld == null) return true;
if (!MacroHandler.getInstance().isMacroToggled()) return true;
Expand Down Expand Up @@ -1570,14 +1627,12 @@ private boolean shouldNotify(EmergencyType emergency) {
return FailsafeNotificationsPage.notifyOnTestFailsafe;
case LOWER_AVERAGE_BPS:
return FailsafeNotificationsPage.notifyOnLowerAverageBPS;
case GUEST_VISIT:
return FailsafeNotificationsPage.notifyOnGuestVisit;
}
return false;
}

// endregion

// region JACOB

private boolean shouldPlaySoundAlert(EmergencyType emergency) {
switch (emergency) {
case ROTATION_CHECK:
Expand All @@ -1602,6 +1657,10 @@ private boolean shouldPlaySoundAlert(EmergencyType emergency) {
return FailsafeNotificationsPage.alertOnJacobFailsafe;
case TEST:
return FailsafeNotificationsPage.alertOnTestFailsafe;
case LOWER_AVERAGE_BPS:
return FailsafeNotificationsPage.alertOnLowerAverageBPS;
case GUEST_VISIT:
return FailsafeNotificationsPage.alertOnGuestVisit;
}
return false;
}
Expand Down Expand Up @@ -1632,12 +1691,12 @@ private boolean shouldAltTab(EmergencyType emergency) {
return FailsafeNotificationsPage.autoAltTabOnTestFailsafe;
case LOWER_AVERAGE_BPS:
return FailsafeNotificationsPage.autoAltTabOnLowerAverageBPS;
case GUEST_VISIT:
return FailsafeNotificationsPage.autoAltTabOnGuestVisit;
}
return false;
}

// endregion

private boolean shouldTagEveryone(EmergencyType emergency) {
switch (emergency) {
case ROTATION_CHECK:
Expand All @@ -1664,6 +1723,8 @@ private boolean shouldTagEveryone(EmergencyType emergency) {
return FailsafeNotificationsPage.tagEveryoneOnTestFailsafe;
case LOWER_AVERAGE_BPS:
return FailsafeNotificationsPage.tagEveryoneOnLowerAverageBPS;
case GUEST_VISIT:
return FailsafeNotificationsPage.tagEveryoneOnGuestVisit;
}
return false;
}
Expand All @@ -1681,7 +1742,9 @@ public enum EmergencyType {
BANWAVE("Banwave has been detected!", 6),
DISCONNECT("You've been§l DISCONNECTED§r§d from the server!", 1),
LOWER_AVERAGE_BPS("Your BPS is lower than average!", 9),
JACOB("You've extended the §lJACOB COUNTER§r§d!", 7);
JACOB("You've extended the §lJACOB COUNTER§r§d!", 7),
GUEST_VISIT("You've got§l VISITED§r§d by "
+ (!getInstance().lastGuestName.isEmpty() ? getInstance().lastGuestName : "a guest") + "!", 1);

final String label;
// 1 is highest priority
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/jelly/farmhelperv2/handler/GameStateHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,25 @@ public boolean inJacobContest() {
return false;
}

public boolean isGuestOnGarden() {
if (mc.theWorld == null || mc.thePlayer == null) return false;
for (String line : ScoreboardUtils.getScoreboardLines()) {
String cleanedLine = ScoreboardUtils.cleanSB(line);
if ((cleanedLine.toLowerCase()).contains("✌ (")) {
return true;
}
}
boolean hasGuestsOnTabList = false;
for (String name : TablistUtils.getTabList()) {
if (StringUtils.stripControlCodes(name).contains("Guests "))
hasGuestsOnTabList = true;
if (StringUtils.stripControlCodes(name).contains("Guests (0)")) {
return false;
}
}
return hasGuestsOnTabList && location == Location.GARDEN;
}

@Getter
public enum Location {
PRIVATE_ISLAND("Private Island"),
Expand Down

0 comments on commit 44b2a47

Please sign in to comment.