Skip to content

Commit

Permalink
Strip control codes from player displayname
Browse files Browse the repository at this point in the history
Signed-off-by: unilock <[email protected]>
  • Loading branch information
unilock committed May 24, 2024
1 parent 60038ec commit fc8b8cd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/cc/unilock/nilcord/util/TextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import net.minecraft.util.DamageSource;
import net.minecraft.util.StatCollector;

import java.util.regex.Pattern;

public class TextUtils {
private static final Pattern FORMATTING_CODE_PATTERN = Pattern.compile("(?i)" + '§' + "[0-9A-FK-OR]");

public static String parseDiscordMessage(String template, String attachmentChunk, String replyChunk, String usernameChunk, User author, Member member, Message message) {
return template
.replace("<attachment_format>", attachmentChunk)
Expand All @@ -37,7 +41,7 @@ public static String parseDiscordReply(String template, Message refMessage) {

public static String parsePlayer(String template, EntityPlayerMP player) {
return template
.replace("<displayname>", player.getDisplayName())
.replace("<displayname>", stripControlCodes(player.getDisplayName()))
.replace("<username>", player.getGameProfile().getName())
.replace("<uuid>", player.getGameProfile().getId().toString());
}
Expand All @@ -61,4 +65,8 @@ public static String parseDeath(String template, EntityPlayerMP player, DamageSo
return parsePlayer(template, player)
.replace("<death_message>", source.func_151519_b(player).getUnformattedTextForChat());
}

public static String stripControlCodes(String text) {
return FORMATTING_CODE_PATTERN.matcher(text).replaceAll("");
}
}

0 comments on commit fc8b8cd

Please sign in to comment.