Skip to content

Commit

Permalink
Switch over to ChatColor's colour-stripping.
Browse files Browse the repository at this point in the history
Closes #5680.

Has a side effect currently: PVP in the subtitle doesn't colour the
right colour.
  • Loading branch information
LlmDl committed Jan 30, 2022
1 parent ca995c7 commit 98928a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/com/palmergames/bukkit/util/ChatTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public static String formatTitle(String title) {
return legacyFormatTitle(title);
// Max width - widgetx2 (already padded with an extra 1px) - title - 2 (1px before and after the title.)
int remainder = MAX_FONT_WIDTH - (WIDGET_WIDTH * 2) - font.getWidth(Colors.strip(title)) - 2;
if (remainder < 14)
return Translation.of("status_title_primary_colour") + WIDGET + title + WIDGET;
if (remainder < 1)
return Translation.of("status_title_primary_colour") + title;
if (remainder < 14)
return Translation.of("status_title_primary_colour") + WIDGET + title + WIDGET;

int times = remainder / (UNDERSCORE_WIDTH * 2);
return Translation.of("status_title_primary_colour") + WIDGET + repeatChar(times, "_") + title + repeatChar(times, "_") + WIDGET;
Expand All @@ -108,10 +108,10 @@ public static String formatSubTitle(String subtitle) {
return legacyFormatSubtitle(subtitle);
// Max width - widgetx2 (already padded with an extra 1px) - title - 2 (1px before and after the title.)
int remainder = MAX_FONT_WIDTH - (SUBWIDGET_WIDTH * 2) - font.getWidth(Colors.strip(subtitle)) - 2;
if (remainder < 10)
return Translation.of("status_title_primary_colour") + SUBWIDGET + subtitle + Translation.of("status_title_primary_colour") + SUBWIDGET;
if (remainder < 1)
return Translation.of("status_title_primary_colour") + subtitle;
if (remainder < 10)
return Translation.of("status_title_primary_colour") + SUBWIDGET+ subtitle + Translation.of("status_title_primary_colour") + SUBWIDGET;

int times = remainder / (SPACE_WIDTH * 2);
return Translation.of("status_title_primary_colour") + SUBWIDGET + repeatChar(times, " ") + subtitle + repeatChar(times, " ") + Translation.of("status_title_primary_colour") + SUBWIDGET;
Expand Down
5 changes: 1 addition & 4 deletions src/com/palmergames/bukkit/util/Colors.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ public class Colors {
public static final String White = "\u00A7f";

public static String strip(String line) {

for (ChatColor cc : ChatColor.values())
line = line.replaceAll(cc.toString(), "");
return line;
return ChatColor.stripColor(line);
}

public static String translateColorCodes(String str) {
Expand Down

0 comments on commit 98928a0

Please sign in to comment.