Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f72903c2a6 | |||
| e2b3abb65d | |||
| 26d1f27f79 | |||
| 4e0195f7ab | |||
| 9856ad0e54 | |||
| de4f24c368 | |||
| 7ae5eea24a | |||
| ac318f4f78 | |||
| fe3e1c1534 | |||
| c7416baed5 | |||
| 98cad69efc | |||
| 64c994bc8b | |||
| a1e29bc89e | |||
| ede9d372f0 | |||
| 7761b5a1be | |||
| 032ada193a |
205
README.md
205
README.md
@@ -1,141 +1,108 @@
|
|||||||
# RealTimeWeather
|
# RealTimeWeather
|
||||||
|
|
||||||
Ein Minecraft-Plugin, das Echtzeit-Wetter und -Zeit in deine Welten bringt! **RealTimeWeather** synchronisiert das In-Game-Wetter und die Tageszeit mit Daten von OpenWeatherMap und bietet eine benutzerfreundliche GUI, Wettervorhersagen und anpassbare Anzeigeoptionen. Entwickelt für Minecraft 1.21.1.
|
**RealTimeWeather** ist ein Bukkit/Spigot/Paper-Plugin, das echte Wetter- und Zeitdaten aus der realen Welt in deine Minecraft-Welt synchronisiert und live auf der Actionbar anzeigt – inklusive Temperatur, Wettericon, Luftfeuchtigkeit, Windstärke und Sonnenauf-/untergang.
|
||||||
|
|
||||||
## Funktionen
|
## ⭐ Features
|
||||||
|
|
||||||
- **Echtzeit-Wetter**: Synchronisiert Regen, Gewitter oder klares Wetter mit realen Wetterdaten eines konfigurierbaren Orts.
|
- Echte Wetter- und Uhrzeit-Synchronisation pro Welt
|
||||||
- **Echtzeit-Zeit**: Passt die Minecraft-Tageszeit an die aktuelle Uhrzeit an (deaktiviert den Tageszyklus).
|
- Anzeige auf der Actionbar:
|
||||||
- **Actionbar-Anzeige**: Zeigt Datum, Uhrzeit, Wetter-Symbol (z. B. 🌧️) und Temperatur in der Actionbar an, mit Optionen für Position (oben links/rechts) und Symbolanzeige.
|
Datum, Uhrzeit, Wetter-Icon, Temperatur, Luftfeuchtigkeit 💧, Windgeschwindigkeit 🌬️, Sonnenaufgang 🌅 & Sonnenuntergang 🌇
|
||||||
- **Wettervorhersage**: 5-Tage-Wettervorhersage über den Befehl `/weatherforecast`.
|
- Eigene Location pro Spieler möglich (GUI & Befehl)
|
||||||
- **GUI**: Intuitive Benutzeroberfläche zum Festlegen von Orten, Umschalten der Anzeige und Abrufen von Informationen.
|
- Ingame-Vorhersage (5 Tage) als Command
|
||||||
- **Mehrsprachenunterstützung**: Unterstützt Deutsch (`de`) und Englisch (`en`) über `lang.yml`, mit einfacher Erweiterung für weitere Sprachen.
|
- Wetterumschaltung auf Server synchron mit echten Wetterdaten (optional)
|
||||||
- **Weltspezifische Konfiguration**: Unterschiedliche Einstellungen für jede Welt in `config.yml`.
|
- Volle Mehrsprachigkeit über lang.yml
|
||||||
- **Spielerindividuelle Orte**: Spieler können ihren eigenen Ort mit `/wetter setlocation` festlegen.
|
- Kompatibel mit Minecraft 1.19.x – 1.21.x
|
||||||
- **Berechtigungen**: Admin-Befehle sind durch Berechtigungen geschützt.
|
|
||||||
|
|
||||||
## Installation
|
## 🔧 Installation
|
||||||
|
|
||||||
1. **Download**: Lade die `RealTimeWeather.jar` aus den [Releases](https://github.com/M_Viper/RealTimeWeather/releases) herunter.
|
1. **Kopiere die Dateien:**<br>
|
||||||
2. **Plugin-Ordner**: Kopiere die JAR-Datei in den `plugins`-Ordner deines Minecraft-Servers.
|
Die JAR nach `/plugins/` kopieren, Server neu starten.
|
||||||
3. **API-Schlüssel**: Registriere dich bei [OpenWeatherMap](https://openweathermap.org/) für einen kostenlosen API-Schlüssel.
|
2. **OpenWeatherMap API-Key** im `/plugins/RealTimeWeather/config.yml` eintragen:
|
||||||
4. **Konfiguration**: Bearbeite die `config.yml` im Ordner `plugins/RealTimeWeather/` und füge deinen API-Schlüssel ein.
|
|
||||||
5. **Server starten**: Starte deinen Server, um das Plugin zu laden. Die `lang.yml` wird automatisch generiert.
|
|
||||||
|
|
||||||
## Konfiguration
|
api-key: "DEIN_OPENWEATHERMAP_API_KEY"
|
||||||
|
|
||||||
Die Konfigurationsdateien befinden sich im Ordner `plugins/RealTimeWeather/`.
|
Registriere gratis unter https://openweathermap.org.
|
||||||
|
|
||||||
### config.yml
|
3. **Plugin starten/neu laden:**<br>
|
||||||
|
`reload` Befehl (`/wetter reload`) oder Server-Neustart.
|
||||||
|
|
||||||
|
## ⚙️ Kurzes Setup
|
||||||
|
|
||||||
|
- Die wichtigsten Einstellungen sind in der `config.yml` dokumentiert (siehe unten).
|
||||||
|
- Du kannst für jede Welt eigene Locations, Anzeige-Modi oder Wettertypen setzen.
|
||||||
|
|
||||||
|
## 🕹️ Kommandos
|
||||||
|
|
||||||
|
| Befehl | Beschreibung |
|
||||||
|
|-----------------------|-----------------------------------------------|
|
||||||
|
| `/wetter help` | Alle Befehle und Kurzinfos anzeigen |
|
||||||
|
| `/wetter reload` | Konfiguration und Sprache neu laden |
|
||||||
|
| `/wetter setlocation <city,country>` | Eigene Stadt für Anzeige wählen |
|
||||||
|
| `/wetter query` | Zeigt das aktuelle Wetter für dich an |
|
||||||
|
| `/wetter info` | Infos zum Plugin |
|
||||||
|
| `/wetter gui` | Öffnet das GUI mit Schnell-Optionen |
|
||||||
|
| `/weatherforecast` | 5-Tage-Wetterprognose deiner Location |
|
||||||
|
| `/toggleweather` | Actionbar-Wetteranzeige für Welt (de)aktivieren |
|
||||||
|
|
||||||
|
## 📊 Live-Anzeige (Actionbar)
|
||||||
|
|
||||||
|
Beispiel:
|
||||||
|
|
||||||
|
08.08.2025 18:31 ☁️ 21.7°C | 💧 68% | 🌬️ 2.5 m/s | 🌅 05:48 | 🌇 21:34
|
||||||
|
|
||||||
|
```yml
|
||||||
|
## 📝 Beispiel-config.yml
|
||||||
|
|
||||||
```yaml
|
|
||||||
api-key: "DEIN_API_KEY_HIER"
|
api-key: "DEIN_API_KEY_HIER"
|
||||||
update-interval: 60 # Sekunden
|
update-interval: 60
|
||||||
|
|
||||||
defaults:
|
defaults:
|
||||||
enabled: true # Plugin für Welten ohne spezifische Konfiguration aktivieren
|
enabled: true
|
||||||
location: "Berlin,de" # Stadt,Ländercode
|
location: "Berlin,de"
|
||||||
units: "metric" # metric = Celsius, imperial = Fahrenheit
|
units: "metric"
|
||||||
time-format: "24h" # "24h" oder "12h"
|
time-format: "24h"
|
||||||
display-actionbar: true
|
display-actionbar: true
|
||||||
display-weather-icon: true
|
display-weather-icon: true
|
||||||
display-position: "top-right" # top-left oder top-right
|
|
||||||
padding-right: 100 # Anzahl der Leerzeichen für top-right
|
display-position / padding-right werden zentriert ignoriert
|
||||||
|
display-position: "top-right"
|
||||||
|
padding-right: 100
|
||||||
|
sync-in-game-weather: true
|
||||||
|
|
||||||
worlds:
|
worlds:
|
||||||
world:
|
world:
|
||||||
enabled: true
|
enabled: true
|
||||||
location: "London,uk"
|
location: "Berlin,de"
|
||||||
units: "imperial"
|
units: "metric"
|
||||||
time-format: "12h"
|
time-format: "24h"
|
||||||
display-actionbar: true
|
display-actionbar: true
|
||||||
display-weather-icon: true
|
display-weather-icon: true
|
||||||
display-position: "top-left"
|
display-position: "top-left"
|
||||||
padding-right: 50
|
padding-right: 50
|
||||||
world_nether:
|
sync-in-game-weather: true
|
||||||
enabled: false
|
world_nether:
|
||||||
location: "Tokyo,jp"
|
enabled: false
|
||||||
units: "metric"
|
location: "Berlin,de"
|
||||||
time-format: "24h"
|
units: "metric"
|
||||||
display-actionbar: true
|
time-format: "24h"
|
||||||
display-weather-icon: false
|
display-actionbar: true
|
||||||
display-position: "top-right"
|
display-weather-icon: false
|
||||||
padding-right: 150
|
display-position: "top-right"
|
||||||
|
padding-right: 150
|
||||||
|
sync-in-game-weather: false
|
||||||
```
|
```
|
||||||
|
|
||||||
# RealTimeWeather
|
|
||||||
|
|
||||||
Ein Minecraft-Plugin, das Echtzeit-Wetter und -Zeit in deine Welten bringt. Synchronisiert Wetter und Tageszeit mit OpenWeatherMap-Daten. Entwickelt für Minecraft 1.21.1 - 1.21.8.
|
## 🧑💻 Erweiterungen
|
||||||
|
|
||||||
## Konfiguration
|
- Anzeige von Feuchtigkeit, Wind & Sonnenzeiten kann leicht deaktiviert/angepasst werden (siehe Actionbar-Code).
|
||||||
|
- Ländercodes und Städte werden in OpenWeatherMap-Syntax verwendet, z. B. `London,gb`, `Frankfurt,de`.
|
||||||
|
|
||||||
|
## ❤️ Lizenz
|
||||||
|
|
||||||
### lang.yml
|
[MIT License](LICENSE)
|
||||||
|
|
||||||
Enthält Übersetzungen für Deutsch (`de`) und Englisch (`en`). Beispiel für Deutsch:
|
---
|
||||||
|
|
||||||
```yaml
|
> Fragen, Feature-Wünsche oder Bugreports gerne als Gitea-Issue!
|
||||||
languages:
|
|
||||||
de:
|
|
||||||
help_header: "RealTimeWeather-Befehle"
|
|
||||||
help_help: "Diese Hilfenachricht anzeigen"
|
|
||||||
help_reload: "Die Plugin-Konfiguration neu laden (Berechtigung: realtimeweather.reload)"
|
|
||||||
help_setlocation: "Eigenen Wetterort für den Spieler festlegen (z.B. Berlin,de)"
|
|
||||||
help_query: "Aktuelles Wetter für den Spielerort oder die Welt anzeigen"
|
|
||||||
help_info: "Plugin-Informationen anzeigen"
|
|
||||||
help_gui: "GUI für Wettersteuerung öffnen"
|
|
||||||
help_weatherforecast: "Wettervorhersage für 5 Tage anzeigen"
|
|
||||||
help_toggleweather: "Wetteranzeige in der Actionbar ein-/ausschalten"
|
|
||||||
usage: "Verwendung: /wetter reload | setlocation <Ort> | query | info | gui | help"
|
|
||||||
usage_setlocation: "Verwendung: /wetter setlocation <Stadt,Land>"
|
|
||||||
no_permission: "Du hast keine Berechtigung für diesen Befehl!"
|
|
||||||
reload_success: "Konfiguration erfolgreich neu geladen!"
|
|
||||||
only_players: "Dieser Befehl ist nur für Spieler!"
|
|
||||||
plugin_disabled: "Plugin ist für die Welt {world} deaktiviert!"
|
|
||||||
location_set: "Ort auf {location} gesetzt!"
|
|
||||||
invalid_location: "Ungültiger Ort: {location}"
|
|
||||||
forecast_error: "Fehler beim Abrufen der Wetterdaten für {location}: {error}"
|
|
||||||
gui_title: "Wettersteuerung"
|
|
||||||
gui_setlocation: "Ort festlegen"
|
|
||||||
gui_setlocation_lore: "Eigenen Wetterort festlegen"
|
|
||||||
gui_toggleweather: "Wetteranzeige umschalten"
|
|
||||||
gui_toggleweather_lore: "Wetter-Actionbar ein-/ausschalten"
|
|
||||||
gui_forecast: "Wettervorhersage"
|
|
||||||
gui_forecast_lore: "5-Tage-Wettervorhersage anzeigen"
|
|
||||||
gui_info: "Info"
|
|
||||||
gui_info_lore: "Plugin-Informationen anzeigen"
|
|
||||||
gui_setlocation_prompt: "Gib den Ort ein (z.B. Berlin,de)"
|
|
||||||
toggle_enabled: "Wetteranzeige für {world} aktiviert!"
|
|
||||||
toggle_disabled: "Wetteranzeige für {world} deaktiviert!"
|
|
||||||
forecast_header: "Wettervorhersage für {location}"
|
|
||||||
weather:
|
|
||||||
clear: "Klar"
|
|
||||||
clouds: "Bewölkt"
|
|
||||||
rain: "Regen"
|
|
||||||
thunderstorm: "Gewitter"
|
|
||||||
snow: "Schnee"
|
|
||||||
mist: "Nebel"
|
|
||||||
fog: "Nebel"
|
|
||||||
haze: "Dunst"
|
|
||||||
en:
|
|
||||||
# Ähnliche Schlüssel wie oben, auf Englisch
|
|
||||||
```
|
|
||||||
|
|
||||||
# RealTimeWeather
|
|
||||||
|
|
||||||
Ein Minecraft-Plugin, das Echtzeit-Wetter und -Zeit in deine Welten bringt. Entwickelt für Minecraft 1.21.1.
|
|
||||||
|
|
||||||
## Befehle
|
|
||||||
|
|
||||||
- `/wetter help`: Zeigt die Hilfeübersicht an.
|
|
||||||
- `/wetter reload`: Lädt die Konfiguration neu (Berechtigung: `realtimeweather.reload`).
|
|
||||||
- `/wetter setlocation <city,country>`: Legt einen individuellen Ort für den Spieler fest.
|
|
||||||
- `/wetter query`: Zeigt aktuelles Wetter für den Spielerort oder die Welt.
|
|
||||||
- `/wetter info`: Zeigt Plugin-Informationen an.
|
|
||||||
- `/wetter gui`: Öffnet die Wetter-GUI.
|
|
||||||
- `/weatherforecast`: Zeigt die 5-Tage-Wettervorhersage.
|
|
||||||
- `/toggleweather`: Schaltet die Wetteranzeige in der Actionbar ein/aus.
|
|
||||||
|
|
||||||
## Berechtigungen
|
|
||||||
|
|
||||||
- `realtimeweather.reload`: Erlaubt `/wetter reload`.
|
|
||||||
- `realtimeweather.admin`: Erlaubt Admin-Benachrichtigungen bei Wetterabfrage-Fehlern.
|
|
||||||
|
|
||||||
|
|||||||
48
pom.xml
48
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<groupId>dev.viper</groupId>
|
<groupId>dev.viper</groupId>
|
||||||
<artifactId>RealTimeWeather</artifactId>
|
<artifactId>RealTimeWeather</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.4</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>RealTimeWeather</name>
|
<name>RealTimeWeather</name>
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
@@ -46,18 +46,36 @@
|
|||||||
<version>20231013</version>
|
<version>20231013</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Adventure API -->
|
<!-- Adventure API (nur für Chat-Nachrichten, NICHT für ActionBar) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.kyori</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>adventure-api</artifactId>
|
<artifactId>adventure-api</artifactId>
|
||||||
<version>4.17.0</version>
|
<version>4.17.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Adventure Platform Bukkit -->
|
<!-- Adventure Platform Bukkit -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.kyori</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>adventure-platform-bukkit</artifactId>
|
<artifactId>adventure-platform-bukkit</artifactId>
|
||||||
<version>4.3.3</version>
|
<version>4.3.4</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Adventure Text Serializer Legacy -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-text-serializer-legacy</artifactId>
|
||||||
|
<version>4.17.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- bStats Bukkit Library -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bstats</groupId>
|
||||||
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
@@ -65,7 +83,7 @@
|
|||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.10.1</version>
|
<version>3.13.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${maven.compiler.source}</source>
|
<source>${maven.compiler.source}</source>
|
||||||
<target>${maven.compiler.target}</target>
|
<target>${maven.compiler.target}</target>
|
||||||
@@ -75,7 +93,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.4.1</version>
|
<version>3.5.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
@@ -87,21 +105,19 @@
|
|||||||
<pattern>org.json</pattern>
|
<pattern>org.json</pattern>
|
||||||
<shadedPattern>dev.viper.shaded.org.json</shadedPattern>
|
<shadedPattern>dev.viper.shaded.org.json</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
<!-- Shade Adventure API -->
|
<!-- Shade ALLE Adventure/Kyori Packages zusammen -->
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>net.kyori.adventure</pattern>
|
<pattern>net.kyori</pattern>
|
||||||
<shadedPattern>dev.viper.shaded.net.kyori.adventure</shadedPattern>
|
<shadedPattern>dev.viper.shaded.net.kyori</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
<!-- Shade Adventure Platform Bukkit -->
|
<!-- Shade bStats -->
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>net.kyori.platform.bukkit</pattern>
|
<pattern>org.bstats</pattern>
|
||||||
<shadedPattern>dev.viper.shaded.net.kyori.platform.bukkit</shadedPattern>
|
<shadedPattern>dev.viper.shaded.org.bstats</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<!-- Minimieren, um die JAR-Größe zu reduzieren (optional) -->
|
<minimizeJar>false</minimizeJar>
|
||||||
<minimizeJar>true</minimizeJar>
|
|
||||||
<!-- Filter, um unnötige Klassen auszuschließen -->
|
|
||||||
<filters>
|
<filters>
|
||||||
<filter>
|
<filter>
|
||||||
<artifact>*:*</artifact>
|
<artifact>*:*</artifact>
|
||||||
|
|||||||
32
src/main/java/dev/viper/weathertime/DisplayMode.java
Normal file
32
src/main/java/dev/viper/weathertime/DisplayMode.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package dev.viper.weathertime;
|
||||||
|
|
||||||
|
public enum DisplayMode {
|
||||||
|
COMPACT("Kompakt", 5),
|
||||||
|
STANDARD("Standard", 10),
|
||||||
|
DETAILED("Detailliert", 15);
|
||||||
|
|
||||||
|
private final String displayName;
|
||||||
|
private final int lineCount;
|
||||||
|
|
||||||
|
DisplayMode(String displayName, int lineCount) {
|
||||||
|
this.displayName = displayName;
|
||||||
|
this.lineCount = lineCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLineCount() {
|
||||||
|
return lineCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DisplayMode fromString(String mode) {
|
||||||
|
for (DisplayMode dm : values()) {
|
||||||
|
if (dm.name().equalsIgnoreCase(mode)) {
|
||||||
|
return dm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return STANDARD;
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/main/java/dev/viper/weathertime/MetricsManager.java
Normal file
21
src/main/java/dev/viper/weathertime/MetricsManager.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package dev.viper.weathertime;
|
||||||
|
|
||||||
|
import org.bstats.bukkit.Metrics;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class MetricsManager {
|
||||||
|
|
||||||
|
private final Metrics metrics;
|
||||||
|
|
||||||
|
public MetricsManager(JavaPlugin plugin) {
|
||||||
|
int pluginId = 26865; // Deine Plugin-ID von bStats
|
||||||
|
this.metrics = new Metrics(plugin, pluginId);
|
||||||
|
|
||||||
|
// Optional: Eigene Charts hinzufügen
|
||||||
|
// metrics.addCustomChart(new Metrics.SingleLineChart("custom_chart", () -> 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Metrics getMetrics() {
|
||||||
|
return metrics;
|
||||||
|
}
|
||||||
|
}
|
||||||
69
src/main/java/dev/viper/weathertime/MoonPhase.java
Normal file
69
src/main/java/dev/viper/weathertime/MoonPhase.java
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package dev.viper.weathertime;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
public class MoonPhase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Berechnet die aktuelle Mondphase basierend auf der Minecraft-Zeit
|
||||||
|
*/
|
||||||
|
public static String getPhase(World world) {
|
||||||
|
long fullTime = world.getFullTime();
|
||||||
|
long daysPassed = fullTime / 24000L;
|
||||||
|
int phase = (int) (daysPassed % 8);
|
||||||
|
|
||||||
|
switch (phase) {
|
||||||
|
case 0: return "🌑 Neumond";
|
||||||
|
case 1: return "🌒 Zunehmende Sichel";
|
||||||
|
case 2: return "🌓 Erstes Viertel";
|
||||||
|
case 3: return "🌔 Zunehmender Mond";
|
||||||
|
case 4: return "🌕 Vollmond";
|
||||||
|
case 5: return "🌖 Abnehmender Mond";
|
||||||
|
case 6: return "🌗 Letztes Viertel";
|
||||||
|
case 7: return "🌘 Abnehmende Sichel";
|
||||||
|
default: return "🌑 Neumond";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt nur das Emoji der Mondphase zurück
|
||||||
|
*/
|
||||||
|
public static String getEmoji(World world) {
|
||||||
|
long fullTime = world.getFullTime();
|
||||||
|
long daysPassed = fullTime / 24000L;
|
||||||
|
int phase = (int) (daysPassed % 8);
|
||||||
|
|
||||||
|
switch (phase) {
|
||||||
|
case 0: return "🌑";
|
||||||
|
case 1: return "🌒";
|
||||||
|
case 2: return "🌓";
|
||||||
|
case 3: return "🌔";
|
||||||
|
case 4: return "🌕";
|
||||||
|
case 5: return "🌖";
|
||||||
|
case 6: return "🌗";
|
||||||
|
case 7: return "🌘";
|
||||||
|
default: return "🌑";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt den Namen der Mondphase zurück (ohne Emoji)
|
||||||
|
*/
|
||||||
|
public static String getName(World world) {
|
||||||
|
long fullTime = world.getFullTime();
|
||||||
|
long daysPassed = fullTime / 24000L;
|
||||||
|
int phase = (int) (daysPassed % 8);
|
||||||
|
|
||||||
|
switch (phase) {
|
||||||
|
case 0: return "Neumond";
|
||||||
|
case 1: return "Zunehmende Sichel";
|
||||||
|
case 2: return "Erstes Viertel";
|
||||||
|
case 3: return "Zunehmender Mond";
|
||||||
|
case 4: return "Vollmond";
|
||||||
|
case 5: return "Abnehmender Mond";
|
||||||
|
case 6: return "Letztes Viertel";
|
||||||
|
case 7: return "Abnehmende Sichel";
|
||||||
|
default: return "Neumond";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
64
src/main/java/dev/viper/weathertime/UpdateChecker.java
Normal file
64
src/main/java/dev/viper/weathertime/UpdateChecker.java
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
package dev.viper.weathertime;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class UpdateChecker {
|
||||||
|
private final JavaPlugin plugin;
|
||||||
|
private final int resourceId;
|
||||||
|
|
||||||
|
public UpdateChecker(JavaPlugin plugin, int resourceId) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.resourceId = resourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getLatestVersion(Consumer<String> consumer) {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
InputStream inputStream = null;
|
||||||
|
Scanner scanner = null;
|
||||||
|
try {
|
||||||
|
HttpURLConnection connection = (HttpURLConnection)
|
||||||
|
new URL("https://api.spiget.org/v2/resources/" + resourceId + "/versions/latest").openConnection();
|
||||||
|
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
connection.addRequestProperty("User-Agent", "Mozilla/5.0");
|
||||||
|
|
||||||
|
inputStream = connection.getInputStream();
|
||||||
|
scanner = new Scanner(inputStream);
|
||||||
|
String response = scanner.useDelimiter("\\A").next();
|
||||||
|
|
||||||
|
JSONObject json = new JSONObject(response);
|
||||||
|
String versionName = json.optString("name");
|
||||||
|
|
||||||
|
// Nur Zahlen + Punkte behalten (z.B. "version 1.1" -> "1.1")
|
||||||
|
String cleanVersion = versionName.replaceAll("[^0-9.]", "").trim();
|
||||||
|
|
||||||
|
consumer.accept(cleanVersion.isEmpty() ? versionName : cleanVersion);
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().warning("Konnte keine Update-Info abrufen: " + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
if (scanner != null) {
|
||||||
|
try {
|
||||||
|
scanner.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (inputStream != null) {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
97
src/main/java/dev/viper/weathertime/WeatherColors.java
Normal file
97
src/main/java/dev/viper/weathertime/WeatherColors.java
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
package dev.viper.weathertime;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
public class WeatherColors {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt die Farbe basierend auf der Temperatur zurück
|
||||||
|
*/
|
||||||
|
public static ChatColor getTemperatureColor(double tempCelsius) {
|
||||||
|
if (tempCelsius < 0) {
|
||||||
|
return ChatColor.AQUA; // Unter 0°C - Hellblau (eisig)
|
||||||
|
} else if (tempCelsius < 10) {
|
||||||
|
return ChatColor.BLUE; // 0-10°C - Blau (kalt)
|
||||||
|
} else if (tempCelsius < 20) {
|
||||||
|
return ChatColor.GREEN; // 10-20°C - Grün (mild)
|
||||||
|
} else if (tempCelsius < 30) {
|
||||||
|
return ChatColor.YELLOW; // 20-30°C - Gelb (warm)
|
||||||
|
} else {
|
||||||
|
return ChatColor.RED; // Über 30°C - Rot (heiß)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt die Farbe basierend auf dem Wetter zurück
|
||||||
|
*/
|
||||||
|
public static ChatColor getWeatherColor(String weatherMain) {
|
||||||
|
switch (weatherMain.toLowerCase()) {
|
||||||
|
case "clear":
|
||||||
|
return ChatColor.GOLD; // Sonnig - Gold
|
||||||
|
case "clouds":
|
||||||
|
return ChatColor.GRAY; // Bewölkt - Grau
|
||||||
|
case "rain":
|
||||||
|
case "drizzle":
|
||||||
|
return ChatColor.BLUE; // Regen - Blau
|
||||||
|
case "thunderstorm":
|
||||||
|
return ChatColor.DARK_PURPLE; // Gewitter - Dunkelviolett
|
||||||
|
case "snow":
|
||||||
|
return ChatColor.WHITE; // Schnee - Weiß
|
||||||
|
case "mist":
|
||||||
|
case "fog":
|
||||||
|
case "haze":
|
||||||
|
return ChatColor.DARK_GRAY; // Nebel - Dunkelgrau
|
||||||
|
default:
|
||||||
|
return ChatColor.WHITE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt die Farbe basierend auf der Luftfeuchtigkeit zurück
|
||||||
|
*/
|
||||||
|
public static ChatColor getHumidityColor(int humidity) {
|
||||||
|
if (humidity < 30) {
|
||||||
|
return ChatColor.RED; // Trocken
|
||||||
|
} else if (humidity < 60) {
|
||||||
|
return ChatColor.GREEN; // Angenehm
|
||||||
|
} else if (humidity < 80) {
|
||||||
|
return ChatColor.YELLOW; // Feucht
|
||||||
|
} else {
|
||||||
|
return ChatColor.AQUA; // Sehr feucht
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt die Farbe basierend auf der Windgeschwindigkeit zurück (m/s)
|
||||||
|
*/
|
||||||
|
public static ChatColor getWindSpeedColor(double windSpeed) {
|
||||||
|
if (windSpeed < 5) {
|
||||||
|
return ChatColor.GREEN; // Leicht
|
||||||
|
} else if (windSpeed < 10) {
|
||||||
|
return ChatColor.YELLOW; // Mäßig
|
||||||
|
} else if (windSpeed < 15) {
|
||||||
|
return ChatColor.GOLD; // Frisch
|
||||||
|
} else if (windSpeed < 20) {
|
||||||
|
return ChatColor.RED; // Stark
|
||||||
|
} else {
|
||||||
|
return ChatColor.DARK_RED; // Sturm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt die Farbe basierend auf dem UV-Index zurück
|
||||||
|
*/
|
||||||
|
public static ChatColor getUVIndexColor(int uvIndex) {
|
||||||
|
if (uvIndex <= 2) {
|
||||||
|
return ChatColor.GREEN; // Niedrig
|
||||||
|
} else if (uvIndex <= 5) {
|
||||||
|
return ChatColor.YELLOW; // Mäßig
|
||||||
|
} else if (uvIndex <= 7) {
|
||||||
|
return ChatColor.GOLD; // Hoch
|
||||||
|
} else if (uvIndex <= 10) {
|
||||||
|
return ChatColor.RED; // Sehr hoch
|
||||||
|
} else {
|
||||||
|
return ChatColor.DARK_RED; // Extrem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package dev.viper.weathertime;
|
package dev.viper.weathertime;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONArray;
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
@@ -11,6 +11,11 @@ import java.time.ZoneId;
|
|||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holt Wetter und Zeitdaten asynchron von OpenWeatherMap.
|
||||||
|
* Liefert WeatherTimeData zurück, mit konsistentem Modell und Fehlerhandling.
|
||||||
|
* Erweiterung: Erfasst Luftfeuchtigkeit, Windgeschwindigkeit, Sonnenauf- und -untergang.
|
||||||
|
*/
|
||||||
public class WeatherFetcher {
|
public class WeatherFetcher {
|
||||||
|
|
||||||
private final String apiKey;
|
private final String apiKey;
|
||||||
@@ -19,54 +24,51 @@ public class WeatherFetcher {
|
|||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
public WeatherFetcher(String apiKey, String location, String units, Logger logger) {
|
public WeatherFetcher(String apiKey, String location, String units, Logger logger) {
|
||||||
this.apiKey = apiKey;
|
this.apiKey = apiKey == null ? "" : apiKey.trim();
|
||||||
this.location = location;
|
this.location = location == null ? "Berlin,de" : location.trim();
|
||||||
this.units = units.toLowerCase();
|
this.units = units == null ? "metric" : units.trim().toLowerCase();
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
if (!this.units.equals("metric") && !this.units.equals("imperial")) {
|
if (!this.units.equals("metric") && !this.units.equals("imperial")) {
|
||||||
logger.warning("Ungültige Einheit für " + location + ": " + units + ". Verwende 'metric' als Fallback.");
|
logger.warning("Ungültige Einheit für " + this.location + ": " + this.units + ". Verwende 'metric' als Fallback.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WeatherData fetch() throws Exception {
|
/**
|
||||||
String effectiveUnits = units.equals("metric") || units.equals("imperial") ? units : "metric";
|
* Holt die aktuellen Wetter- und Zeitdaten inklusive Zusatzinfos.
|
||||||
|
* Wirft RuntimeExceptions mit klaren Messages bei Fehlern.
|
||||||
|
*/
|
||||||
|
public WeatherTimeData fetchAsWeatherTimeData() throws Exception {
|
||||||
|
if (apiKey.isEmpty()) throw new RuntimeException("API-Key fehlt.");
|
||||||
|
String effectiveUnits = (units.equals("metric") || units.equals("imperial")) ? units : "metric";
|
||||||
String urlString = String.format(
|
String urlString = String.format(
|
||||||
"https://api.openweathermap.org/data/2.5/weather?q=%s&appid=%s&units=%s",
|
"https://api.openweathermap.org/data/2.5/weather?q=%s&appid=%s&units=%s",
|
||||||
location, apiKey, effectiveUnits);
|
location, apiKey, effectiveUnits);
|
||||||
|
|
||||||
URL url = new URL(urlString);
|
BufferedReader in = null;
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
try {
|
||||||
connection.setRequestMethod("GET");
|
JSONObject json;
|
||||||
connection.setConnectTimeout(5000);
|
in = new BufferedReader(new InputStreamReader(openConnectionStream(urlString)));
|
||||||
connection.setReadTimeout(5000);
|
|
||||||
|
|
||||||
int status = connection.getResponseCode();
|
|
||||||
if (status != 200) {
|
|
||||||
logger.warning("HTTP-Fehlercode: " + status + " für Ort: " + location);
|
|
||||||
throw new RuntimeException("HTTP-Fehlercode: " + status + " für Ort: " + location);
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
||||||
StringBuilder content = new StringBuilder();
|
StringBuilder content = new StringBuilder();
|
||||||
String inputLine;
|
String inputLine;
|
||||||
|
|
||||||
while ((inputLine = in.readLine()) != null) {
|
while ((inputLine = in.readLine()) != null) {
|
||||||
content.append(inputLine);
|
content.append(inputLine);
|
||||||
}
|
}
|
||||||
in.close();
|
json = new JSONObject(content.toString());
|
||||||
connection.disconnect();
|
|
||||||
|
|
||||||
JSONObject json = new JSONObject(content.toString());
|
// Fehlerfall: Antwort-Code ungleich 200
|
||||||
long dt = json.getLong("dt");
|
if (json.has("cod") && json.getInt("cod") != 200) {
|
||||||
int timezoneShift;
|
String msg = json.has("message") ? json.getString("message") : "Unbekannter Fehler";
|
||||||
try {
|
logger.warning("API Error für " + location + ": " + msg);
|
||||||
timezoneShift = json.getInt("timezone");
|
throw new RuntimeException(msg);
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warning("Fehler beim Abrufen der Zeitzone für Ort: " + location + ": " + e.getMessage());
|
|
||||||
throw new RuntimeException("Fehler beim Abrufen der Zeitzone für Ort: " + location, e);
|
|
||||||
}
|
}
|
||||||
ZonedDateTime dateTime = Instant.ofEpochSecond(dt).atZone(ZoneId.of("UTC")).plusSeconds(timezoneShift);
|
|
||||||
|
long dt = json.getLong("dt");
|
||||||
|
int timezoneShift = json.optInt("timezone", 0); // Zeitzonen-Offset in Sekunden
|
||||||
|
|
||||||
|
ZonedDateTime dateTime = Instant.ofEpochSecond(dt)
|
||||||
|
.atZone(ZoneId.of("UTC"))
|
||||||
|
.plusSeconds(timezoneShift);
|
||||||
|
|
||||||
String weatherMain = json.getJSONArray("weather").getJSONObject(0).getString("main");
|
String weatherMain = json.getJSONArray("weather").getJSONObject(0).getString("main");
|
||||||
double temperature = json.getJSONObject("main").getDouble("temp");
|
double temperature = json.getJSONObject("main").getDouble("temp");
|
||||||
|
|
||||||
@@ -76,48 +78,119 @@ public class WeatherFetcher {
|
|||||||
logger.warning("Unrealistische Temperatur für " + location + ": " + temperature + "°C. API-Fehler?");
|
logger.warning("Unrealistische Temperatur für " + location + ": " + temperature + "°C. API-Fehler?");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WeatherData(dateTime, weatherMain, temperature);
|
// Temperatur immer in Celsius für WeatherTimeData speichern
|
||||||
|
double tempCelsius = effectiveUnits.equals("imperial") ? (temperature - 32) * 5.0 / 9.0 : temperature;
|
||||||
|
|
||||||
|
// FELDER AUSLESEN
|
||||||
|
int humidity = json.getJSONObject("main").getInt("humidity");
|
||||||
|
double windSpeed = json.getJSONObject("wind").optDouble("speed", 0.0);
|
||||||
|
double windDeg = json.getJSONObject("wind").optDouble("deg", 0.0);
|
||||||
|
|
||||||
|
int pressure = json.getJSONObject("main").optInt("pressure", 1013);
|
||||||
|
int clouds = json.getJSONObject("clouds").optInt("all", 0);
|
||||||
|
double feelsLikeTemp = json.getJSONObject("main").optDouble("feels_like", temperature);
|
||||||
|
double feelsLikeCelsius = effectiveUnits.equals("imperial") ? (feelsLikeTemp - 32) * 5.0 / 9.0 : feelsLikeTemp;
|
||||||
|
int visibility = json.optInt("visibility", 10000); // Standard 10km
|
||||||
|
|
||||||
|
ZonedDateTime sunrise = Instant.ofEpochSecond(json.getJSONObject("sys").getLong("sunrise"))
|
||||||
|
.atZone(ZoneId.of("UTC"))
|
||||||
|
.plusSeconds(timezoneShift);
|
||||||
|
|
||||||
|
ZonedDateTime sunset = Instant.ofEpochSecond(json.getJSONObject("sys").getLong("sunset"))
|
||||||
|
.atZone(ZoneId.of("UTC"))
|
||||||
|
.plusSeconds(timezoneShift);
|
||||||
|
|
||||||
|
return new WeatherTimeData(dateTime, weatherMain, tempCelsius,
|
||||||
|
humidity, windSpeed, windDeg, sunrise, sunset,
|
||||||
|
pressure, clouds, feelsLikeCelsius, visibility);
|
||||||
|
|
||||||
|
} catch (RuntimeException ru) {
|
||||||
|
throw ru;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.warning("Fehler beim Abrufen von OpenWeatherMap: " + ex.getMessage());
|
||||||
|
throw new RuntimeException("Verbindung oder API-Fehler: " + ex.getMessage(), ex);
|
||||||
|
} finally {
|
||||||
|
if (in != null) {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holt das Wetter-Vorhersage-JSON (5 Tage, 3-Stunden-Takt).
|
||||||
|
* Muss im Command asynchron ausgewertet werden!
|
||||||
|
*/
|
||||||
public JSONObject fetchForecast() throws Exception {
|
public JSONObject fetchForecast() throws Exception {
|
||||||
String effectiveUnits = units.equals("metric") || units.equals("imperial") ? units : "metric";
|
if (apiKey.isEmpty()) throw new RuntimeException("API-Key fehlt.");
|
||||||
|
String effectiveUnits = (units.equals("metric") || units.equals("imperial")) ? units : "metric";
|
||||||
String urlString = String.format(
|
String urlString = String.format(
|
||||||
"https://api.openweathermap.org/data/2.5/forecast?q=%s&appid=%s&units=%s",
|
"https://api.openweathermap.org/data/2.5/forecast?q=%s&appid=%s&units=%s",
|
||||||
location, apiKey, effectiveUnits);
|
location, apiKey, effectiveUnits);
|
||||||
URL url = new URL(urlString);
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setRequestMethod("GET");
|
|
||||||
connection.setConnectTimeout(5000);
|
|
||||||
connection.setReadTimeout(5000);
|
|
||||||
|
|
||||||
int status = connection.getResponseCode();
|
BufferedReader in = null;
|
||||||
if (status != 200) {
|
try {
|
||||||
logger.warning("HTTP-Fehlercode: " + status + " für Ort: " + location);
|
in = new BufferedReader(new InputStreamReader(openConnectionStream(urlString)));
|
||||||
throw new RuntimeException("HTTP-Fehlercode: " + status + " für Ort: " + location);
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
||||||
StringBuilder content = new StringBuilder();
|
StringBuilder content = new StringBuilder();
|
||||||
String inputLine;
|
String inputLine;
|
||||||
while ((inputLine = in.readLine()) != null) {
|
while ((inputLine = in.readLine()) != null) {
|
||||||
content.append(inputLine);
|
content.append(inputLine);
|
||||||
}
|
}
|
||||||
|
JSONObject json = new JSONObject(content.toString());
|
||||||
|
if (json.has("cod") && (!"200".equals(json.get("cod").toString()))) {
|
||||||
|
String msg = json.has("message") ? json.getString("message") : "Unbekannter Fehler";
|
||||||
|
logger.warning("API Error (Forecast) für " + location + ": " + msg);
|
||||||
|
throw new RuntimeException(msg);
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warning("Fehler beim Abrufen der Wettervorhersage: " + e.getMessage());
|
||||||
|
throw new RuntimeException("Fehler beim Abrufen der Wettervorhersage: " + e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
if (in != null) {
|
||||||
|
try {
|
||||||
in.close();
|
in.close();
|
||||||
connection.disconnect();
|
} catch (Exception e) {
|
||||||
|
// Ignore
|
||||||
return new JSONObject(content.toString());
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class WeatherData {
|
/** Öffnet eine HTTP-GET-Verbindung und liefert den InputStream der Response zurück (Timeouts gesetzt). */
|
||||||
ZonedDateTime dateTime;
|
private java.io.InputStream openConnectionStream(String urlString) throws Exception {
|
||||||
String weatherMain;
|
URL url = new URL(urlString);
|
||||||
double temperature;
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
connection.setConnectTimeout(6000);
|
||||||
|
connection.setReadTimeout(6000);
|
||||||
|
|
||||||
public WeatherData(ZonedDateTime dateTime, String weatherMain, double temperature) {
|
int status = connection.getResponseCode();
|
||||||
this.dateTime = dateTime;
|
if (status != 200) {
|
||||||
this.weatherMain = weatherMain;
|
String err = "(keine Fehlerdetails)";
|
||||||
this.temperature = temperature;
|
BufferedReader errIn = null;
|
||||||
|
try {
|
||||||
|
errIn = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
String l;
|
||||||
|
while ((l = errIn.readLine()) != null) sb.append(l);
|
||||||
|
err = sb.toString();
|
||||||
|
} catch (Exception suppress) {
|
||||||
|
// Ignore
|
||||||
|
} finally {
|
||||||
|
if (errIn != null) {
|
||||||
|
try {
|
||||||
|
errIn.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
throw new RuntimeException("HTTP-Fehlercode: " + status + " – " + err);
|
||||||
|
}
|
||||||
|
return connection.getInputStream();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,57 +1,164 @@
|
|||||||
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.
|
||||||
|
* Erweiterung: enthält jetzt auch Luftfeuchtigkeit, Windgeschwindigkeit, Windrichtung,
|
||||||
|
* Sonnenauf/untergang, Luftdruck, Wolkendichte und UV-Index.
|
||||||
|
*/
|
||||||
public class WeatherTimeData {
|
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) {
|
private final ZonedDateTime dateTime; // Lokale Zeit am Standort
|
||||||
this.rain = rain;
|
private final String weatherMain; // Hauptwetterbeschreibung (z. B. "Clear", "Rain")
|
||||||
this.thunder = thunder;
|
private final double tempCelsius; // Temperatur in °C
|
||||||
this.unixTime = unixTime;
|
|
||||||
|
private final int humidity; // Luftfeuchtigkeit in %
|
||||||
|
private final double windSpeed; // Windgeschwindigkeit (m/s oder mph)
|
||||||
|
private final double windDeg; // Windrichtung in Grad (0-360)
|
||||||
|
private final ZonedDateTime sunrise; // Sonnenaufgang
|
||||||
|
private final ZonedDateTime sunset; // Sonnenuntergang
|
||||||
|
|
||||||
|
private final int pressure; // Luftdruck in hPa
|
||||||
|
private final int clouds; // Wolkendichte in %
|
||||||
|
private final double feelsLike; // Gefühlte Temperatur in °C
|
||||||
|
private final int visibility; // Sichtweite in Metern
|
||||||
|
|
||||||
|
public WeatherTimeData(
|
||||||
|
ZonedDateTime dateTime,
|
||||||
|
String weatherMain,
|
||||||
|
double tempCelsius,
|
||||||
|
int humidity,
|
||||||
|
double windSpeed,
|
||||||
|
double windDeg,
|
||||||
|
ZonedDateTime sunrise,
|
||||||
|
ZonedDateTime sunset,
|
||||||
|
int pressure,
|
||||||
|
int clouds,
|
||||||
|
double feelsLike,
|
||||||
|
int visibility) {
|
||||||
|
this.dateTime = dateTime;
|
||||||
|
this.weatherMain = weatherMain;
|
||||||
this.tempCelsius = tempCelsius;
|
this.tempCelsius = tempCelsius;
|
||||||
|
this.humidity = humidity;
|
||||||
|
this.windSpeed = windSpeed;
|
||||||
|
this.windDeg = windDeg;
|
||||||
|
this.sunrise = sunrise;
|
||||||
|
this.sunset = sunset;
|
||||||
|
this.pressure = pressure;
|
||||||
|
this.clouds = clouds;
|
||||||
|
this.feelsLike = feelsLike;
|
||||||
|
this.visibility = visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRain() {
|
public ZonedDateTime getDateTime() {
|
||||||
return rain;
|
return dateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isThunder() {
|
public String getWeatherMain() {
|
||||||
return thunder;
|
return weatherMain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getTemp(String unit) {
|
public double getTemp(String unit) {
|
||||||
return unit.equalsIgnoreCase("F") ? (tempCelsius * 9 / 5) + 32 : tempCelsius;
|
return "F".equalsIgnoreCase(unit)
|
||||||
|
? (tempCelsius * 9.0 / 5.0) + 32.0
|
||||||
|
: tempCelsius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHumidity() {
|
||||||
|
return humidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getWindSpeed() {
|
||||||
|
return windSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getWindDeg() {
|
||||||
|
return windDeg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZonedDateTime getSunrise() {
|
||||||
|
return sunrise;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZonedDateTime getSunset() {
|
||||||
|
return sunset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPressure() {
|
||||||
|
return pressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getClouds() {
|
||||||
|
return clouds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getFeelsLike(String unit) {
|
||||||
|
return "F".equalsIgnoreCase(unit)
|
||||||
|
? (feelsLike * 9.0 / 5.0) + 32.0
|
||||||
|
: feelsLike;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVisibility() {
|
||||||
|
return visibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Berechnet einen einfachen UV-Index basierend auf Tageszeit, Wolken und Wetter
|
||||||
|
* (0-11+: 0-2=niedrig, 3-5=mäßig, 6-7=hoch, 8-10=sehr hoch, 11+=extrem)
|
||||||
|
*/
|
||||||
|
public int getUVIndex() {
|
||||||
|
int hour = dateTime.getHour();
|
||||||
|
|
||||||
|
// Nachts ist UV-Index 0
|
||||||
|
if (hour < 6 || hour > 20) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Basis UV-Index je nach Tageszeit (Maximum mittags)
|
||||||
|
int baseUV;
|
||||||
|
if (hour >= 11 && hour <= 13) {
|
||||||
|
baseUV = 9; // Mittags am höchsten
|
||||||
|
} else if (hour >= 10 && hour <= 14) {
|
||||||
|
baseUV = 7;
|
||||||
|
} else if (hour >= 9 && hour <= 15) {
|
||||||
|
baseUV = 5;
|
||||||
|
} else {
|
||||||
|
baseUV = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reduzierung durch Wolken
|
||||||
|
baseUV = baseUV - (clouds / 20);
|
||||||
|
|
||||||
|
// Reduzierung bei Regen/Schnee/Gewitter
|
||||||
|
if (weatherMain.equalsIgnoreCase("rain") ||
|
||||||
|
weatherMain.equalsIgnoreCase("drizzle") ||
|
||||||
|
weatherMain.equalsIgnoreCase("thunderstorm") ||
|
||||||
|
weatherMain.equalsIgnoreCase("snow")) {
|
||||||
|
baseUV = Math.max(1, baseUV / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.max(0, Math.min(11, baseUV));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFormattedTime(String format) {
|
public String getFormattedTime(String format) {
|
||||||
LocalTime time = Instant.ofEpochSecond(unixTime)
|
int hour = dateTime.getHour();
|
||||||
.atOffset(ZoneOffset.UTC)
|
int minute = dateTime.getMinute();
|
||||||
.toLocalTime();
|
|
||||||
|
|
||||||
if ("12h".equalsIgnoreCase(format)) {
|
if ("12h".equalsIgnoreCase(format)) {
|
||||||
int hour = time.getHour();
|
|
||||||
String ampm = hour >= 12 ? "PM" : "AM";
|
String ampm = hour >= 12 ? "PM" : "AM";
|
||||||
hour = hour % 12;
|
hour = hour % 12;
|
||||||
if (hour == 0) hour = 12;
|
if (hour == 0) hour = 12;
|
||||||
return String.format("%02d:%02d %s", hour, time.getMinute(), ampm);
|
return String.format("%02d:%02d %s", hour, minute, ampm);
|
||||||
} else {
|
|
||||||
return String.format("%02d:%02d", time.getHour(), time.getMinute());
|
|
||||||
}
|
}
|
||||||
|
return String.format("%02d:%02d", hour, minute);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long toMinecraftTime() {
|
public long toMinecraftTime() {
|
||||||
LocalTime time = Instant.ofEpochSecond(unixTime)
|
int hour = dateTime.getHour();
|
||||||
.atOffset(ZoneOffset.UTC)
|
int minute = dateTime.getMinute();
|
||||||
.toLocalTime();
|
int second = dateTime.getSecond();
|
||||||
|
return ((hour + 18) % 24) * 1000L
|
||||||
int hour = time.getHour();
|
+ (minute * 1000L / 60)
|
||||||
int minute = time.getMinute();
|
+ (second * 1000L / 3600);
|
||||||
return (hour * 1000L / 24) + (minute * 1000L / (24 * 60));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
83
src/main/java/dev/viper/weathertime/WindDirection.java
Normal file
83
src/main/java/dev/viper/weathertime/WindDirection.java
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
package dev.viper.weathertime;
|
||||||
|
|
||||||
|
public class WindDirection {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Konvertiert Windrichtung in Grad (0-360) zu Himmelsrichtung
|
||||||
|
*/
|
||||||
|
public static String getDirection(double degrees) {
|
||||||
|
// Normalisiere auf 0-360
|
||||||
|
degrees = degrees % 360;
|
||||||
|
if (degrees < 0) degrees += 360;
|
||||||
|
|
||||||
|
if (degrees >= 337.5 || degrees < 22.5) {
|
||||||
|
return "N"; // Nord
|
||||||
|
} else if (degrees >= 22.5 && degrees < 67.5) {
|
||||||
|
return "NO"; // Nordost
|
||||||
|
} else if (degrees >= 67.5 && degrees < 112.5) {
|
||||||
|
return "O"; // Ost
|
||||||
|
} else if (degrees >= 112.5 && degrees < 157.5) {
|
||||||
|
return "SO"; // Südost
|
||||||
|
} else if (degrees >= 157.5 && degrees < 202.5) {
|
||||||
|
return "S"; // Süd
|
||||||
|
} else if (degrees >= 202.5 && degrees < 247.5) {
|
||||||
|
return "SW"; // Südwest
|
||||||
|
} else if (degrees >= 247.5 && degrees < 292.5) {
|
||||||
|
return "W"; // West
|
||||||
|
} else {
|
||||||
|
return "NW"; // Nordwest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt den Pfeil-Emoji basierend auf der Windrichtung zurück
|
||||||
|
*/
|
||||||
|
public static String getArrow(double degrees) {
|
||||||
|
degrees = degrees % 360;
|
||||||
|
if (degrees < 0) degrees += 360;
|
||||||
|
|
||||||
|
if (degrees >= 337.5 || degrees < 22.5) {
|
||||||
|
return "↓"; // Nord (Wind kommt von Norden, weht nach Süden)
|
||||||
|
} else if (degrees >= 22.5 && degrees < 67.5) {
|
||||||
|
return "↙"; // Nordost
|
||||||
|
} else if (degrees >= 67.5 && degrees < 112.5) {
|
||||||
|
return "←"; // Ost
|
||||||
|
} else if (degrees >= 112.5 && degrees < 157.5) {
|
||||||
|
return "↖"; // Südost
|
||||||
|
} else if (degrees >= 157.5 && degrees < 202.5) {
|
||||||
|
return "↑"; // Süd
|
||||||
|
} else if (degrees >= 202.5 && degrees < 247.5) {
|
||||||
|
return "↗"; // Südwest
|
||||||
|
} else if (degrees >= 247.5 && degrees < 292.5) {
|
||||||
|
return "→"; // West
|
||||||
|
} else {
|
||||||
|
return "↘"; // Nordwest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt die volle Bezeichnung der Windrichtung zurück
|
||||||
|
*/
|
||||||
|
public static String getFullName(double degrees) {
|
||||||
|
degrees = degrees % 360;
|
||||||
|
if (degrees < 0) degrees += 360;
|
||||||
|
|
||||||
|
if (degrees >= 337.5 || degrees < 22.5) {
|
||||||
|
return "Nord";
|
||||||
|
} else if (degrees >= 22.5 && degrees < 67.5) {
|
||||||
|
return "Nordost";
|
||||||
|
} else if (degrees >= 67.5 && degrees < 112.5) {
|
||||||
|
return "Ost";
|
||||||
|
} else if (degrees >= 112.5 && degrees < 157.5) {
|
||||||
|
return "Südost";
|
||||||
|
} else if (degrees >= 157.5 && degrees < 202.5) {
|
||||||
|
return "Süd";
|
||||||
|
} else if (degrees >= 202.5 && degrees < 247.5) {
|
||||||
|
return "Südwest";
|
||||||
|
} else if (degrees >= 247.5 && degrees < 292.5) {
|
||||||
|
return "West";
|
||||||
|
} else {
|
||||||
|
return "Nordwest";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,20 @@
|
|||||||
|
# OpenWeatherMap API-Key – hier eintragen
|
||||||
api-key: "DEIN_API_KEY_HIER"
|
api-key: "DEIN_API_KEY_HIER"
|
||||||
|
|
||||||
|
# Update-Intervall in Sekunden (Standard: 60)
|
||||||
update-interval: 60
|
update-interval: 60
|
||||||
|
|
||||||
defaults:
|
defaults:
|
||||||
enabled: true
|
enabled: true
|
||||||
location: "Berlin,de"
|
location: "Berlin,de" # Stadt,Land
|
||||||
units: "metric"
|
units: "metric" # metric = °C, imperial = °F
|
||||||
time-format: "24h"
|
time-format: "24h" # oder "12h"
|
||||||
display-actionbar: true
|
display-actionbar: true
|
||||||
display-weather-icon: true
|
display-weather-icon: true
|
||||||
display-position: "top-right"
|
display-position: "top-right"
|
||||||
padding-right: 100
|
padding-right: 100
|
||||||
|
sync-in-game-weather: true
|
||||||
|
|
||||||
worlds:
|
worlds:
|
||||||
world:
|
world:
|
||||||
enabled: true
|
enabled: true
|
||||||
@@ -19,6 +25,8 @@ worlds:
|
|||||||
display-weather-icon: true
|
display-weather-icon: true
|
||||||
display-position: "top-left"
|
display-position: "top-left"
|
||||||
padding-right: 50
|
padding-right: 50
|
||||||
|
sync-in-game-weather: true
|
||||||
|
|
||||||
world_nether:
|
world_nether:
|
||||||
enabled: false
|
enabled: false
|
||||||
location: "Berlin,de"
|
location: "Berlin,de"
|
||||||
@@ -28,3 +36,4 @@ worlds:
|
|||||||
display-weather-icon: false
|
display-weather-icon: false
|
||||||
display-position: "top-right"
|
display-position: "top-right"
|
||||||
padding-right: 150
|
padding-right: 150
|
||||||
|
sync-in-game-weather: false
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
name: RealTimeWeather
|
name: RealTimeWeather
|
||||||
version: 1.0
|
version: 1.4
|
||||||
main: dev.viper.weathertime.WeatherTimeSyncPlugin
|
main: dev.viper.weathertime.WeatherTimeSyncPlugin
|
||||||
api-version: 1.21
|
api-version: 1.21
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
wetter:
|
wetter:
|
||||||
description: Manages real-time weather and time synchronization
|
description: Manages real-time weather and time synchronization
|
||||||
@@ -15,6 +16,7 @@ commands:
|
|||||||
description: Toggles the weather display for the current world
|
description: Toggles the weather display for the current world
|
||||||
usage: /<command>
|
usage: /<command>
|
||||||
permission: realtimeweather.toggle
|
permission: realtimeweather.toggle
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
realtimeweather.use:
|
realtimeweather.use:
|
||||||
description: Allows usage of the /wetter command
|
description: Allows usage of the /wetter command
|
||||||
|
|||||||
Reference in New Issue
Block a user