Skip to content

Commit

Permalink
Ajout temps de jeu
Browse files Browse the repository at this point in the history
  • Loading branch information
JiveOff committed Sep 24, 2023
1 parent f20a814 commit 9ecaec0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private Collection<String> getLines() {
+ LegacyComponentSerializer.legacySection().serialize(field.value())
);
} else {
fieldsToShow.add(LegacyComponentSerializer.legacySection().serialize(field.name().decoration(TextDecoration.BOLD, true)));
fieldsToShow.add(LegacyComponentSerializer.legacySection().serialize(field.name()));
fieldsToShow.add(LegacyComponentSerializer.legacySection().serialize(field.value()));
}
fieldsToShow.add("§r");
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/fr/efreicraft/ecatup/utils/TimeUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package fr.efreicraft.ecatup.utils;

import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.title.Title;
import net.kyori.adventure.util.Ticks;
import org.jetbrains.annotations.NotNull;

public class TimeUtils {

private TimeUtils() {
throw new IllegalStateException("Utility class");
}

/**
* Construis une chaîne de caractères correspondant au temps donné.
* @param time Temps à formater en secondes.
* @return La chaîne de caractères formatée.
*/
public static @NotNull String formatTime(long time) {
// if days > 0, then format like this: 0j 00h 00m 00s
// else hours > 0, then format like this: 00h 00m 00s
// else minutes > 0, then format like this: 00m 00s
// else seconds > 0, then format like this: 00s
// else format like this: 0s

long days = time / 86400;
long hours = (time % 86400) / 3600;
long minutes = (time % 3600) / 60;
long seconds = time % 60;

if (days > 0) {
return days + "j " + hours + "h " + minutes + "m " + seconds + "s";
} else if (hours > 0) {
return hours + "h " + minutes + "m " + seconds + "s";
} else if (minutes > 0) {
return minutes + "m " + seconds + "s";
} else if (seconds > 0) {
return seconds + "s";
} else {
return "0s";
}
}

}

0 comments on commit 9ecaec0

Please sign in to comment.