diff --git a/pom.xml b/pom.xml
index 2e88faf..326faa3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,7 +49,7 @@
eu.m724
wtapi
- 0.5
+ 0.6
diff --git a/src/main/java/eu/m724/realweather/RealWeatherPlugin.java b/src/main/java/eu/m724/realweather/RealWeatherPlugin.java
index defdb9e..e4b50a4 100644
--- a/src/main/java/eu/m724/realweather/RealWeatherPlugin.java
+++ b/src/main/java/eu/m724/realweather/RealWeatherPlugin.java
@@ -14,9 +14,9 @@ import com.google.common.base.Charsets;
import eu.m724.realweather.commands.AdminCommand;
import eu.m724.realweather.commands.GeoCommand;
import eu.m724.realweather.commands.LocalTimeCommand;
+import eu.m724.realweather.exception.UserError;
import eu.m724.realweather.mapper.Mapper;
import eu.m724.realweather.mapper.MapperConfig;
-import eu.m724.realweather.object.UserException;
import eu.m724.realweather.thunder.ThunderConfig;
import eu.m724.realweather.thunder.ThunderMaster;
import eu.m724.realweather.time.TimeConfig;
@@ -26,6 +26,7 @@ import eu.m724.realweather.updater.Updater;
import eu.m724.realweather.updater.UpdaterConfig;
import eu.m724.realweather.weather.WeatherConfig;
import eu.m724.realweather.weather.WeatherMaster;
+import eu.m724.wtapi.provider.exception.NoSuchProviderException;
import eu.m724.wtapi.provider.exception.ProviderException;
public class RealWeatherPlugin extends JavaPlugin {
@@ -118,7 +119,7 @@ public class RealWeatherPlugin extends JavaPlugin {
GlobalConstants.updaterConfig = UpdaterConfig.fromConfiguration(configuration.getConfigurationSection("updater"));
updater = new Updater(GlobalConstants.updaterConfig);
updater.init();
- } catch (UserException e) {
+ } catch (UserError | NoSuchProviderException e) {
logger.severe("There are errors in your config:");
logger.severe(e.getMessage());
diff --git a/src/main/java/eu/m724/realweather/exception/UserError.java b/src/main/java/eu/m724/realweather/exception/UserError.java
new file mode 100644
index 0000000..890dade
--- /dev/null
+++ b/src/main/java/eu/m724/realweather/exception/UserError.java
@@ -0,0 +1,11 @@
+package eu.m724.realweather.exception;
+
+public class UserError extends Error {
+
+ private static final long serialVersionUID = 7152429719832602384L;
+
+ public UserError(String message) {
+ super(message);
+ }
+
+}
diff --git a/src/main/java/eu/m724/realweather/object/UserException.java b/src/main/java/eu/m724/realweather/object/UserException.java
deleted file mode 100644
index af04a19..0000000
--- a/src/main/java/eu/m724/realweather/object/UserException.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package eu.m724.realweather.object;
-
-public class UserException extends Exception {
-
- private static final long serialVersionUID = 6850666306511891275L;
-
- public UserException(String message) {
- super(message);
- }
-
-}
diff --git a/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java b/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java
index e08a2d0..9987f77 100644
--- a/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java
+++ b/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java
@@ -4,10 +4,10 @@ import org.bukkit.plugin.Plugin;
import eu.m724.realweather.DebugLogger;
import eu.m724.realweather.GlobalConstants;
-import eu.m724.realweather.object.UserException;
+import eu.m724.wtapi.provider.Providers;
+import eu.m724.wtapi.provider.exception.NoSuchProviderException;
import eu.m724.wtapi.provider.exception.ProviderException;
-import eu.m724.wtapi.thunder.ThunderProvider;
-import eu.m724.wtapi.thunder.impl.blitzortung.BlitzortungProvider;
+import eu.m724.wtapi.provider.thunder.ThunderProvider;
public class ThunderMaster {
private ThunderConfig config;
@@ -22,18 +22,14 @@ public class ThunderMaster {
/**
* initializes, tests and starts
- * @throws UserException config issue
* @throws ProviderException if provider initialization failed
+ * @throws NoSuchProviderException config issue
*/
- public void init() throws UserException, ProviderException {
+ public void init() throws ProviderException, NoSuchProviderException {
if (!config.enabled)
return;
- provider = createProvider();
-
- if (provider == null)
- throw new UserException("Invalid provider: " + config.provider);
-
+ provider = Providers.getThunderProvider(config.provider, null);
provider.init();
thunderTask = new ThunderTask(provider);
@@ -43,15 +39,6 @@ public class ThunderMaster {
DebugLogger.info("thunder loaded", 1);
}
- private ThunderProvider createProvider() {
- switch (config.provider) {
- case "blitzortung":
- return new BlitzortungProvider();
- }
-
- return null;
- }
-
public long getLatency() {
return provider.getLatency();
}
diff --git a/src/main/java/eu/m724/realweather/thunder/ThunderTask.java b/src/main/java/eu/m724/realweather/thunder/ThunderTask.java
index 1d29daf..f03b42f 100644
--- a/src/main/java/eu/m724/realweather/thunder/ThunderTask.java
+++ b/src/main/java/eu/m724/realweather/thunder/ThunderTask.java
@@ -8,8 +8,8 @@ import org.bukkit.scheduler.BukkitRunnable;
import eu.m724.realweather.DebugLogger;
import eu.m724.realweather.GlobalConstants;
import eu.m724.realweather.mapper.Mapper;
-import eu.m724.wtapi.thunder.ThunderProvider;
-import eu.m724.wtapi.thunder.impl.blitzortung.TimedStrike;
+import eu.m724.wtapi.provider.thunder.ThunderProvider;
+import eu.m724.wtapi.provider.thunder.impl.blitzortung.TimedStrike;
class ThunderTask extends BukkitRunnable {
private ThunderProvider thunderProvider;
diff --git a/src/main/java/eu/m724/realweather/time/TimeMaster.java b/src/main/java/eu/m724/realweather/time/TimeMaster.java
index ced4488..44bcd08 100644
--- a/src/main/java/eu/m724/realweather/time/TimeMaster.java
+++ b/src/main/java/eu/m724/realweather/time/TimeMaster.java
@@ -6,7 +6,6 @@ import org.bukkit.plugin.Plugin;
import eu.m724.realweather.DebugLogger;
import eu.m724.realweather.GlobalConstants;
import eu.m724.realweather.mapper.Mapper;
-import eu.m724.realweather.object.UserException;
public class TimeMaster {
private TimeConfig timeConfig;
@@ -17,15 +16,11 @@ public class TimeMaster {
this.timeConfig = timeConfig;
}
- /**
- * initializes, tests and starts
- * @throws UserException config issue
- */
- public void init() throws UserException {
+
+ public void init() {
if (!timeConfig.enabled)
return;
-
long period = (long) (72 / timeConfig.scale);
if (timeConfig.scale * Math.floor(period) != 72.0) {
diff --git a/src/main/java/eu/m724/realweather/updater/Updater.java b/src/main/java/eu/m724/realweather/updater/Updater.java
index 8a4b448..463cecf 100644
--- a/src/main/java/eu/m724/realweather/updater/Updater.java
+++ b/src/main/java/eu/m724/realweather/updater/Updater.java
@@ -17,7 +17,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import eu.m724.realweather.DebugLogger;
import eu.m724.realweather.GlobalConstants;
-import eu.m724.realweather.object.UserException;
+import eu.m724.realweather.exception.UserError;
import eu.m724.realweather.updater.metadata.MetadataRetriever;
import eu.m724.realweather.updater.metadata.MetadataServerException;
import eu.m724.realweather.updater.metadata.VersionMetadata;
@@ -50,13 +50,13 @@ public class Updater extends BukkitRunnable implements Listener {
this.metadataRetriever = new MetadataRetriever(plugin, updaterConfig.channel);
}
- public void init() throws UserException {
+ public void init() {
try {
DebugLogger.info("probing for channels...", 1);
List channels = metadataRetriever.getChannels().join();
if (!channels.contains(updaterConfig.channel)) {
- throw new UserException(
+ throw new UserError( // TODO replace this with its own error / exception?
"Invalid channel: %s. Valid ones are: %s"
.formatted(updaterConfig.channel, String.join(", ", channels))); // WHY DID NOBODY TELL ME ABOUT .formatted
}
diff --git a/src/main/java/eu/m724/realweather/weather/AsyncWeatherRetriever.java b/src/main/java/eu/m724/realweather/weather/AsyncWeatherRetriever.java
index f2ddec1..4f9de91 100644
--- a/src/main/java/eu/m724/realweather/weather/AsyncWeatherRetriever.java
+++ b/src/main/java/eu/m724/realweather/weather/AsyncWeatherRetriever.java
@@ -19,7 +19,7 @@ import eu.m724.realweather.mapper.Mapper;
import eu.m724.realweather.weather.event.AsyncWeatherUpdateEvent;
import eu.m724.wtapi.object.Coordinates;
import eu.m724.wtapi.object.Weather;
-import eu.m724.wtapi.provider.WeatherProvider;
+import eu.m724.wtapi.provider.weather.WeatherProvider;
public class AsyncWeatherRetriever extends BukkitRunnable implements Listener { // TODO split this
private WeatherProvider weatherProvider;
diff --git a/src/main/java/eu/m724/realweather/weather/WeatherMaster.java b/src/main/java/eu/m724/realweather/weather/WeatherMaster.java
index 5836bde..1486ccf 100644
--- a/src/main/java/eu/m724/realweather/weather/WeatherMaster.java
+++ b/src/main/java/eu/m724/realweather/weather/WeatherMaster.java
@@ -6,10 +6,10 @@ import org.bukkit.plugin.Plugin;
import eu.m724.realweather.DebugLogger;
import eu.m724.realweather.GlobalConstants;
import eu.m724.realweather.mapper.Mapper;
-import eu.m724.realweather.object.UserException;
-import eu.m724.wtapi.provider.WeatherProvider;
+import eu.m724.wtapi.provider.Providers;
+import eu.m724.wtapi.provider.exception.NoSuchProviderException;
import eu.m724.wtapi.provider.exception.ProviderException;
-import eu.m724.wtapi.provider.impl.openweathermap.OpenWeatherMapProvider;
+import eu.m724.wtapi.provider.weather.WeatherProvider;
public class WeatherMaster {
private WeatherConfig config;
@@ -23,18 +23,14 @@ public class WeatherMaster {
/**
* initializes, tests and starts
- * @throws UserException config issue
* @throws ProviderException if provider initialization failed
+ * @throws NoSuchProviderException config issue
*/
- public void init() throws UserException, ProviderException {
+ public void init() throws ProviderException, NoSuchProviderException {
if (!config.enabled)
return;
- provider = createProvider();
-
- if (provider == null)
- throw new UserException("Invalid provider: " + config.provider);
-
+ provider = Providers.getWeatherProvider(config.provider, config.apiKey);
provider.init();
AsyncWeatherRetriever retriever = new AsyncWeatherRetriever(provider);
@@ -46,13 +42,4 @@ public class WeatherMaster {
DebugLogger.info("weather loaded", 1);
}
-
- private WeatherProvider createProvider() {
- switch (config.provider) {
- case "openweathermap":
- return new OpenWeatherMapProvider(config.apiKey);
- }
-
- return null;
- }
}