SteamWar/RealTime
Archiviert
13
0
Dieser Commit ist enthalten in:
Yaruma3341 2020-01-18 19:42:37 +01:00
Ursprung 243a8f0002
Commit f283d822b6
3 geänderte Dateien mit 59 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -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");
}
}

Datei anzeigen

@ -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,

2
src/weather.yml Normale Datei
Datei anzeigen

@ -0,0 +1,2 @@
RealTime:
RealWeather: