Skip to content

Enhance /grim sendalert with Hybrid MiniMessage & Legacy Formatting#2141

Draft
GigaZelensky wants to merge 3 commits into
GrimAnticheat:2.0from
GigaZelensky:patch-5
Draft

Enhance /grim sendalert with Hybrid MiniMessage & Legacy Formatting#2141
GigaZelensky wants to merge 3 commits into
GrimAnticheat:2.0from
GigaZelensky:patch-5

Conversation

@GigaZelensky
Copy link
Copy Markdown
Contributor

This PR updates the /grim sendalert command to support both MiniMessage and traditional legacy & color code formatting for staff alerts. This allows for richer alert messages using features like hover/click events and gradients, while maintaining compatibility with existing legacy formatted messages.

Changes

  • Input Pre-processing:

    • Trims whitespace and strips optional wrapping quotes ("/') from the input message.
    • Replaces standard %placeholders%.
    • Translates legacy & color codes to § section codes. This helps the MiniMessage parser correctly interpret legacy codes embedded within MiniMessage tag attributes (e.g., hover_text).
  • Hybrid Parsing Strategy:

    1. MiniMessage Attempt: The pre-processed string (with § codes) is first parsed using a strict MiniMessage instance.
      • If MiniMessage tags are successfully processed, this result is used.
      • If no MiniMessage tags were effectively applied (e.g., the input was pure legacy like &cHello), the logic proceeds to the fallback.
    2. Legacy/Fallback (MessageUtil.miniMessage):
      • If the MiniMessage attempt indicates the input was pure legacy/plain text, MessageUtil.miniMessage() is used with the original (pre-§ translation) string to ensure correct legacy & code handling.
      • If the strict MiniMessage parser encounters an exception (e.g., malformed MiniMessage or a complex mix it can't handle), MessageUtil.miniMessage() is used as a fallback with the original string.

This ensures pure MiniMessage, pure legacy codes, and MiniMessage containing embedded legacy codes are all handled appropriately.

How to Test

  1. Legacy: /grim sendalert &cLegacy &lAlert
    • Expected: Colored and bolded alert.
  2. MiniMessage: /grim sendalert "<red>MiniMessage <click:run_command:/say Test>Click</click>"
    • Expected: Red text, clickable "Click".
  3. MiniMessage with & in attributes: /grim sendalert "<hover:show_text:'&aTooltip &6Example'>Hover Me</hover>"
    • Expected: "Hover Me" displays; hovering shows colored "Tooltip Example".
  4. Quoted Input: /grim sendalert ""'<blue>Quoted MiniMessage</blue>'""
    • Expected: Blue "Quoted MiniMessage", quotes are stripped.

This provides a robust and flexible way for staff to create alerts, without impacting any current configurations.

@ManInMyVan
Copy link
Copy Markdown
Contributor

MessageUtil.miniMessage already handles legacy formatting codes

@GigaZelensky
Copy link
Copy Markdown
Contributor Author

GigaZelensky commented May 31, 2025

MessageUtil.miniMessage already handles legacy formatting codes

the sendalert command doesn't handle minimessage tho

@GigaZelensky
Copy link
Copy Markdown
Contributor Author

GigaZelensky commented May 31, 2025

(This isn't ready yet too) i tested on lightninggrim and it doesnt work on here lmao

edit: i think the reason it's not working is because packetevents broke it: retrooper/packetevents#1241

i love my life

Edit 2: More research has led me to conclude the issue is somehow packetevents. I guess I'll wait for a fix...

@ManInMyVan
Copy link
Copy Markdown
Contributor

ManInMyVan commented May 31, 2025

the sendalert command doesn't handle minimessage tho

it does

@GigaZelensky
Copy link
Copy Markdown
Contributor Author

the sendalert command doesn't handle minimessage tho

it does

i might just be stupid ill test it further lol

@GigaZelensky
Copy link
Copy Markdown
Contributor Author

I would like to take this moment of utter stupidity to address the fact that hovering and clicking does not work with current PacketEvents. Or maybe I'm just being stupid again lol.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants