diff --git a/Realtime.iml b/Realtime.iml
index f3c4b8a..96d8037 100644
--- a/Realtime.iml
+++ b/Realtime.iml
@@ -9,6 +9,6 @@
-
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 6519705..38f1ac8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,7 +46,7 @@
steamwar
Spigot
- 1.0
+ 1.12
provided
diff --git a/src/de/steamwar/realtime/Realtime.java b/src/de/steamwar/realtime/Realtime.java
index ca036c4..b25cd6e 100644
--- a/src/de/steamwar/realtime/Realtime.java
+++ b/src/de/steamwar/realtime/Realtime.java
@@ -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 {