Skip to content

Commit

Permalink
feature: add the suppress sending feature to allow to suppress the …
Browse files Browse the repository at this point in the history
…sending of message by its key. (core)
  • Loading branch information
sakurawald committed Jan 3, 2025
1 parent 8b090e2 commit 7bc78f1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/chapters/module/language/language.tex
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@
\LevelTwo{Difference}
Disabled: All the players use the \ttt{default\_language}.\\
Enabled: Fuji will \textbf{try} to respect the player's client-side language, if the server-side supports.

\LevelTwo{Example}
\begin{example}{To supress the sending of a message}
Set the value of a message key to \str{[suppress-sending]}, to suppress the sending of this type of message.
\end{example}
2 changes: 1 addition & 1 deletion docs/chapters/module/teleport_warmup/teleport_warmup.tex
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@

\LevelTwo{Meta}
\begin{description}
\item [fuji.teleport_warmup.warmup] The per player teleport warmup time in seconds.
\item [fuji.teleport\_warmup.warmup] The per player teleport warmup time in seconds.
\end{description}
Binary file modified docs/release/fuji.pdf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public class TextHelper {
private static final Map<String, JsonObject> code2json = new HashMap<>();
private static final JsonObject UNSUPPORTED_LANGUAGE_MARKER = new JsonObject();

private static final String SUPPRESS_SENDING_STRING_MARKER = "[suppress-sending]";
private static final Text SUPPRESS_SENDING_TEXT_MARKER = Text.literal("[suppress-sending]");

static {
writeDefaultLanguageFilesIfAbsent();

Expand Down Expand Up @@ -219,6 +222,11 @@ private static boolean isDefaultLanguageCode(String languageCode) {
private static @NotNull Text getText(@NonNull NodeParser parser, @Nullable Object audience, boolean isKey, String keyOrValue, Object... args) {
String value = isKey ? getValueByKey(audience, keyOrValue) : keyOrValue;

// suppress this sending?
if (value.equals(SUPPRESS_SENDING_STRING_MARKER)) {
return SUPPRESS_SENDING_TEXT_MARKER;
}

// resolve args
value = resolveArgs(value, args);

Expand Down Expand Up @@ -292,6 +300,13 @@ public static void sendMessageByFlag(@NotNull Object audience, boolean flag) {
public static void sendMessageByKey(@NotNull Object audience, String key, Object... args) {
Text text = getTextByKey(audience, key, args);

/* suppress this sending ? */
if (text == SUPPRESS_SENDING_TEXT_MARKER) {
LogUtil.debug("Suppress the sending of message: audience = {}, key = {}, args = {}", audience, key, args);
return;
}


/* extract the source */
if (audience instanceof CommandContext<?> ctx) {
audience = ctx.getSource();
Expand Down

0 comments on commit 7bc78f1

Please sign in to comment.