SteamWar/RealTime
Archiviert
13
0
Dieser Commit ist enthalten in:
Yaruma3341 2019-12-19 17:10:26 +01:00
Ursprung e84b2625c3
Commit 5aec7f9872
3 geänderte Dateien mit 56 neuen und 34 gelöschten Zeilen

1
.gitignore vendored
Datei anzeigen

@ -1,2 +1,3 @@
.idea .idea
target target
*.iml

Datei anzeigen

@ -3,7 +3,12 @@ package de.steamwar.realtime;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; 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.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
@ -18,19 +23,19 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
public class Realtime extends JavaPlugin { public class Realtime extends JavaPlugin implements Listener {
@Override @Override
public void onEnable() { public void onEnable() {
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { PluginManager pluginManager = Bukkit.getPluginManager();
/*Date time = Calendar.getInstance().getTime(); pluginManager.registerEvents(this, this);
long l = time.getHours() * 1000 + (long)(time.getMinutes() * 16.66666666666667) + (long)(time.getSeconds() * 0.1666666666666667) - 6000;
for(World w : Bukkit.getWorlds()){ WeatherState oldWeatherState = null;
w.setTime(l);
}*/
//Zeit
DateFormat dateFormat = new SimpleDateFormat("HHmm"); DateFormat dateFormat = new SimpleDateFormat("HHmm");
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
//Zeit
Date date = new Date(); Date date = new Date();
int time = Integer.parseInt((dateFormat.format(date) + "0")); int time = Integer.parseInt((dateFormat.format(date) + "0"));
@ -42,6 +47,8 @@ public class Realtime extends JavaPlugin {
//Wetter //Wetter
WeatherState weatherState = getCurrentWeather(); WeatherState weatherState = getCurrentWeather();
if(oldWeatherState != null && oldWeatherState == weatherState)
return;
for(World world : Bukkit.getWorlds()) { for(World world : Bukkit.getWorlds()) {
@ -69,6 +76,8 @@ public class Realtime extends JavaPlugin {
}, 0, 20 * 60); }, 0, 20 * 60);
} }
private String jsonString = "";
public WeatherState getCurrentWeather() { public WeatherState getCurrentWeather() {
/* /*
@ -88,9 +97,13 @@ public class Realtime extends JavaPlugin {
* Drizzle (Nieselregen): ID 3xx -> ^ * Drizzle (Nieselregen): ID 3xx -> ^
* Thunderstorm: ID 2xx ^ * Thunderstorm: ID 2xx ^
*/ */
new BukkitRunnable() {
InputStream inputStream = null; InputStream inputStream = null;
DataInputStream dataInputStream; DataInputStream dataInputStream;
String jsonString = "";
@Override
public void run() {
try { 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=2950159&APPID=16e8ffada1fbdbe3f3903802b0785751");
inputStream = url.openStream(); inputStream = url.openStream();
@ -111,6 +124,9 @@ public class Realtime extends JavaPlugin {
} finally { } finally {
IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(inputStream);
} }
}
}.runTaskAsynchronously(this);
JSONObject jsonObject = (JSONObject) JSONValue.parse(jsonString); JSONObject jsonObject = (JSONObject) JSONValue.parse(jsonString);
@ -139,4 +155,9 @@ public class Realtime extends JavaPlugin {
THUNDER_STORM, THUNDER_STORM,
SNOW SNOW
} }
@EventHandler
public void handleBlockForm(BlockFormEvent event) {
Bukkit.broadcastMessage(event.getBlock() + " : " + event.getNewState().toString());
}
} }