aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de
diff options
context:
space:
mode:
authorFluboxer <36457056+Fluboxer@users.noreply.github.com>2025-05-08 01:08:18 +0300
committerGitHub <noreply@github.com>2025-05-07 18:08:18 -0400
commit3548ce05dac929cf2037fdb6c02f09a01d13e0b2 (patch)
treeb28167df7351f1d3c097abc1120cd2b47c4cef48 /src/main/java/de
parent89031b39097f896782a2f97d3280acf66b25ed96 (diff)
downloadSkyblocker-3548ce05dac929cf2037fdb6c02f09a01d13e0b2.tar.gz
Skyblocker-3548ce05dac929cf2037fdb6c02f09a01d13e0b2.tar.bz2
Skyblocker-3548ce05dac929cf2037fdb6c02f09a01d13e0b2.zip
Confirmation Prompt Helper 2.0 (#1245)
* initial commit * Add one symbol to ConfirmationPromptHelper.java
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chat/ConfirmationPromptHelper.java48
1 files changed, 43 insertions, 5 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chat/ConfirmationPromptHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/chat/ConfirmationPromptHelper.java
index 43617774..d484e1ed 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ConfirmationPromptHelper.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ConfirmationPromptHelper.java
@@ -1,5 +1,6 @@
package de.hysky.skyblocker.skyblock.chat;
+import java.util.List;
import java.util.Optional;
import de.hysky.skyblocker.annotations.Init;
@@ -16,19 +17,45 @@ import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ConfirmationPromptHelper {
+ public static final Logger LOGGER = LoggerFactory.getLogger(ConfirmationPromptHelper.class);
+ private static final List<String> CONFIRMATION_PHRASES = List.of(
+ "[Aye sure do!]", // [NPC] Carnival Pirateman
+ "[You guessed it!]", // [NPC] Carnival Fisherman
+ "[Sure thing, partner!]", // [NPC] Carnival Cowboy
+ "YES",
+ "Yes");
+
+ // Put here full lines with formatting codes, excluding '\n' and spaces (those are trimmed)
+ // It can be extracted by logging asString or from JSON of chat message. Logs also contain it
+ private static final List<String> CONFIRMATION_PHRASES_FORMATTING = List.of(
+ "§e ➜ §a[Aye sure do!]", // [NPC] Carnival Pirateman
+ "§e ➜ §a[You guessed it!]", // [NPC] Carnival Fisherman
+ "§e ➜ §a[Sure thing, partner!]", // [NPC] Carnival Cowboy
+ "§a§l[YES]",
+ "§a[Yes]");
+
private static String command;
private static long commandFoundAt;
-
@Init
public static void init() {
ClientReceiveMessageEvents.GAME.register(ConfirmationPromptHelper::onMessage);
ScreenEvents.AFTER_INIT.register((_client, screen, _scaledWidth, _scaledHeight) -> {
//Don't check for the command being present in case the user opens the chat before the prompt is sent
if (Utils.isOnSkyblock() && screen instanceof ChatScreen && SkyblockerConfigManager.get().chat.confirmationPromptHelper) {
- ScreenMouseEvents.beforeMouseClick(screen).register((_screen1, _mouseX, _mouseY, _button) -> {
+ ScreenMouseEvents.beforeMouseClick(screen).register((_screen1, mouseX, mouseY, button) -> {
if (hasCommand()) {
+ MinecraftClient client = MinecraftClient.getInstance();
+ if (client.currentScreen instanceof ChatScreen) { // Ignore clicks on other interactive elements
+ Style style = client.inGameHud.getChatHud().getTextStyleAt(mouseX, mouseY);
+ if (style != null && style.getClickEvent() != null) { // clicking on some prompts invalidates first prompt but not in all cases, so I decided not to nullify command
+ return;
+ }
+ }
+
MessageScheduler.INSTANCE.sendMessageAfterCooldown(command, true);
command = null;
commandFoundAt = 0;
@@ -46,13 +73,24 @@ public class ConfirmationPromptHelper {
return command != null && commandFoundAt + 60_000 > System.currentTimeMillis();
}
+ private static boolean containsConfirmationPhrase(Text message) {
+ String messageStr = message.getString();
+ for (String phrase : CONFIRMATION_PHRASES) {
+ if (messageStr.contains(phrase)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private static void onMessage(Text message, boolean overlay) {
- if (Utils.isOnSkyblock() && !overlay && SkyblockerConfigManager.get().chat.confirmationPromptHelper && message.getString().contains("[YES]")) {
+ if (Utils.isOnSkyblock() && !overlay && SkyblockerConfigManager.get().chat.confirmationPromptHelper && containsConfirmationPhrase(message)) {
Optional<String> confirmationCommand = message.visit((style, asString) -> {
ClickEvent event = style.getClickEvent();
+ asString = asString.replaceAll("\\s+", " ").trim(); // clear newline '\n' and trim spaces
- //Check to see if its a yes and has the proper command
- if (asString.equals("§a§l[YES]") && event instanceof ClickEvent.RunCommand(String command) && command.startsWith("/chatprompt")) {
+ //Check to see if it has confirmation phrase and has the proper commands
+ if (CONFIRMATION_PHRASES_FORMATTING.contains(asString) && event instanceof ClickEvent.RunCommand(String command) && (command.startsWith("/chatprompt") || command.startsWith("/selectnpcoption"))) {
return Optional.of(command);
}