n
This commit is contained in:
commit
65d528f700
9 changed files with 214 additions and 0 deletions
25
.classpath
Normal file
25
.classpath
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
/target/
|
||||||
|
|
||||||
|
org.eclipse.*
|
23
.project
Normal file
23
.project
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>realweather</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
41
pom.xml
Normal file
41
pom.xml
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>pl.minecon724</groupId>
|
||||||
|
<artifactId>realweather</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.18.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
<version>20220320</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
</project>
|
14
src/main/java/pl/minecon724/realweather/RW.java
Normal file
14
src/main/java/pl/minecon724/realweather/RW.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package pl.minecon724.realweather;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class RW extends JavaPlugin {
|
||||||
|
FileConfiguration config;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
saveDefaultConfig();
|
||||||
|
config = getConfig();
|
||||||
|
}
|
||||||
|
}
|
6
src/main/java/pl/minecon724/realweather/Source.java
Normal file
6
src/main/java/pl/minecon724/realweather/Source.java
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package pl.minecon724.realweather;
|
||||||
|
|
||||||
|
public interface Source {
|
||||||
|
public void init();
|
||||||
|
public WeatherState.State request_state(double lat, double lon);
|
||||||
|
}
|
31
src/main/java/pl/minecon724/realweather/WeatherState.java
Normal file
31
src/main/java/pl/minecon724/realweather/WeatherState.java
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package pl.minecon724.realweather;
|
||||||
|
|
||||||
|
public class WeatherState {
|
||||||
|
|
||||||
|
// Enums
|
||||||
|
|
||||||
|
public enum Condition { THUNDER, DRIZZLE, RAIN, SNOW, CLEAR, CLOUDY };
|
||||||
|
public enum ConditionLevel { LIGHT, MODERATE, HEAVY, EXTREME };
|
||||||
|
public enum ConditionSimple { THUNDER, RAIN, CLEAR };
|
||||||
|
|
||||||
|
// State class
|
||||||
|
|
||||||
|
public class State {
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
|
||||||
|
Condition condition;
|
||||||
|
ConditionLevel level;
|
||||||
|
ConditionSimple simple;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
|
||||||
|
public State(Condition condition,
|
||||||
|
ConditionLevel level,
|
||||||
|
ConditionSimple simple) {
|
||||||
|
this.condition = condition;
|
||||||
|
this.level = level;
|
||||||
|
this.simple = simple;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package pl.minecon724.realweather.provider;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import pl.minecon724.realweather.*;
|
||||||
|
import pl.minecon724.realweather.WeatherState.State;
|
||||||
|
|
||||||
|
public class OpenWeatherMapProvider implements Source {
|
||||||
|
|
||||||
|
URL endpoint;
|
||||||
|
|
||||||
|
RW main;
|
||||||
|
String apiKey;
|
||||||
|
|
||||||
|
public OpenWeatherMapProvider(RW main, String apiKey) {
|
||||||
|
this.main = main;
|
||||||
|
this.apiKey = apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
try {
|
||||||
|
endpoint = new URL("https://api.openweathermap.org");
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public State request_state(double lat, double lon) {
|
||||||
|
JSONObject json;
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
HttpURLConnection con = (HttpURLConnection) endpoint.openConnection();
|
||||||
|
con.setRequestMethod("GET");
|
||||||
|
int status = con.getResponseCode();
|
||||||
|
InputStream stream = status > 299 ? con.getErrorStream() : con.getInputStream();
|
||||||
|
BufferedReader rd = new BufferedReader(
|
||||||
|
new InputStreamReader(stream));
|
||||||
|
String line;
|
||||||
|
StringBuffer content = new StringBuffer();
|
||||||
|
while ((line = rd.readLine()) != null) {
|
||||||
|
content.append(line);
|
||||||
|
}
|
||||||
|
rd.close();
|
||||||
|
con.disconnect();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
content['a']
|
||||||
|
Condition condition;
|
||||||
|
switch () {
|
||||||
|
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
5
src/main/resources/plugin.yml
Normal file
5
src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
name: RealWeather
|
||||||
|
version: ${project.version}
|
||||||
|
api-version: 1.18
|
||||||
|
author: Minecon724
|
||||||
|
main: pl.minecon724.realweather.RW
|
Loading…
Reference in a new issue