Skip to content
Open
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
63 changes: 47 additions & 16 deletions src/main/java/com/roxiun/mellow/data/PlayerProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.roxiun.mellow.api.tnt.TntRunPlayer;
import com.roxiun.mellow.api.urchin.UrchinTag;
import java.util.List;
import java.util.Locale;

public class PlayerProfile {

Expand Down Expand Up @@ -177,8 +178,8 @@ public TabStats getTabStats(StatScope scope) {
null,
skywarsPlayer.getFormattedWlrWithColor(),
null,
skywarsPlayer.getFormattedWinsWithColor(),
skywarsPlayer.getFormattedKillsWithColor(),
formatTabCountForDisplay(skywarsPlayer.getFormattedWinsWithColor()),
formatTabCountForDisplay(skywarsPlayer.getFormattedKillsWithColor()),
null,
null
);
Expand All @@ -191,13 +192,13 @@ public TabStats getTabStats(StatScope scope) {
duelsPlayer.getFormattedNameWithRank(),
duelsPlayer.getDivision(),
duelsPlayer.getFormattedKdrWithColor(),
duelsPlayer.getFormattedWinstreakWithColor(),
formatTabCountForDisplay(duelsPlayer.getFormattedWinstreakWithColor()),
duelsPlayer.getFormattedWlrWithColor(),
null,
duelsPlayer.getFormattedWinsWithColor(),
duelsPlayer.getFormattedLossesWithColor(),
duelsPlayer.getFormattedKillsWithColor(),
duelsPlayer.getFormattedDeathsWithColor(),
formatTabCountForDisplay(duelsPlayer.getFormattedWinsWithColor()),
formatTabCountForDisplay(duelsPlayer.getFormattedLossesWithColor()),
formatTabCountForDisplay(duelsPlayer.getFormattedKillsWithColor()),
formatTabCountForDisplay(duelsPlayer.getFormattedDeathsWithColor()),
null,
null
);
Expand All @@ -213,7 +214,7 @@ public TabStats getTabStats(StatScope scope) {
null,
null,
null,
buildBattlePlayer.getFormattedWinsWithColor(),
formatTabCountForDisplay(buildBattlePlayer.getFormattedWinsWithColor()),
null,
null,
null
Expand All @@ -230,8 +231,8 @@ public TabStats getTabStats(StatScope scope) {
null,
tntRunPlayer.getFormattedRatioWithColor(),
null,
tntRunPlayer.getFormattedWinsWithColor(),
tntRunPlayer.getFormattedDeathsWithColor(),
formatTabCountForDisplay(tntRunPlayer.getFormattedWinsWithColor()),
formatTabCountForDisplay(tntRunPlayer.getFormattedDeathsWithColor()),
null,
null,
null,
Expand All @@ -244,14 +245,20 @@ public TabStats getTabStats(StatScope scope) {
}

// Format numbers with appropriate formatting including colors
String formattedWins = getBedwarsPlayer().getFormattedWinsWithColor();
String formattedBeds = getBedwarsPlayer().getFormattedBedsWithColor();
String formattedFinals =
getBedwarsPlayer().getFormattedFinalsWithColor();
String formattedWins = formatTabCountForDisplay(
getBedwarsPlayer().getFormattedWinsWithColor()
);
String formattedBeds = formatTabCountForDisplay(
getBedwarsPlayer().getFormattedBedsWithColor()
);
String formattedFinals = formatTabCountForDisplay(
getBedwarsPlayer().getFormattedFinalsWithColor()
);
String formattedFkdr =
bedwarsPlayer.getFkdrColor() + bedwarsPlayer.getFormattedFkdr();
String formattedWinstreak =
getBedwarsPlayer().getFormattedWinstreakWithColor();
String formattedWinstreak = formatTabCountForDisplay(
getBedwarsPlayer().getFormattedWinstreakWithColor()
);
String formattedWLR = getBedwarsPlayer().getFormattedWLRWithColor();
String formattedBBLR = getBedwarsPlayer().getFormattedBBLRWithColor();

Expand All @@ -270,4 +277,28 @@ public TabStats getTabStats(StatScope scope) {
formattedFinals
);
}

public static String formatTabCountForDisplay(String value) {
if (value == null || value.isEmpty()) {
return value;
}

int index = 0;
while (index + 1 < value.length() && value.charAt(index) == '§') {
index += 2;
}

String prefix = value.substring(0, index);
String numericPart = value.substring(index);
if (numericPart.isEmpty()) {
return value;
}

try {
long parsed = Long.parseLong(numericPart);
return prefix + String.format(Locale.US, "%,d", parsed);
} catch (NumberFormatException ignored) {
return value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.roxiun.mellow.data;

import org.junit.Assert;
import org.junit.Test;

public class PlayerProfileTabFormattingTest {

@Test
public void formatTabCountForDisplayAddsCommas() {
Assert.assertEquals("§c12,345", PlayerProfile.formatTabCountForDisplay("§c12345"));
}

@Test
public void formatTabCountForDisplayLeavesRatiosUnchanged() {
Assert.assertEquals("§e1.23", PlayerProfile.formatTabCountForDisplay("§e1.23"));
}
}