From f283d822b6790dcba81261e993ec31a6b770253e Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Sat, 18 Jan 2020 19:42:37 +0100 Subject: [PATCH] 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