Skip to content

Commit

Permalink
Made the requested changes.
Browse files Browse the repository at this point in the history
Moved the nag to `TokenParser` and to end of `buildTree` method.
  • Loading branch information
LinoxGH committed Jan 13, 2022
1 parent 10c8a84 commit 75f682f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Expand Up @@ -63,7 +63,6 @@ final class MiniMessageParser {

@NotNull String escapeTokens(final @NotNull String richMessage, final @NotNull ContextImpl context) {
final StringBuilder sb = new StringBuilder(richMessage.length());
tryToNag(richMessage, context.strict());
this.escapeTokens(sb, richMessage, context);
return sb.toString();
}
Expand All @@ -87,7 +86,6 @@ void escapeTokens(final StringBuilder sb, final @NotNull String richMessage, fin

@NotNull String stripTokens(final @NotNull String richMessage, final @NotNull ContextImpl context) {
final StringBuilder sb = new StringBuilder(richMessage.length());
tryToNag(richMessage, context.strict());
this.processTokens(sb, richMessage, context, (token, builder) -> {});
return sb.toString();
}
Expand Down Expand Up @@ -129,7 +127,6 @@ private void processTokens(final @NotNull StringBuilder sb, final @NotNull Strin
} catch (final IOException ignored) {
}
}
tryToNag(richMessage, context.strict());

final Function<TagNode, Transformation> transformationFactory;
if (debug != null) {
Expand Down Expand Up @@ -250,10 +247,4 @@ private Component handleModifying(final Modifying modTransformation, final Compo
private String sanitizePlaceholderName(final String name) {
return name.toLowerCase(Locale.ROOT);
}

private void tryToNag(final String input, final boolean strict) {
if (input.contains("§") && strict) {
throw new IllegalArgumentException("Legacy formatting codes have been detected in a component - this is unsupported behaviour. Please refer to the Adventure documentation (https://docs.adventure.kyori.net) for more information.");
}
}
}
Expand Up @@ -503,6 +503,8 @@ private static ElementNode buildTree(
throw new ParsingException(sb.toString(), message, errorTokens);
}

tryToNag(message, strict);

return root;
}

Expand Down Expand Up @@ -672,4 +674,17 @@ public static String unescape(final String text, final int startIndex, final int

return sb.toString();
}

/**
* Nags the user about using legacy symbol, if they used it.
*
* @param input the input text
* @param strict strict mode
* @since 4.10.0
*/
private static void tryToNag(final String input, final boolean strict) {
if (input.contains("§") && strict) {
throw new IllegalArgumentException("Legacy formatting codes have been detected in a component - this is unsupported behaviour. Please refer to the Adventure documentation (https://docs.adventure.kyori.net) for more information.");
}
}
}

0 comments on commit 75f682f

Please sign in to comment.