From 65d528f700010d9b7f9d4013f636781d85f561cb Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Sat, 23 Apr 2022 09:27:48 +0200 Subject: [PATCH] n --- .classpath | 25 +++++++ .gitignore | 3 + .project | 23 +++++++ pom.xml | 41 ++++++++++++ .../java/pl/minecon724/realweather/RW.java | 14 ++++ .../pl/minecon724/realweather/Source.java | 6 ++ .../minecon724/realweather/WeatherState.java | 31 +++++++++ .../provider/OpenWeatherMapProvider.java | 66 +++++++++++++++++++ src/main/resources/plugin.yml | 5 ++ 9 files changed, 214 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 pom.xml create mode 100644 src/main/java/pl/minecon724/realweather/RW.java create mode 100644 src/main/java/pl/minecon724/realweather/Source.java create mode 100644 src/main/java/pl/minecon724/realweather/WeatherState.java create mode 100644 src/main/java/pl/minecon724/realweather/provider/OpenWeatherMapProvider.java create mode 100644 src/main/resources/plugin.yml diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..0d7710f --- /dev/null +++ b/.classpath @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5f38dd6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target/ + +org.eclipse.* \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..59e25aa --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + realweather + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..10bfc61 --- /dev/null +++ b/pom.xml @@ -0,0 +1,41 @@ + + 4.0.0 + pl.minecon724 + realweather + 0.0.1 + + + 17 + 17 + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + org.spigotmc + spigot-api + 1.18.2-R0.1-SNAPSHOT + provided + + + org.json + json + 20220320 + + + + + + + src/main/resources + true + + + + \ No newline at end of file diff --git a/src/main/java/pl/minecon724/realweather/RW.java b/src/main/java/pl/minecon724/realweather/RW.java new file mode 100644 index 0000000..8b75fed --- /dev/null +++ b/src/main/java/pl/minecon724/realweather/RW.java @@ -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(); + } +} diff --git a/src/main/java/pl/minecon724/realweather/Source.java b/src/main/java/pl/minecon724/realweather/Source.java new file mode 100644 index 0000000..ed680e7 --- /dev/null +++ b/src/main/java/pl/minecon724/realweather/Source.java @@ -0,0 +1,6 @@ +package pl.minecon724.realweather; + +public interface Source { + public void init(); + public WeatherState.State request_state(double lat, double lon); +} diff --git a/src/main/java/pl/minecon724/realweather/WeatherState.java b/src/main/java/pl/minecon724/realweather/WeatherState.java new file mode 100644 index 0000000..9504905 --- /dev/null +++ b/src/main/java/pl/minecon724/realweather/WeatherState.java @@ -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; + } + } +} diff --git a/src/main/java/pl/minecon724/realweather/provider/OpenWeatherMapProvider.java b/src/main/java/pl/minecon724/realweather/provider/OpenWeatherMapProvider.java new file mode 100644 index 0000000..6e4280d --- /dev/null +++ b/src/main/java/pl/minecon724/realweather/provider/OpenWeatherMapProvider.java @@ -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; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..bdfdaa5 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,5 @@ +name: RealWeather +version: ${project.version} +api-version: 1.18 +author: Minecon724 +main: pl.minecon724.realweather.RW \ No newline at end of file