SteamWar/RealTime
Archiviert
13
0

closes #1 realtime weather #2

Zusammengeführt
Lixfel hat 8 Commits von weather nach master 2020-02-24 17:48:31 +01:00 zusammengeführt
Nur Änderungen aus Commit 243a8f0002 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -55,7 +55,7 @@ public class Realtime extends JavaPlugin implements Listener {
}, 0, 20 * 60);
//Weather Updater
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> updateCurrentWeather(), 0, 20 * 60 * 10); //Die Wetterdaten werden bei OpenWeatherMAP nur alle 10 Minuten erneuert
Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, () -> updateCurrentWeather(), 0, 20 * 60 * 10); //Die Wetterdaten werden bei OpenWeatherMAP nur alle 10 Minuten erneuert
}
@ -81,81 +81,77 @@ public class Realtime extends JavaPlugin implements Listener {
* Thunderstorm: ID 2xx ^
*/
Bukkit.getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
InputStream inputStream = null;
DataInputStream dataInputStream;
InputStream inputStream = null;
DataInputStream dataInputStream;
@Override
public void run() {
try {
URL url = new URL("http://api.openweathermap.org/data/2.5/weather?id=2934245&APPID=16e8ffada1fbdbe3f3903802b0785751");
inputStream = url.openStream();
try {
URL url = new URL("http://api.openweathermap.org/data/2.5/weather?id=2934245&APPID=16e8ffada1fbdbe3f3903802b0785751");
inputStream = url.openStream();
dataInputStream = new DataInputStream(new BufferedInputStream(inputStream));
dataInputStream = new DataInputStream(new BufferedInputStream(inputStream));
StringBuilder stringBuilder = new StringBuilder();
String inputLine;
StringBuilder stringBuilder = new StringBuilder();
String inputLine;
while ((inputLine = dataInputStream.readLine()) != null) {
stringBuilder.append(inputLine);
}
jsonString = stringBuilder.toString();
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
IOUtils.closeQuietly(inputStream);
}
while ((inputLine = dataInputStream.readLine()) != null) {
stringBuilder.append(inputLine);
}
jsonString = stringBuilder.toString();
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
IOUtils.closeQuietly(inputStream);
}
JSONObject jsonObject = (JSONObject) JSONValue.parse(jsonString);
JSONObject jsonObject = (JSONObject) JSONValue.parse(jsonString);
String weather;
String weather;
JSONArray jsonArray = (JSONArray) jsonObject.get("weather");
JSONObject arrayObject = (JSONObject) jsonArray.get(0);
weather = String.valueOf((int) (long) arrayObject.get("id"));
JSONArray jsonArray = (JSONArray) jsonObject.get("weather");
JSONObject arrayObject = (JSONObject) jsonArray.get(0);
weather = String.valueOf((int) (long) arrayObject.get("id"));
oldWeatherState = weatherState;
String firstChar = Character.toString(weather.charAt(0));
switch (firstChar) {
case "6":
weatherState = WeatherState.SNOW;
oldWeatherState = weatherState;
String firstChar = Character.toString(weather.charAt(0));
switch (firstChar) {
case "6":
weatherState = WeatherState.SNOW;
break;
case "5": case "3": //3 = Drizzle
weatherState = WeatherState.RAIN;
break;
case "2":
weatherState = WeatherState.THUNDER_STORM;
break;
default:
weatherState = WeatherState.CLEAR_SKY; //case 8 ebenfalls CLEAR_SKY
break;
}
//Weltänderungen
Bukkit.getScheduler().scheduleSyncDelayedTask(getInstance(), () -> {
if(oldWeatherState != null && oldWeatherState == weatherState)
return;
for(World world : Bukkit.getWorlds()) {
switch (weatherState) {
case CLEAR_SKY:
world.setThundering(false);
world.setStorm(false);
break;
case "5": case "3": //3 = Drizzle
weatherState = WeatherState.RAIN;
case RAIN:
case SNOW:
world.setThundering(false);
world.setStorm(true);
break;
case "2":
weatherState = WeatherState.THUNDER_STORM;
break;
default:
weatherState = WeatherState.CLEAR_SKY; //case 8 ebenfalls CLEAR_SKY
case THUNDER_STORM:
world.setThundering(true);
world.setStorm(true);
break;
}
//Weltänderungen
Bukkit.getScheduler().scheduleSyncDelayedTask(getInstance(), () -> {
if(oldWeatherState != null && oldWeatherState == weatherState)
return;
for(World world : Bukkit.getWorlds()) {
switch (weatherState) {
case CLEAR_SKY:
world.setThundering(false);
world.setStorm(false);
break;
case RAIN: case SNOW:
world.setThundering(false);
world.setStorm(true);
break;
case THUNDER_STORM:
world.setThundering(true);
world.setStorm(true);
break;
}
}
}, 0);
}
}, 0);
}