src/main/java/dev/viper/weathertime/WeatherTimeData.java aktualisiert
This commit is contained in:
@@ -1,57 +1,87 @@
|
|||||||
package dev.viper.weathertime;
|
package dev.viper.weathertime;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.LocalTime;
|
|
||||||
import java.time.ZoneOffset;
|
/**
|
||||||
|
* Zentrale Datenklasse für Wetter- und Zeitinformationen.
|
||||||
public class WeatherTimeData {
|
* Erweiterung: enthält jetzt auch Luftfeuchtigkeit, Windgeschwindigkeit und Sonnenauf/untergang.
|
||||||
private final boolean rain;
|
*/
|
||||||
private final boolean thunder;
|
public class WeatherTimeData {
|
||||||
private final long unixTime;
|
|
||||||
private final double tempCelsius;
|
private final ZonedDateTime dateTime; // Lokale Zeit am Standort
|
||||||
|
private final String weatherMain; // Hauptwetterbeschreibung (z. B. "Clear", "Rain")
|
||||||
public WeatherTimeData(boolean rain, boolean thunder, long unixTime, double tempCelsius) {
|
private final double tempCelsius; // Temperatur in °C
|
||||||
this.rain = rain;
|
|
||||||
this.thunder = thunder;
|
private final int humidity; // Luftfeuchtigkeit in %
|
||||||
this.unixTime = unixTime;
|
private final double windSpeed; // Windgeschwindigkeit (m/s oder mph)
|
||||||
this.tempCelsius = tempCelsius;
|
private final ZonedDateTime sunrise; // Sonnenaufgang
|
||||||
}
|
private final ZonedDateTime sunset; // Sonnenuntergang
|
||||||
|
|
||||||
public boolean isRain() {
|
public WeatherTimeData(
|
||||||
return rain;
|
ZonedDateTime dateTime,
|
||||||
}
|
String weatherMain,
|
||||||
|
double tempCelsius,
|
||||||
public boolean isThunder() {
|
int humidity,
|
||||||
return thunder;
|
double windSpeed,
|
||||||
}
|
ZonedDateTime sunrise,
|
||||||
|
ZonedDateTime sunset) {
|
||||||
public double getTemp(String unit) {
|
this.dateTime = dateTime;
|
||||||
return unit.equalsIgnoreCase("F") ? (tempCelsius * 9 / 5) + 32 : tempCelsius;
|
this.weatherMain = weatherMain;
|
||||||
}
|
this.tempCelsius = tempCelsius;
|
||||||
|
this.humidity = humidity;
|
||||||
public String getFormattedTime(String format) {
|
this.windSpeed = windSpeed;
|
||||||
LocalTime time = Instant.ofEpochSecond(unixTime)
|
this.sunrise = sunrise;
|
||||||
.atOffset(ZoneOffset.UTC)
|
this.sunset = sunset;
|
||||||
.toLocalTime();
|
}
|
||||||
|
|
||||||
if ("12h".equalsIgnoreCase(format)) {
|
public ZonedDateTime getDateTime() {
|
||||||
int hour = time.getHour();
|
return dateTime;
|
||||||
String ampm = hour >= 12 ? "PM" : "AM";
|
}
|
||||||
hour = hour % 12;
|
|
||||||
if (hour == 0) hour = 12;
|
public String getWeatherMain() {
|
||||||
return String.format("%02d:%02d %s", hour, time.getMinute(), ampm);
|
return weatherMain;
|
||||||
} else {
|
}
|
||||||
return String.format("%02d:%02d", time.getHour(), time.getMinute());
|
|
||||||
}
|
public double getTemp(String unit) {
|
||||||
}
|
return "F".equalsIgnoreCase(unit)
|
||||||
|
? (tempCelsius * 9 / 5) + 32
|
||||||
public long toMinecraftTime() {
|
: tempCelsius;
|
||||||
LocalTime time = Instant.ofEpochSecond(unixTime)
|
}
|
||||||
.atOffset(ZoneOffset.UTC)
|
|
||||||
.toLocalTime();
|
public int getHumidity() {
|
||||||
|
return humidity;
|
||||||
int hour = time.getHour();
|
}
|
||||||
int minute = time.getMinute();
|
|
||||||
return (hour * 1000L / 24) + (minute * 1000L / (24 * 60));
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user