GeorgH93 / MarriageMaster

Marriage Plugin for Bukkit/Spigot
https://www.spigotmc.org/resources/marriage-master.19273/
GNU General Public License v3.0
113 stars 90 forks source link

Messages with "JSON" strings are displayed with previous hover and click events. :((( #234

Closed Qveshn closed 2 years ago

Qveshn commented 2 years ago

Information

Environment information Plugin + server version info:

>marry version
[04:39:30] [Server thread/INFO]: ##### Start Marriage Master version info #####
[04:39:30] [Server thread/INFO]: Marriage Master: 2.5.1-Release
[04:39:30] [Server thread/INFO]: Server: 3284-Spigot-3892929-0ebef35 (MC: 1.17.1)
[04:39:30] [Server thread/INFO]: Java: 16.0.2
[04:39:30] [Server thread/INFO]: PlaceholderAPI: 2.10.10
[04:39:30] [Server thread/INFO]: #####  End Marriage Master version info  #####

Online mode: no

BungeeCord: yes

Server/crash log

no

Plugin config (optional)

config.yml -> Language -> Language: en

Details

Description
When I use /marry list, then it shows the list and the footer like: <<< Previous <<< Showing page ../.. >>> Next >>> But The second part of the message "Showing page ../.." contains hover text and click event from the first part. 😟

Steps to reproduce

  1. Set language to "en" in your config
  2. Remove en.yml (to be sure you will get the original file from plugin)
  3. Restart the server or reload plugin.
  4. Make atleast one marriage (if there are no married players)
  5. Run command from client: /marry list

You will see the list in chat and the footer: <<< Previous <<< Showing page ../.. >>> Next >>>

  1. Move mouse over "Showing page" part and you will see the hover text from the "previous" part, The click event also will be from the first part of the message.

Expected behavior
I expected not to see any hover text and click event in the second part of the message, because "Footer" parameter in en.yml does not contain it.

Other information (more details)

en.yml contains:

Language:
  ...
  Ingame:
    ...
    List:
      ...
      Footer: "[{\"text\":\"<<< Previous <<<\",\"color\":\"gray\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/{MainCommand} {SubCommand} {PrevPage}\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"/{MainCommand} {SubCommand} {PrevPage}\"}},{\"text\":\" Showing page {CurrentPage}/{MaxPage} \",\"color\":\"gold\"},{\"text\":\">>> Next >>>\",\"color\":\"gray\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/{MainCommand} {SubCommand} {NextPage}\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"/{MainCommand} {SubCommand} {NextPage}\"}}]"

The en.yml was not modified. It is come from plugin jar-file.

The "footer" message is a json object. I have formated it here to make easy to read it:

[
    {
        "text": "<<< Previous <<<",
        "color": "gray",
        "clickEvent": {
            "action": "run_command",
            "value": "/{MainCommand} {SubCommand} {PrevPage}"
        },
        "hoverEvent": {
            "action": "show_text",
            "value": "/{MainCommand} {SubCommand} {PrevPage}"
        }
    },
    {
        "text": " Showing page {CurrentPage}/{MaxPage} ",
        "color": "gold"
    },
    {
        "text": ">>> Next >>>",
        "color": "gray",
        "clickEvent": {
            "action": "run_command",
            "value": "/{MainCommand} {SubCommand} {NextPage}"
        },
        "hoverEvent": {
            "action": "show_text",
            "value": "/{MainCommand} {SubCommand} {NextPage}"
        }
    }
]

As we see, there are 3 main sections (previous, current, next) The second section (current) does not contain "clickEvent" and "hoverEvent" components. Therefore I expected to see 3 parts of the message with next functionality:

  1. "<<< Previous <<<" with hover and click event
  2. "Showing page ../.." without hover and click event
  3. ">>> Next >>>" with hover and click event

But I see the second part "Showing page ../.." also with hover and click event from the first part 😟

IMHO: I think there is a bug with parsing json from the string. As I understood "PluginLib" from your jar-file do it using predefined schema for chat message. And it does not clear the previous component attributes while parsing the next one. If I set "clickEvent" and "hoverEvent" in the second section with properly formed values, then I will see them on the client. If I set "clickEvent" and "hoverEvent" to null values, then I see the exception like: com.google.gson.JsonSyntaxException: Expected clickEvent to be a JsonObject, was null (json) if I delete "clickEvent" and "hoverEvent" (as in original en.yml) or set them to empty object like clickEvent: {} then I will see them again with values from the first part of the message

Qveshn commented 2 years ago

Hmm... just noticed...

If I insert the first component as text without hover and click events, then everything works fine 😕 Example 1:

[
    "",
    {
        "text": "<<< Previous <<<",
        "color": "gray",
        "clickEvent": {
            "action": "run_command",
            "value": "/{MainCommand} {SubCommand} {PrevPage}"
        },
        "hoverEvent": {
            "action": "show_text",
            "value": "/{MainCommand} {SubCommand} {PrevPage}"
        }
    },
    {
        "text": " Showing page {CurrentPage}/{MaxPage} ",
        "color": "gold"
    },
    {
        "text": ">>> Next >>>",
        "color": "gray",
        "clickEvent": {
            "action": "run_command",
            "value": "/{MainCommand} {SubCommand} {NextPage}"
        },
        "hoverEvent": {
            "action": "show_text",
            "value": "/{MainCommand} {SubCommand} {NextPage}"
        }
    }
]

Example 2:

[
    {
        "text": ""
    },
    {
        "text": "<<< Previous <<<",
        "color": "gray",
        "clickEvent": {
            "action": "run_command",
            "value": "/{MainCommand} {SubCommand} {PrevPage}"
        },
        "hoverEvent": {
            "action": "show_text",
            "value": "/{MainCommand} {SubCommand} {PrevPage}"
        }
    },
    {
        "text": " Showing page {CurrentPage}/{MaxPage} ",
        "color": "gold"
    },
    {
        "text": ">>> Next >>>",
        "color": "gray",
        "clickEvent": {
            "action": "run_command",
            "value": "/{MainCommand} {SubCommand} {NextPage}"
        },
        "hoverEvent": {
            "action": "show_text",
            "value": "/{MainCommand} {SubCommand} {NextPage}"
        }
    }
]

Also I have done some experiments and found out next: If one of the message components does not contain "clickEvent" or "hoverEvent", then it will be taken from the first component of the message 😕 😕 😕

Is this client or plugin bug? Can you check what json message is sent to client exactly?

If this is client bug, then I advise you to insert additionally to all "json" messages at the beginning of its array the first component as text "" (empty string), if it is missing

GeorgH93 commented 2 years ago

Thanks for the info. Looks like Mojang changed the behavior of this (used to only carry over formatting, not the events), I will update the bundled yml files accordingly.

Qveshn commented 2 years ago

Thanks