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
Nur Änderungen aus Commit 06e67be6e3 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

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