diff --git a/src/main/java/dev/viper/weathertime/WeatherTimeData.java b/src/main/java/dev/viper/weathertime/WeatherTimeData.java index b137ff4..7ed4f9d 100644 --- a/src/main/java/dev/viper/weathertime/WeatherTimeData.java +++ b/src/main/java/dev/viper/weathertime/WeatherTimeData.java @@ -1,57 +1,87 @@ -package dev.viper.weathertime; - -import java.time.Instant; -import java.time.LocalTime; -import java.time.ZoneOffset; - -public class WeatherTimeData { - private final boolean rain; - private final boolean thunder; - private final long unixTime; - private final double tempCelsius; - - public WeatherTimeData(boolean rain, boolean thunder, long unixTime, double tempCelsius) { - this.rain = rain; - this.thunder = thunder; - this.unixTime = unixTime; - this.tempCelsius = tempCelsius; - } - - public boolean isRain() { - return rain; - } - - public boolean isThunder() { - return thunder; - } - - public double getTemp(String unit) { - return unit.equalsIgnoreCase("F") ? (tempCelsius * 9 / 5) + 32 : tempCelsius; - } - - public String getFormattedTime(String format) { - LocalTime time = Instant.ofEpochSecond(unixTime) - .atOffset(ZoneOffset.UTC) - .toLocalTime(); - - if ("12h".equalsIgnoreCase(format)) { - int hour = time.getHour(); - String ampm = hour >= 12 ? "PM" : "AM"; - hour = hour % 12; - if (hour == 0) hour = 12; - return String.format("%02d:%02d %s", hour, time.getMinute(), ampm); - } else { - return String.format("%02d:%02d", time.getHour(), time.getMinute()); - } - } - - public long toMinecraftTime() { - LocalTime time = Instant.ofEpochSecond(unixTime) - .atOffset(ZoneOffset.UTC) - .toLocalTime(); - - int hour = time.getHour(); - int minute = time.getMinute(); - return (hour * 1000L / 24) + (minute * 1000L / (24 * 60)); - } -} \ No newline at end of file +package dev.viper.weathertime; + +import java.time.ZonedDateTime; + +/** + * Zentrale Datenklasse für Wetter- und Zeitinformationen. + * Erweiterung: enthält jetzt auch Luftfeuchtigkeit, Windgeschwindigkeit und Sonnenauf/untergang. + */ +public class WeatherTimeData { + + private final ZonedDateTime dateTime; // Lokale Zeit am Standort + private final String weatherMain; // Hauptwetterbeschreibung (z. B. "Clear", "Rain") + private final double tempCelsius; // Temperatur in °C + + private final int humidity; // Luftfeuchtigkeit in % + private final double windSpeed; // Windgeschwindigkeit (m/s oder mph) + private final ZonedDateTime sunrise; // Sonnenaufgang + private final ZonedDateTime sunset; // Sonnenuntergang + + public WeatherTimeData( + ZonedDateTime dateTime, + String weatherMain, + double tempCelsius, + int humidity, + double windSpeed, + ZonedDateTime sunrise, + ZonedDateTime sunset) { + this.dateTime = dateTime; + this.weatherMain = weatherMain; + this.tempCelsius = tempCelsius; + this.humidity = humidity; + this.windSpeed = windSpeed; + this.sunrise = sunrise; + this.sunset = sunset; + } + + public ZonedDateTime getDateTime() { + return dateTime; + } + + public String getWeatherMain() { + return weatherMain; + } + + public double getTemp(String unit) { + return "F".equalsIgnoreCase(unit) + ? (tempCelsius * 9 / 5) + 32 + : tempCelsius; + } + + public int getHumidity() { + return humidity; + } + + public double getWindSpeed() { + return windSpeed; + } + + public ZonedDateTime getSunrise() { + return sunrise; + } + + public ZonedDateTime getSunset() { + return sunset; + } + + public String getFormattedTime(String format) { + int hour = dateTime.getHour(); + int minute = dateTime.getMinute(); + if ("12h".equalsIgnoreCase(format)) { + String ampm = hour >= 12 ? "PM" : "AM"; + hour = hour % 12; + if (hour == 0) hour = 12; + return String.format("%02d:%02d %s", hour, minute, ampm); + } + return String.format("%02d:%02d", hour, minute); + } + + public long toMinecraftTime() { + int hour = dateTime.getHour(); + int minute = dateTime.getMinute(); + int second = dateTime.getSecond(); + return ((hour + 18) % 24) * 1000L + + (minute * 1000L / 60) + + (second * 1000L / 3600); + } +}