This commit is contained in:
Minecon724 2022-04-24 16:13:32 +00:00
parent f894706f6c
commit e184902841
5 changed files with 20 additions and 11 deletions

View file

@ -44,10 +44,10 @@ public class GetStateTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
logger.fine("Refreshing weather by " + source); logger.info("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);
logger.fine(String.format("Provider returned state %s %s", state.condition.name(), state.level.name())); logger.info(String.format("Provider returned state %s %s (%s)", state.condition.name(), state.level.name(), state.simple.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;
@ -67,11 +67,11 @@ public class GetStateTask extends BukkitRunnable {
location = client.city(playerIp).getLocation(); location = client.city(playerIp).getLocation();
lat = location.getLatitude(); lat = location.getLatitude();
lon = location.getLongitude(); lon = location.getLongitude();
logger.fine( String.format( logger.info( String.format(
"%s's location is %f, %f", p.getName(), lat, lon "%s's location is %f, %f", p.getName(), lat, lon
)); ));
state = provider.request_state(lat, lon); state = provider.request_state(lat, lon);
logger.fine( String.format( logger.info( String.format(
"Provider returned state %s %s for %s", state.condition.name(), state.level.name(), p.getName() "Provider returned state %s %s for %s", state.condition.name(), state.level.name(), p.getName()
)); ));
p.setPlayerWeather(state.simple == ConditionSimple.CLEAR ? WeatherType.CLEAR : WeatherType.DOWNFALL); p.setPlayerWeather(state.simple == ConditionSimple.CLEAR ? WeatherType.CLEAR : WeatherType.DOWNFALL);

View file

@ -1,6 +1,7 @@
package pl.minecon724.realweather; package pl.minecon724.realweather;
import java.util.List; import java.util.List;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level; import java.util.logging.Level;
import com.maxmind.geoip2.WebServiceClient; import com.maxmind.geoip2.WebServiceClient;
@ -28,11 +29,6 @@ public class RW extends JavaPlugin {
ConfigurationSection providerSec = config.getConfigurationSection("provider"); ConfigurationSection providerSec = config.getConfigurationSection("provider");
ConfigurationSection settingsSec = config.getConfigurationSection("settings"); ConfigurationSection settingsSec = config.getConfigurationSection("settings");
if (settingsSec.getBoolean("debug")) {
this.getLogger().setLevel(Level.ALL);
this.getLogger().fine("Debug info will appear in the console");
}
String source = weatherSec.getString("source"); String source = weatherSec.getString("source");
ConfigurationSection point = weatherSec.getConfigurationSection("point"); ConfigurationSection point = weatherSec.getConfigurationSection("point");
ConfigurationSection player = weatherSec.getConfigurationSection("player"); ConfigurationSection player = weatherSec.getConfigurationSection("player");

View file

@ -36,10 +36,12 @@ public class WeatherState {
switch (condition) { switch (condition) {
case THUNDER: case THUNDER:
this.simple = ConditionSimple.THUNDER; this.simple = ConditionSimple.THUNDER;
break;
case DRIZZLE: case DRIZZLE:
case RAIN: case RAIN:
case SNOW: case SNOW:
this.simple = ConditionSimple.RAIN; this.simple = ConditionSimple.RAIN;
break;
case CLEAR: case CLEAR:
case CLOUDY: case CLOUDY:
this.simple = ConditionSimple.CLEAR; this.simple = ConditionSimple.CLEAR;

View file

@ -63,11 +63,13 @@ public class OpenWeatherMapProvider implements Provider {
case 210: case 210:
case 230: case 230:
level = ConditionLevel.LIGHT; level = ConditionLevel.LIGHT;
break;
case 201: case 201:
case 211: case 211:
case 221: case 221:
case 231: case 231:
level = ConditionLevel.MODERATE; level = ConditionLevel.MODERATE;
break;
case 202: case 202:
case 212: case 212:
case 232: case 232:
@ -79,11 +81,13 @@ public class OpenWeatherMapProvider implements Provider {
case 300: case 300:
case 310: case 310:
level = ConditionLevel.LIGHT; level = ConditionLevel.LIGHT;
break;
case 301: case 301:
case 311: case 311:
case 313: case 313:
case 321: case 321:
level = ConditionLevel.MODERATE; level = ConditionLevel.MODERATE;
break;
case 302: case 302:
case 312: case 312:
case 314: case 314:
@ -95,14 +99,17 @@ public class OpenWeatherMapProvider implements Provider {
case 500: case 500:
case 520: case 520:
level = ConditionLevel.LIGHT; level = ConditionLevel.LIGHT;
break;
case 501: case 501:
case 511: case 511:
case 521: case 521:
case 531: case 531:
level = ConditionLevel.MODERATE; level = ConditionLevel.MODERATE;
break;
case 502: case 502:
case 522: case 522:
level = ConditionLevel.HEAVY; level = ConditionLevel.HEAVY;
break;
case 503: case 503:
case 504: case 504:
level = ConditionLevel.EXTREME; level = ConditionLevel.EXTREME;
@ -115,12 +122,14 @@ public class OpenWeatherMapProvider implements Provider {
case 615: case 615:
case 620: case 620:
level = ConditionLevel.LIGHT; level = ConditionLevel.LIGHT;
break;
case 601: case 601:
case 611: case 611:
case 613: case 613:
case 616: case 616:
case 621: case 621:
level = ConditionLevel.MODERATE; level = ConditionLevel.MODERATE;
break;
case 602: case 602:
case 622: case 622:
level = ConditionLevel.HEAVY; level = ConditionLevel.HEAVY;
@ -130,10 +139,13 @@ public class OpenWeatherMapProvider implements Provider {
switch (stateId) { switch (stateId) {
case 801: case 801:
level = ConditionLevel.LIGHT; level = ConditionLevel.LIGHT;
break;
case 802: case 802:
level = ConditionLevel.MODERATE; level = ConditionLevel.MODERATE;
break;
case 803: case 803:
level = ConditionLevel.HEAVY; level = ConditionLevel.HEAVY;
break;
case 804: case 804:
level = ConditionLevel.EXTREME; level = ConditionLevel.EXTREME;
} }

View file

@ -32,5 +32,4 @@ settings:
timeBetweenRecheck: 600 timeBetweenRecheck: 600
# Advanced options # Advanced options
timeBeforeInitialRun: 0 timeBeforeInitialRun: 0
debug: true