a
This commit is contained in:
parent
8ef528879e
commit
7d2ef0c492
3 changed files with 13 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
package pl.minecon724.realweather;
|
package pl.minecon724.realweather;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
@ -15,25 +16,27 @@ public class GetStateTask extends BukkitRunnable {
|
||||||
double pointLatitude;
|
double pointLatitude;
|
||||||
double pointLongitude;
|
double pointLongitude;
|
||||||
List<String> worlds;
|
List<String> worlds;
|
||||||
|
Logger logger;
|
||||||
|
|
||||||
public GetStateTask(
|
public GetStateTask(
|
||||||
Provider provider, String source,
|
Provider provider, String source,
|
||||||
double pointLatitude, double pointLongitude,
|
double pointLatitude, double pointLongitude,
|
||||||
List<String> worlds
|
List<String> worlds, Logger logger
|
||||||
) {
|
) {
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.pointLatitude = pointLatitude;
|
this.pointLatitude = pointLatitude;
|
||||||
this.pointLongitude = pointLongitude;
|
this.pointLongitude = pointLongitude;
|
||||||
this.worlds = worlds;
|
this.worlds = worlds;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Bukkit.getLogger().fine("Refreshing weather by " + source);
|
logger.fine("Refreshing weather by " + source);
|
||||||
if (source.equals("point")) {
|
if (source.equals("point")) {
|
||||||
State state = provider.request_state(pointLatitude, pointLongitude);
|
State state = provider.request_state(pointLatitude, pointLongitude);
|
||||||
Bukkit.getLogger().fine(String.format("Provider returned state %s %s", state.condition.name(), state.level.name()));
|
logger.fine(String.format("Provider returned state %s %s", state.condition.name(), state.level.name()));
|
||||||
for (String w : worlds) {
|
for (String w : worlds) {
|
||||||
World world = Bukkit.getWorld(w);
|
World world = Bukkit.getWorld(w);
|
||||||
if (world == null) continue;
|
if (world == null) continue;
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class RW extends JavaPlugin {
|
||||||
ConfigurationSection settingsSec = config.getConfigurationSection("settings");
|
ConfigurationSection settingsSec = config.getConfigurationSection("settings");
|
||||||
|
|
||||||
if (settingsSec.getBoolean("debug")) {
|
if (settingsSec.getBoolean("debug")) {
|
||||||
Bukkit.getLogger().setLevel(Level.ALL);
|
this.getLogger().setLevel(Level.ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
String source = weatherSec.getString("source");
|
String source = weatherSec.getString("source");
|
||||||
|
@ -39,26 +39,26 @@ public class RW extends JavaPlugin {
|
||||||
ConfigurationSection providerCfg = providerSec.getConfigurationSection(choice);
|
ConfigurationSection providerCfg = providerSec.getConfigurationSection(choice);
|
||||||
|
|
||||||
if (providerCfg == null) {
|
if (providerCfg == null) {
|
||||||
Bukkit.getLogger().severe("Unknown provider: " + choice);
|
this.getLogger().severe("Unknown provider: " + choice);
|
||||||
Bukkit.getLogger().info("The plugin will disable now");
|
this.getLogger().info("The plugin will disable now");
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Provider provider = null;
|
Provider provider = null;
|
||||||
if (choice.equals("openweathermap")) {
|
if (choice.equals("openweathermap")) {
|
||||||
Bukkit.getLogger().info("Using OpenWeatherMap as the weather provider");
|
this.getLogger().info("Using OpenWeatherMap as the weather provider");
|
||||||
provider = new OpenWeatherMapProvider( providerCfg.getString("apiKey") );
|
provider = new OpenWeatherMapProvider( providerCfg.getString("apiKey") );
|
||||||
}
|
}
|
||||||
provider.init();
|
provider.init();
|
||||||
|
|
||||||
new GetStateTask(
|
new GetStateTask(
|
||||||
provider, source, pointLatitude, pointLongitude, worlds
|
provider, source, pointLatitude, pointLongitude, worlds, this.getLogger()
|
||||||
).runTaskTimerAsynchronously(this,
|
).runTaskTimerAsynchronously(this,
|
||||||
settingsSec.getLong("timeBeforeInitialRun"),
|
settingsSec.getLong("timeBeforeInitialRun"),
|
||||||
settingsSec.getLong("timeBetweenRecheck")
|
settingsSec.getLong("timeBetweenRecheck")
|
||||||
);
|
);
|
||||||
|
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
Bukkit.getLogger().info( String.format( this.getName() + " enabled! (%s ms)", Long.toString( end-start ) ) );
|
this.getLogger().info( String.format( this.getName() + " enabled! (%s ms)", Long.toString( end-start ) ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import pl.minecon724.realweather.WeatherState.*;
|
||||||
public class OpenWeatherMapProvider implements Provider {
|
public class OpenWeatherMapProvider implements Provider {
|
||||||
|
|
||||||
URL endpoint;
|
URL endpoint;
|
||||||
|
|
||||||
String apiKey;
|
String apiKey;
|
||||||
|
|
||||||
public OpenWeatherMapProvider(String apiKey) {
|
public OpenWeatherMapProvider(String apiKey) {
|
||||||
|
|
Loading…
Reference in a new issue