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
3 geänderte Dateien mit 35 neuen und 29 gelöschten Zeilen
Nur Änderungen aus Commit 7b5ffcfe75 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -9,6 +9,6 @@
</content>
Review

iml bitte entfernen

iml bitte entfernen
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: steamwar:Spigot:1.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: steamwar:Spigot:1.12" level="project" />
</component>
</module>

Datei anzeigen

@ -46,7 +46,7 @@
<dependency>
<groupId>steamwar</groupId>
<artifactId>Spigot</artifactId>
<version>1.0</version>
<version>1.12</version>
<scope>provided</scope>
</dependency>
</dependencies>

Datei anzeigen

@ -8,7 +8,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
@ -25,12 +24,14 @@ import java.util.Date;
public class Realtime extends JavaPlugin implements Listener {
WeatherState oldWeatherState = null;
WeatherState weatherState = null;
@Override
public void onEnable() {
PluginManager pluginManager = Bukkit.getPluginManager();
pluginManager.registerEvents(this, this);
WeatherState oldWeatherState = null;
DateFormat dateFormat = new SimpleDateFormat("HHmm");
@ -46,7 +47,7 @@ public class Realtime extends JavaPlugin implements Listener {
}
//Wetter
WeatherState weatherState = getCurrentWeather();
updateCurrentWeather();
if(oldWeatherState != null && oldWeatherState == weatherState)
return;
@ -78,7 +79,7 @@ public class Realtime extends JavaPlugin implements Listener {
private String jsonString = "";
public WeatherState getCurrentWeather() {
public void updateCurrentWeather() {
/*
* https://openweathermap.org/current
@ -98,7 +99,7 @@ public class Realtime extends JavaPlugin implements Listener {
* Thunderstorm: ID 2xx ^
*/
new BukkitRunnable() {
Bukkit.getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
InputStream inputStream = null;
DataInputStream dataInputStream;
@ -124,29 +125,34 @@ public class Realtime extends JavaPlugin implements Listener {
} finally {
IOUtils.closeQuietly(inputStream);
}
JSONObject jsonObject = (JSONObject) JSONValue.parse(jsonString);
String weather;
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;
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;
}
}
}.runTaskAsynchronously(this);
JSONObject jsonObject = (JSONObject) JSONValue.parse(jsonString);
String weather;
JSONArray jsonArray = (JSONArray) jsonObject.get("weather");
JSONObject arrayObject = (JSONObject) jsonArray.get(0);
weather = String.valueOf((int) (long) arrayObject.get("id"));
String firstChar = Character.toString(weather.charAt(0));
switch (firstChar) {
case "6":
return WeatherState.SNOW;
case "5": case "3": //3 = Drizzle
return WeatherState.RAIN;
case "2":
return WeatherState.THUNDER_STORM;
default:
return WeatherState.CLEAR_SKY; //case 8 ebenfalls CLEAR_SKY
}
}, 0);
}
enum WeatherState {