Skip to content

Commit d5324b5

Browse files
sebampuerohyperdefined
authored andcommitted
feat: some first changes
Add placeholders for time values, new formatting function and call for new function.
1 parent 4fe4c2b commit d5324b5

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

src/main/java/lol/hyper/toolstats/tools/ItemLore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,8 +815,8 @@ public ItemMeta updateFlightTime(ItemStack elytra, long duration) {
815815
}
816816

817817
container.set(toolStats.flightTime, PersistentDataType.LONG, flightTime + duration);
818-
String oldFlightFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
819-
String newFlightFormatted = toolStats.numberFormat.formatDouble((double) (flightTime + duration) / 1000);
818+
String oldFlightFormatted = toolStats.numberFormat.formatTime(flightTime);
819+
String newFlightFormatted = toolStats.numberFormat.formatTime(flightTime + duration);
820820
Component oldLine = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightFormatted);
821821
Component newLine = toolStats.configTools.formatLore("flight-time", "{time}", newFlightFormatted);
822822
if (oldLine == null || newLine == null) {

src/main/java/lol/hyper/toolstats/tools/NumberFormat.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,41 @@ public String formatDouble(double number) {
136136
public String formatDate(Date date) {
137137
return DATE_FORMAT.format(date);
138138
}
139+
140+
/**
141+
* Formats time in milliseconds in a human readable format.
142+
* @param time The time in milliseconds to format.
143+
* @return The time in a human readable format.
144+
*/
145+
public String formatTime(Long time) {
146+
final int SECONDS_PER_MINUTE = 60;
147+
final int MINUTES_PER_HOUR = 60;
148+
final int HOURS_PER_DAY = 24;
149+
final int DAYS_PER_WEEK = 7;
150+
final int DAYS_PER_MONTH = 30; // Approximation
151+
final int DAYS_PER_YEAR = 365; // Approximation
152+
153+
long totalSeconds = time / 1000;
154+
155+
long years = totalSeconds / (DAYS_PER_YEAR * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
156+
totalSeconds %= (DAYS_PER_YEAR * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
157+
158+
long months = totalSeconds / (DAYS_PER_MONTH * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
159+
totalSeconds %= (DAYS_PER_MONTH * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
160+
161+
long weeks = totalSeconds / (DAYS_PER_WEEK * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
162+
totalSeconds %= (DAYS_PER_WEEK * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
163+
164+
long days = totalSeconds / (HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
165+
totalSeconds %= (HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
166+
167+
long hours = totalSeconds / (MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
168+
totalSeconds %= (MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
169+
170+
long minutes = totalSeconds / SECONDS_PER_MINUTE;
171+
totalSeconds %= SECONDS_PER_MINUTE;
172+
173+
long seconds = totalSeconds;
174+
return "";
175+
}
139176
}

src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ messages:
196196
dropped-by: "&7Dropped by: &8{name}" # name will be player/mob name
197197
damage-taken: "&7Damage taken: &8{damage}"
198198
arrows-shot: "&7Arrows shot: &8{arrows}"
199-
flight-time: "&7Flight time: &8{time}"
199+
flight-time: "&7Flight time: &8{years}y {months}m {days}d {hours}h {minutes}m {seconds}s"
200200
damage-done: "&7Damage done: &8{damage}"
201201
# Set display name for mobs. See: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html
202202
mobs:

0 commit comments

Comments
 (0)