Skip to content

Commit

Permalink
Support formatter_number_time placeholder as a time placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgeiss0702 committed Jan 23, 2024
1 parent f5dc9b8 commit 787a2b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/main/java/us/ajg0702/leaderboards/formatting/formats/Time.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,27 @@ public class Time extends Format {
private static final List<String> knownTimePlaceholders = Arrays.asList(
"statistic_time_played",
"statistic_time_since_death",
"mbedwars_stats-play_time"
"mbedwars_stats-play_time",
"formatter_number_time_*"
);

private boolean isKnownTimePlaceholder(String placeholder) {
boolean is = false;
for (String knownTimePlaceholder : knownTimePlaceholders) {
if(knownTimePlaceholder.endsWith("*")) {
is = placeholder.startsWith(knownTimePlaceholder.substring(0, knownTimePlaceholder.length() - 1));
} else {
is = placeholder.equals(knownTimePlaceholder);
}
if(is) break;
}

return is;
}

@Override
public boolean matches(String output, String placeholder) {
if(knownTimePlaceholders.contains(placeholder.toLowerCase(Locale.ROOT))) {
if(isKnownTimePlaceholder(placeholder.toLowerCase(Locale.ROOT))) {
// don't bother with more expensive checks below if we know it's a time placeholder
// let me know about any other placeholders that should be here!
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public void testMatches() throws Exception {
"31m",
"13 hours 21 minutes 15 seconds",
"6d 15h 46m 8s",
"9h 21m 44s"
"9h 21m 44s",
"2s"
);
List<String> shouldNotMatch = Arrays.asList(
"hello there",
Expand Down

0 comments on commit 787a2b7

Please sign in to comment.