Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/modules/styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,34 @@ These options can be configured in the `styling` section of the config file.

Emote format (`/me`).

!!! config "team-format"

Format for incoming team messages sent with `/teammsg` or `/tm`.

Leave empty to keep the vanilla format, which is translated by the client.

**Placeholders**

* `${team}` - Team display name, including the vanilla hover and click style.
* `${sender}` - Sender display name.
* `${message}` - Message after formatting.

```hocon
team-format="${team} <${sender}> <gray>:</gray> ${message}"
```

!!! config "team-sent-format"

Format for the sender's own copy of a team message.

Leave empty to keep the vanilla format, which is translated by the client.

Placeholders are the same as `team-format`.

```hocon
team-sent-format="<gray>-></gray> ${team} <${sender}> <gray>:</gray> ${message}"
```

!!! config "join-format"

Player join message format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.alexdevs.solstice.modules.ModuleProvider;
import me.alexdevs.solstice.modules.styling.formatters.ChatFormatter;
import me.alexdevs.solstice.modules.styling.formatters.EmoteFormatter;
import me.alexdevs.solstice.modules.styling.formatters.TeamFormatter;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.OutgoingChatMessage;
Expand Down Expand Up @@ -66,14 +67,20 @@ public void sendToPlayer(ServerPlayer receiver, boolean filterMaskEnabled, ChatT
return;
}

//? >= 1.21.1
switch (params.chatType().value().chat().translationKey()) {
case "chat.type.text":
receiver.sendSystemMessage(this.formattedChatMessage);
break;
case "chat.type.emote":
EmoteFormatter.sendEmoteMessage(receiver, message, params, sender);
break;
case "chat.type.team.text":
case "chat.type.team.sent":
if (TeamFormatter.sendTeamMessage(receiver, signedMessage, params, sender)) {
break;
}
receiver.connection.sendDisguisedChatMessage(this.message.decoratedContent(), params);
break;
default:
receiver.connection.sendDisguisedChatMessage(this.message.decoratedContent(), params);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public class StylingConfig {
"default", "%player:displayname%<gray>:</gray> ${message}"
);

@Comment("Team message format. Placeholders: ${team}, ${sender}, ${message}. Leave empty to use vanilla formatting.")
public String teamFormat = "";

@Comment("Team message format as seen by the sender. Placeholders: ${team}, ${sender}, ${message}. Leave empty to use vanilla formatting.")
public String teamSentFormat = "";

@Comment("Enable nameplate customizations.")
public boolean enableNameplateFormatting = true;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package me.alexdevs.solstice.modules.styling.formatters;

import eu.pb4.placeholders.api.PlaceholderContext;
import me.alexdevs.solstice.api.text.Components;
import me.alexdevs.solstice.api.text.Format;
import me.alexdevs.solstice.modules.ModuleProvider;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.PlayerChatMessage;
import net.minecraft.server.level.ServerPlayer;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

public class TeamFormatter {
public static boolean sendTeamMessage(ServerPlayer receiver, PlayerChatMessage message, ChatType.Bound params, @Nullable ServerPlayer sender) {
if (sender == null) {
return false;
}

var team = params.targetName().orElse(null);
if (team == null) {
return false;
}

var config = ModuleProvider.STYLING.getConfig();
var isSent = params.chatType().value().chat().translationKey().equals("chat.type.team.sent");
var format = isSent ? config.teamSentFormat : config.teamFormat;

if (format.isBlank()) {
return false;
}

var playerContext = PlaceholderContext.of(sender);
var messageText = Components.chat(message, sender);

var text = Format.parse(
format,
playerContext,
Map.of(
"team", team,
"sender", params.name(),
"message", messageText
)
);

receiver.sendSystemMessage(text);
return true;
}
}
Loading