Skip to content

Commit

Permalink
Rewrite static initializer of CraftChatMessage to not throw on duplic…
Browse files Browse the repository at this point in the history
…ate Formattings

Closes: #406
  • Loading branch information
C0D3-M4513R committed Feb 24, 2025
1 parent d60f4ed commit 30ba9c7
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.network.chat.contents.LiteralContents;
import net.minecraft.network.chat.contents.TranslatableContents;
import org.bukkit.ChatColor;
import org.kettingpowered.ketting.core.Ketting;

public final class CraftChatMessage {

Expand All @@ -28,8 +29,15 @@ public final class CraftChatMessage {

static {
Builder<Character, ChatFormatting> builder = ImmutableMap.builder();
java.util.HashMap<Character, ChatFormatting> check = new java.util.HashMap<>();
for (ChatFormatting format : ChatFormatting.values()) {
builder.put(Character.toLowerCase(format.toString().charAt(1)), format);
final Character chr = Character.toLowerCase(format.toString().charAt(1));
final ChatFormatting dupe = check.put(chr, format);
if (dupe != null) {
Ketting.LOGGER.warn("Skipping Duplicate ChatFormatting: §{}, original formatting: {}, duplicate formatting: {}", chr, dupe, format);
} else {
builder.put(chr, format);
}
}
formatMap = builder.build();
}
Expand Down

0 comments on commit 30ba9c7

Please sign in to comment.