From 5aec7f98720aa3a148ea77b814b49933ea23c704 Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Thu, 19 Dec 2019 17:10:26 +0100 Subject: [PATCH 1/8] cleanup --- .gitignore | 1 + pom.xml | 12 ++-- src/de/steamwar/realtime/Realtime.java | 77 ++++++++++++++++---------- 3 files changed, 56 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index ee44a96..18f0443 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea target +*.iml \ No newline at end of file diff --git a/pom.xml b/pom.xml index e9f4ae3..6519705 100644 --- a/pom.xml +++ b/pom.xml @@ -43,11 +43,11 @@ - - steamwar - Spigot - 1.0 - provided - + + steamwar + Spigot + 1.0 + provided + \ No newline at end of file diff --git a/src/de/steamwar/realtime/Realtime.java b/src/de/steamwar/realtime/Realtime.java index 47a86fa..ca036c4 100644 --- a/src/de/steamwar/realtime/Realtime.java +++ b/src/de/steamwar/realtime/Realtime.java @@ -3,7 +3,12 @@ package de.steamwar.realtime; import org.apache.commons.io.IOUtils; import org.bukkit.Bukkit; import org.bukkit.World; +import org.bukkit.event.EventHandler; +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; @@ -18,19 +23,19 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; -public class Realtime extends JavaPlugin { +public class Realtime extends JavaPlugin implements Listener { @Override - public void onEnable(){ - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { - /*Date time = Calendar.getInstance().getTime(); - long l = time.getHours() * 1000 + (long)(time.getMinutes() * 16.66666666666667) + (long)(time.getSeconds() * 0.1666666666666667) - 6000; - for(World w : Bukkit.getWorlds()){ - w.setTime(l); - }*/ + public void onEnable() { + PluginManager pluginManager = Bukkit.getPluginManager(); + pluginManager.registerEvents(this, this); + WeatherState oldWeatherState = null; + + DateFormat dateFormat = new SimpleDateFormat("HHmm"); + + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { //Zeit - DateFormat dateFormat = new SimpleDateFormat("HHmm"); Date date = new Date(); int time = Integer.parseInt((dateFormat.format(date) + "0")); @@ -42,6 +47,8 @@ public class Realtime extends JavaPlugin { //Wetter WeatherState weatherState = getCurrentWeather(); + if(oldWeatherState != null && oldWeatherState == weatherState) + return; for(World world : Bukkit.getWorlds()) { @@ -69,6 +76,8 @@ public class Realtime extends JavaPlugin { }, 0, 20 * 60); } + + private String jsonString = ""; public WeatherState getCurrentWeather() { /* @@ -88,29 +97,36 @@ public class Realtime extends JavaPlugin { * Drizzle (Nieselregen): ID 3xx -> ^ * Thunderstorm: ID 2xx ^ */ - InputStream inputStream = null; - DataInputStream dataInputStream; - String jsonString = ""; - try { - URL url = new URL("http://api.openweathermap.org/data/2.5/weather?id=2950159&APPID=16e8ffada1fbdbe3f3903802b0785751"); - inputStream = url.openStream(); - dataInputStream = new DataInputStream(new BufferedInputStream(inputStream)); + new BukkitRunnable() { + InputStream inputStream = null; + DataInputStream dataInputStream; - StringBuilder stringBuilder = new StringBuilder(); - String inputLine; + @Override + public void run() { + try { + URL url = new URL("http://api.openweathermap.org/data/2.5/weather?id=2950159&APPID=16e8ffada1fbdbe3f3903802b0785751"); + inputStream = url.openStream(); - while ((inputLine = dataInputStream.readLine()) != null) { - stringBuilder.append(inputLine); + dataInputStream = new DataInputStream(new BufferedInputStream(inputStream)); + + 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); + } } - jsonString = stringBuilder.toString(); - } catch (MalformedURLException ex) { - ex.printStackTrace(); - } catch (IOException ex) { - ex.printStackTrace(); - } finally { - IOUtils.closeQuietly(inputStream); - } + }.runTaskAsynchronously(this); + JSONObject jsonObject = (JSONObject) JSONValue.parse(jsonString); @@ -139,4 +155,9 @@ public class Realtime extends JavaPlugin { THUNDER_STORM, SNOW } + + @EventHandler + public void handleBlockForm(BlockFormEvent event) { + Bukkit.broadcastMessage(event.getBlock() + " : " + event.getNewState().toString()); + } } -- 2.39.5 From 7b5ffcfe75ef5447830bfcfee2c92e878413b3a9 Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Thu, 19 Dec 2019 18:05:40 +0100 Subject: [PATCH 2/8] cleanup --- Realtime.iml | 2 +- pom.xml | 2 +- src/de/steamwar/realtime/Realtime.java | 60 ++++++++++++++------------ 3 files changed, 35 insertions(+), 29 deletions(-) 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 { -- 2.39.5 From 06e67be6e3daef4692d45dc013b9ed2342cba978 Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Mon, 13 Jan 2020 19:02:39 +0100 Subject: [PATCH 3/8] cleanup and hotfixes --- src/de/steamwar/realtime/Realtime.java | 78 +++++++++++++------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/de/steamwar/realtime/Realtime.java b/src/de/steamwar/realtime/Realtime.java index b25cd6e..b16b7d8 100644 --- a/src/de/steamwar/realtime/Realtime.java +++ b/src/de/steamwar/realtime/Realtime.java @@ -3,9 +3,7 @@ package de.steamwar.realtime; import org.apache.commons.io.IOUtils; import org.bukkit.Bukkit; import org.bukkit.World; -import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockFormEvent; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.json.simple.JSONArray; @@ -24,19 +22,25 @@ import java.util.Date; public class Realtime extends JavaPlugin implements Listener { + DateFormat dateFormat = new SimpleDateFormat("HHmm"); + WeatherState oldWeatherState = null; WeatherState weatherState = null; + private static Realtime instance; + + public static Realtime getInstance() { + return instance; + } + @Override public void onEnable() { + instance = this; PluginManager pluginManager = Bukkit.getPluginManager(); pluginManager.registerEvents(this, this); - - DateFormat dateFormat = new SimpleDateFormat("HHmm"); - + //Time updater Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { - //Zeit Date date = new Date(); int time = Integer.parseInt((dateFormat.format(date) + "0")); @@ -46,35 +50,12 @@ public class Realtime extends JavaPlugin implements Listener { time+= 24000; } - //Wetter - updateCurrentWeather(); - if(oldWeatherState != null && oldWeatherState == weatherState) - return; - - - for(World world : Bukkit.getWorlds()) { + for(World world : Bukkit.getWorlds()) world.setTime(time); - - switch (weatherState) { - case CLEAR_SKY: - world.setThundering(false); - world.setStorm(false); - break; - case RAIN: - world.setThundering(false); - world.setStorm(true); - break; - case THUNDER_STORM: - world.setThundering(true); - world.setStorm(true); - break; - case SNOW: - world.setThundering(false); - world.setStorm(true); - //Biom muss geändert werden - } - } }, 0, 20 * 60); + + //Weather Updater + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> updateCurrentWeather(), 0, 20 * 60/* * 10*/); //Die Wetterdaten werden bei OpenWeatherMAP nur alle 10 Minuten erneuert } @@ -89,6 +70,7 @@ public class Realtime extends JavaPlugin implements Listener { * &APPID=16e8ffada1fbdbe3f3903802b0785751 * * Berlin id: 2950159 + * Düsseldorf id: 2934245 * * ID Liste: https://openweathermap.org/weather-conditions * @@ -106,7 +88,7 @@ public class Realtime extends JavaPlugin implements Listener { @Override public void run() { try { - URL url = new URL("http://api.openweathermap.org/data/2.5/weather?id=2950159&APPID=16e8ffada1fbdbe3f3903802b0785751"); + 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)); @@ -151,6 +133,29 @@ public class Realtime extends JavaPlugin implements Listener { 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 RAIN: case SNOW: + world.setThundering(false); + world.setStorm(true); + break; + case THUNDER_STORM: + world.setThundering(true); + world.setStorm(true); + break; + } + } + }, 0); } }, 0); } @@ -161,9 +166,4 @@ public class Realtime extends JavaPlugin implements Listener { THUNDER_STORM, SNOW } - - @EventHandler - public void handleBlockForm(BlockFormEvent event) { - Bukkit.broadcastMessage(event.getBlock() + " : " + event.getNewState().toString()); - } } -- 2.39.5 From 6953836b12faed774084bdb270bd57fd3f7d6cb1 Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Mon, 13 Jan 2020 19:07:20 +0100 Subject: [PATCH 4/8] hotfix --- src/de/steamwar/realtime/Realtime.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/realtime/Realtime.java b/src/de/steamwar/realtime/Realtime.java index b16b7d8..5fa529e 100644 --- a/src/de/steamwar/realtime/Realtime.java +++ b/src/de/steamwar/realtime/Realtime.java @@ -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().scheduleSyncRepeatingTask(this, () -> updateCurrentWeather(), 0, 20 * 60 * 10); //Die Wetterdaten werden bei OpenWeatherMAP nur alle 10 Minuten erneuert } -- 2.39.5 From 31aefc37737689f9f752021feef5a45f072b4bef Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Thu, 16 Jan 2020 22:19:47 +0100 Subject: [PATCH 5/8] =?UTF-8?q?=E2=80=9ERealtime.iml=E2=80=9C=20l=C3=B6sch?= =?UTF-8?q?en?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Realtime.iml | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 Realtime.iml diff --git a/Realtime.iml b/Realtime.iml deleted file mode 100644 index 96d8037..0000000 --- a/Realtime.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file -- 2.39.5 From 243a8f000229f9692048849073a9e0ad7d84196c Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Thu, 16 Jan 2020 22:34:27 +0100 Subject: [PATCH 6/8] code cleanup --- src/de/steamwar/realtime/Realtime.java | 122 ++++++++++++------------- 1 file changed, 59 insertions(+), 63 deletions(-) diff --git a/src/de/steamwar/realtime/Realtime.java b/src/de/steamwar/realtime/Realtime.java index 5fa529e..8861de8 100644 --- a/src/de/steamwar/realtime/Realtime.java +++ b/src/de/steamwar/realtime/Realtime.java @@ -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); } -- 2.39.5 From f283d822b6790dcba81261e993ec31a6b770253e Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Sat, 18 Jan 2020 19:42:37 +0100 Subject: [PATCH 7/8] added config --- src/de/steamwar/realtime/Config.java | 31 +++++++++++++++++++ src/de/steamwar/realtime/Realtime.java | 43 ++++++++++++++++---------- src/weather.yml | 2 ++ 3 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 src/de/steamwar/realtime/Config.java create mode 100644 src/weather.yml diff --git a/src/de/steamwar/realtime/Config.java b/src/de/steamwar/realtime/Config.java new file mode 100644 index 0000000..a0b6491 --- /dev/null +++ b/src/de/steamwar/realtime/Config.java @@ -0,0 +1,31 @@ +package de.steamwar.realtime; + +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; + +import java.io.File; +import java.util.logging.Level; + +public class Config { + + private Config() {} + + private static Realtime instance = Realtime.getInstance(); + + //Cache + public static final boolean RealTime; + public static final boolean RealWeather; + + static { + if(!new File(instance.getDataFolder(), "weather.yml").exists()) { + instance.saveDefaultConfig(); + Bukkit.getLogger().log(Level.SEVERE, "Config fehlt!"); + instance.shutdown(null); + } + FileConfiguration config = instance.getConfig(); + RealTime = config.getBoolean("RealTime"); + RealWeather = config.getBoolean("RealWeather"); + } + + +} diff --git a/src/de/steamwar/realtime/Realtime.java b/src/de/steamwar/realtime/Realtime.java index 8861de8..01be430 100644 --- a/src/de/steamwar/realtime/Realtime.java +++ b/src/de/steamwar/realtime/Realtime.java @@ -22,17 +22,13 @@ import java.util.Date; public class Realtime extends JavaPlugin implements Listener { + private static Realtime instance; + DateFormat dateFormat = new SimpleDateFormat("HHmm"); WeatherState oldWeatherState = null; WeatherState weatherState = null; - private static Realtime instance; - - public static Realtime getInstance() { - return instance; - } - @Override public void onEnable() { instance = this; @@ -40,22 +36,26 @@ public class Realtime extends JavaPlugin implements Listener { pluginManager.registerEvents(this, this); //Time updater - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { - Date date = new Date(); - int time = Integer.parseInt((dateFormat.format(date) + "0")); + if(Config.RealTime) { + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { + Date date = new Date(); + int time = Integer.parseInt((dateFormat.format(date) + "0")); - time -= 6000; + time -= 6000; - if(time < 0) { - time+= 24000; - } + if(time < 0) { + time+= 24000; + } - for(World world : Bukkit.getWorlds()) - world.setTime(time); - }, 0, 20 * 60); + for(World world : Bukkit.getWorlds()) + world.setTime(time); + }, 0, 20 * 60); + } //Weather Updater - Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, () -> updateCurrentWeather(), 0, 20 * 60 * 10); //Die Wetterdaten werden bei OpenWeatherMAP nur alle 10 Minuten erneuert + if(Config.RealWeather) { + Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, () -> updateCurrentWeather(), 0, 20 * 60 * 10); //Die Wetterdaten werden bei OpenWeatherMAP nur alle 10 Minuten erneuert + } } @@ -156,6 +156,15 @@ public class Realtime extends JavaPlugin implements Listener { }, 0); } + public void shutdown(final String reason) { + Bukkit.getOnlinePlayers().forEach(player -> player.kickPlayer(reason)); + Bukkit.shutdown(); + } + + public static Realtime getInstance() { + return instance; + } + enum WeatherState { CLEAR_SKY, RAIN, diff --git a/src/weather.yml b/src/weather.yml new file mode 100644 index 0000000..da4c7b4 --- /dev/null +++ b/src/weather.yml @@ -0,0 +1,2 @@ +RealTime: +RealWeather: \ No newline at end of file -- 2.39.5 From cc486725cbac869e949070cdd25d907fd20617ae Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Sun, 23 Feb 2020 23:13:10 +0100 Subject: [PATCH 8/8] hotfix --- src/de/steamwar/realtime/Config.java | 13 +++++++------ src/weather.yml | 2 -- 2 files changed, 7 insertions(+), 8 deletions(-) delete mode 100644 src/weather.yml diff --git a/src/de/steamwar/realtime/Config.java b/src/de/steamwar/realtime/Config.java index a0b6491..540fd47 100644 --- a/src/de/steamwar/realtime/Config.java +++ b/src/de/steamwar/realtime/Config.java @@ -17,14 +17,15 @@ public class Config { public static final boolean RealWeather; static { - if(!new File(instance.getDataFolder(), "weather.yml").exists()) { - instance.saveDefaultConfig(); + if(!new File(Bukkit.getWorlds().get(0).getWorldFolder(), "weather.yml").exists()) { Bukkit.getLogger().log(Level.SEVERE, "Config fehlt!"); - instance.shutdown(null); + RealTime = true; + RealWeather = false; + } else { + FileConfiguration config = instance.getConfig(); + RealTime = config.getBoolean("RealTime"); + RealWeather = config.getBoolean("RealWeather"); } - FileConfiguration config = instance.getConfig(); - RealTime = config.getBoolean("RealTime"); - RealWeather = config.getBoolean("RealWeather"); } diff --git a/src/weather.yml b/src/weather.yml deleted file mode 100644 index da4c7b4..0000000 --- a/src/weather.yml +++ /dev/null @@ -1,2 +0,0 @@ -RealTime: -RealWeather: \ No newline at end of file -- 2.39.5