feat: add world_time_(12|24)

This commit is contained in:
iGabyTM committed 2024-06-24 15:52:17 +03:00
1 parent 43da98e619
commit d3924df5ba
2 files changed
+21 -2

No files matched your search

@@ -3,6 +3,7 @@ package at.helpch.placeholderapi.expansion.player;
import at.helpch.placeholderapi.expansion.player.util.ItemUtil;
import at.helpch.placeholderapi.expansion.player.ping.PingFormatter;
import at.helpch.placeholderapi.expansion.player.util.PlayerUtil;
import at.helpch.placeholderapi.expansion.player.util.TimeUtil;
import at.helpch.placeholderapi.expansion.player.util.VersionHelper;
import com.google.common.collect.ImmutableMap;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
@@ -280,9 +281,8 @@ public final class PlayerExpansion extends PlaceholderExpansion implements Confi
case "world_time":
return String.valueOf(player.getWorld().getTime());
case "world_time_12":
return null; // TODO world_time_12
case "world_time_24":
return null; // TODO world_time_24
return TimeUtil.formatWorldTime(player.getWorld().getTime(), params.equals("world_time_24"));
case "weather_duration":
return String.valueOf(player.getWorld().getWeatherDuration());
case "thunder_duration":
@@ -0,0 +1,19 @@
package at.helpch.placeholderapi.expansion.player.util;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public final class TimeUtil {
private static final LocalTime SIX_O_CLOCK = LocalTime.of(6, 0);
private static final double MINECRAFT_SECONDS_PER_TICK = 3.6d;
private static final DateTimeFormatter TWENTY_FOUR_FORMAT = DateTimeFormatter.ofPattern("HH:mm");
private static final DateTimeFormatter TWELVE_FORMAT = DateTimeFormatter.ofPattern("hh:mm a");
public static String formatWorldTime(final long ticks, final boolean twentyFourHourFormat) {
final LocalTime time = SIX_O_CLOCK.plusSeconds((long) (ticks * MINECRAFT_SECONDS_PER_TICK));
return time.format(twentyFourHourFormat ? TWENTY_FOUR_FORMAT : TWELVE_FORMAT);
}
}