This commit is contained in:
Minecon724 2022-04-23 18:14:22 +00:00
parent 8ef528879e
commit 7d2ef0c492
3 changed files with 13 additions and 10 deletions

View file

@ -1,6 +1,7 @@
package pl.minecon724.realweather;
import java.util.List;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.World;
@ -15,25 +16,27 @@ public class GetStateTask extends BukkitRunnable {
double pointLatitude;
double pointLongitude;
List<String> worlds;
Logger logger;
public GetStateTask(
Provider provider, String source,
double pointLatitude, double pointLongitude,
List<String> worlds
List<String> worlds, Logger logger
) {
this.provider = provider;
this.source = source;
this.pointLatitude = pointLatitude;
this.pointLongitude = pointLongitude;
this.worlds = worlds;
this.logger = logger;
}
@Override
public void run() {
Bukkit.getLogger().fine("Refreshing weather by " + source);
logger.fine("Refreshing weather by " + source);
if (source.equals("point")) {
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) {
World world = Bukkit.getWorld(w);
if (world == null) continue;

View file

@ -25,7 +25,7 @@ public class RW extends JavaPlugin {
ConfigurationSection settingsSec = config.getConfigurationSection("settings");
if (settingsSec.getBoolean("debug")) {
Bukkit.getLogger().setLevel(Level.ALL);
this.getLogger().setLevel(Level.ALL);
}
String source = weatherSec.getString("source");
@ -39,26 +39,26 @@ public class RW extends JavaPlugin {
ConfigurationSection providerCfg = providerSec.getConfigurationSection(choice);
if (providerCfg == null) {
Bukkit.getLogger().severe("Unknown provider: " + choice);
Bukkit.getLogger().info("The plugin will disable now");
this.getLogger().severe("Unknown provider: " + choice);
this.getLogger().info("The plugin will disable now");
Bukkit.getPluginManager().disablePlugin(this);
}
Provider provider = null;
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.init();
new GetStateTask(
provider, source, pointLatitude, pointLongitude, worlds
provider, source, pointLatitude, pointLongitude, worlds, this.getLogger()
).runTaskTimerAsynchronously(this,
settingsSec.getLong("timeBeforeInitialRun"),
settingsSec.getLong("timeBetweenRecheck")
);
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 ) ) );
}
}

View file

@ -15,7 +15,7 @@ import pl.minecon724.realweather.WeatherState.*;
public class OpenWeatherMapProvider implements Provider {
URL endpoint;
String apiKey;
public OpenWeatherMapProvider(String apiKey) {