added real time and realtime weather
Dieser Commit ist enthalten in:
Ursprung
ede8f512ee
Commit
e84b2625c3
14
Realtime.iml
Normale Datei
14
Realtime.iml
Normale Datei
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||||
|
<output url="file://$MODULE_DIR$/target/classes" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: steamwar:Spigot:1.0" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -1,10 +1,21 @@
|
||||||
package de.steamwar.realtime;
|
package de.steamwar.realtime;
|
||||||
|
|
||||||
|
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.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.JSONValue;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class Realtime extends JavaPlugin {
|
public class Realtime extends JavaPlugin {
|
||||||
|
@ -12,11 +23,120 @@ public class Realtime extends JavaPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void onEnable(){
|
public void onEnable(){
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
||||||
Date time = Calendar.getInstance().getTime();
|
/*Date time = Calendar.getInstance().getTime();
|
||||||
long l = time.getHours() * 1000 + (long)(time.getMinutes() * 16.66666666666667) + (long)(time.getSeconds() * 0.1666666666666667) - 6000;
|
long l = time.getHours() * 1000 + (long)(time.getMinutes() * 16.66666666666667) + (long)(time.getSeconds() * 0.1666666666666667) - 6000;
|
||||||
for(World w : Bukkit.getWorlds()){
|
for(World w : Bukkit.getWorlds()){
|
||||||
w.setTime(l);
|
w.setTime(l);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
//Zeit
|
||||||
|
DateFormat dateFormat = new SimpleDateFormat("HHmm");
|
||||||
|
Date date = new Date();
|
||||||
|
int time = Integer.parseInt((dateFormat.format(date) + "0"));
|
||||||
|
|
||||||
|
time -= 6000;
|
||||||
|
|
||||||
|
if(time < 0) {
|
||||||
|
time+= 24000;
|
||||||
}
|
}
|
||||||
}, 0, 600);
|
|
||||||
|
//Wetter
|
||||||
|
WeatherState weatherState = getCurrentWeather();
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WeatherState getCurrentWeather() {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* https://openweathermap.org/current
|
||||||
|
*
|
||||||
|
* http://api.openweathermap.org/data/2.5/weather?id=
|
||||||
|
* ID
|
||||||
|
* &APPID=16e8ffada1fbdbe3f3903802b0785751
|
||||||
|
*
|
||||||
|
* Berlin id: 2950159
|
||||||
|
*
|
||||||
|
* ID Liste: https://openweathermap.org/weather-conditions
|
||||||
|
*
|
||||||
|
* Clear Sky: ID 800
|
||||||
|
* Snow: ID 6xx -> xx sind alle Zahlen hinter der 6
|
||||||
|
* Rain: ID 5xx -> ^
|
||||||
|
* 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));
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum WeatherState {
|
||||||
|
CLEAR_SKY,
|
||||||
|
RAIN,
|
||||||
|
THUNDER_STORM,
|
||||||
|
SNOW
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren