diff --git a/pom.xml b/pom.xml
index fbba810..82856b8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
4.0.0
pl.minecon724
realweather
- 0.1.0
+ 0.1.1
17
diff --git a/src/main/java/pl/minecon724/realweather/GetStateTask.java b/src/main/java/pl/minecon724/realweather/GetStateTask.java
index a876275..76f81c2 100644
--- a/src/main/java/pl/minecon724/realweather/GetStateTask.java
+++ b/src/main/java/pl/minecon724/realweather/GetStateTask.java
@@ -6,6 +6,7 @@ import java.util.logging.Logger;
import com.maxmind.geoip2.WebServiceClient;
import com.maxmind.geoip2.exception.AddressNotFoundException;
+import com.maxmind.geoip2.model.CityResponse;
import com.maxmind.geoip2.record.Location;
import org.bukkit.Bukkit;
@@ -26,12 +27,15 @@ public class GetStateTask extends BukkitRunnable {
List worlds;
Logger logger;
WebServiceClient client;
+ boolean broadcast;
+ boolean debug, debugDox;
public GetStateTask(
Provider provider, String source,
double pointLatitude, double pointLongitude,
List worlds, Logger logger,
- WebServiceClient client
+ WebServiceClient client, boolean broadcast,
+ boolean debug, boolean debugDox
) {
this.provider = provider;
this.source = source;
@@ -40,6 +44,9 @@ public class GetStateTask extends BukkitRunnable {
this.worlds = worlds;
this.logger = logger;
this.client = client;
+ this.broadcast = broadcast;
+ this.debug = debug;
+ this.debugDox = debugDox;
}
@Override
@@ -47,7 +54,7 @@ public class GetStateTask extends BukkitRunnable {
logger.info("Refreshing weather by " + source);
if (source.equals("point")) {
State state = provider.request_state(pointLatitude, pointLongitude);
- logger.info(String.format("Provider returned state %s %s (%s)", state.condition.name(), state.level.name(), state.simple.name()));
+ if (debug) logger.info(String.format("Provider returned state %s %s (%s)", state.condition.name(), state.level.name(), state.simple.name()));
for (String w : worlds) {
World world = Bukkit.getWorld(w);
if (world == null) continue;
@@ -61,20 +68,21 @@ public class GetStateTask extends BukkitRunnable {
Location location;
State state;
double lat, lon;
+ CityResponse city;
for (Player p : Bukkit.getOnlinePlayers()) {
curr = p;
playerIp = p.getAddress().getAddress();
- location = client.city(playerIp).getLocation();
+ city = client.city(playerIp);
+ location = city.getLocation();
lat = location.getLatitude();
lon = location.getLongitude();
- logger.info( String.format(
- "%s's location is %f, %f", p.getName(), lat, lon
- ));
+ if (debugDox) logger.info( String.format( "%s's location is %f, %f", p.getName(), lat, lon ));
state = provider.request_state(lat, lon);
- logger.info( String.format(
+ if (debug) logger.info( String.format(
"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);
+ if (broadcast) p.sendMessage( String.format("%s %s in %s", state.level.name(), state.condition.name(), city.getCity().getName()) );
}
} catch (AddressNotFoundException e) {
logger.warning(String.format("%s's IP address (%s) is not a public IP address, therefore we can't retrieve their location.", curr.getName(), playerIp.toString()));
diff --git a/src/main/java/pl/minecon724/realweather/RW.java b/src/main/java/pl/minecon724/realweather/RW.java
index 00af39f..1d170a5 100644
--- a/src/main/java/pl/minecon724/realweather/RW.java
+++ b/src/main/java/pl/minecon724/realweather/RW.java
@@ -1,8 +1,6 @@
package pl.minecon724.realweather;
import java.util.List;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Level;
import com.maxmind.geoip2.WebServiceClient;
@@ -60,15 +58,19 @@ public class RW extends JavaPlugin {
client = new WebServiceClient.Builder(accId, license).host("geolite.info").build();
}
+ boolean broadcast = settingsSec.getBoolean("broadcast");
+ boolean debug = settingsSec.getBoolean("debug");
+ boolean debugDox = settingsSec.getBoolean("debugDox");
+
new GetStateTask(
- provider, source, pointLatitude, pointLongitude, worlds, this.getLogger(), client
+ provider, source, pointLatitude, pointLongitude, worlds, this.getLogger(), client, broadcast, debug, debugDox
).runTaskTimerAsynchronously(this,
settingsSec.getLong("timeBeforeInitialRun"),
settingsSec.getLong("timeBetweenRecheck")
);
// new Metrics(this, 15020);
- // bstat disabled cuz error :(
+ // ^^ https://www.spigotmc.org/threads/554949/
long end = System.currentTimeMillis();
this.getLogger().info( String.format( this.getName() + " enabled! (%s ms)", Long.toString( end-start ) ) );
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 907d007..95ddba5 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -30,6 +30,10 @@ settings:
# 20 is one second
# Shouldn't affect performance
timeBetweenRecheck: 600
+ # Whether to broadcast messages about weather updates
+ broadcast: false
# Advanced options
- timeBeforeInitialRun: 0
\ No newline at end of file
+ timeBeforeInitialRun: 0
+ debug: false
+ debugAllowDox: false
\ No newline at end of file