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

Fix ShutdownCommand message styling #1427

Open
wants to merge 3 commits into
base: dev/3.0.0
Choose a base branch
from

Conversation

456dev
Copy link
Contributor

@456dev 456dev commented Sep 14, 2024

the docs specify the command as accepting json components, as well as minimessage
in the previous implementation, neither were true, as the minimessage deserialisation after parsing legacy escaped any tags internally.

This PR fixes that by only deserialising the string once before parsing it on.
due to this, legacy "&" support has been removed

to support parsing as both minimessage + json, parsing as json will only kick in if it looks like a valid json text component:

  • "plain format, starting with a quote."
  • {"text":"Object format, starting with a curly brace"}
  • ["Array format", {"text": "starting with a square bracket"}]

Docs PR: PaperMC/docs#493

));
Component reasonComponent = null;

if (reason.startsWith("{") || reason.startsWith("[") || reason.startsWith("\"")) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should do it like this?

        char firstChar = reason.charAt(0);
        char lastChar = reason.charAt(reason.length() - 1);

        if ((firstChar == '{' && lastChar == '}')
                || (firstChar == '[' && lastChar == ']')
                || (firstChar == '"' && lastChar == '"')) {
                try {
                    reasonComponent = GsonComponentSerializer.gson()
                            .deserializeOrNull(reason);
                } catch (JsonSyntaxException e) {
                    log.warn("Failed to parse reason as JSON object: {}", reason, e);
                }
        }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally not fond of printing a warning for that kinda thing, and generally not sure what exactly this would solve vs the current approach

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally not fond of printing a warning for that kinda thing, and generally not sure what exactly this would solve vs the current approach

this will allow server administrators to know the exact error when formatting is incorrect

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command accepts json or MiniMessage, the intent is that it will silently fall through to parsing the alt format rather than blowing up

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command accepts json or MiniMessage, the intent is that it will silently fall through to parsing the alt format rather than blowing up

How then to quickly determine where the error occurred? Maybe in that case it is worth trying log.debug?

@astei
Copy link
Contributor

astei commented Oct 21, 2024

@456dev can you fix the checkstyle issue here?

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.

5 participants