s
This commit is contained in:
parent
0ab397b8c9
commit
15652828ce
6 changed files with 72 additions and 19 deletions
26
.classpath
26
.classpath
|
@ -1,11 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="optional" value="true"/>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
@ -21,13 +15,6 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="optional" value="true"/>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
<attribute name="test" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="src" path="target/generated-sources/annotations">
|
<classpathentry kind="src" path="target/generated-sources/annotations">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
|
@ -36,6 +23,19 @@
|
||||||
<attribute name="m2e-apt" value="true"/>
|
<attribute name="m2e-apt" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
|
|
7
pom.xml
7
pom.xml
|
@ -2,7 +2,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>pl.minecon724</groupId>
|
<groupId>pl.minecon724</groupId>
|
||||||
<artifactId>realweather</artifactId>
|
<artifactId>realweather</artifactId>
|
||||||
<version>0.0.2</version>
|
<version>0.1.0</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
@ -33,6 +33,11 @@
|
||||||
<artifactId>bstats-bukkit</artifactId>
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
<version>3.0.0</version>
|
<version>3.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.maxmind.geoip2</groupId>
|
||||||
|
<artifactId>geoip2</artifactId>
|
||||||
|
<version>3.0.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
package pl.minecon724.realweather;
|
package pl.minecon724.realweather;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import com.maxmind.geoip2.WebServiceClient;
|
||||||
|
import com.maxmind.geoip2.model.CityResponse;
|
||||||
|
import com.maxmind.geoip2.record.Location;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.WeatherType;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import pl.minecon724.realweather.WeatherState.ConditionSimple;
|
import pl.minecon724.realweather.WeatherState.ConditionSimple;
|
||||||
|
@ -18,11 +25,13 @@ public class GetStateTask extends BukkitRunnable {
|
||||||
double pointLongitude;
|
double pointLongitude;
|
||||||
List<String> worlds;
|
List<String> worlds;
|
||||||
Logger logger;
|
Logger logger;
|
||||||
|
WebServiceClient client;
|
||||||
|
|
||||||
public GetStateTask(
|
public GetStateTask(
|
||||||
Provider provider, String source,
|
Provider provider, String source,
|
||||||
double pointLatitude, double pointLongitude,
|
double pointLatitude, double pointLongitude,
|
||||||
List<String> worlds, Logger logger
|
List<String> worlds, Logger logger,
|
||||||
|
WebServiceClient client
|
||||||
) {
|
) {
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
this.source = source;
|
this.source = source;
|
||||||
|
@ -30,6 +39,7 @@ public class GetStateTask extends BukkitRunnable {
|
||||||
this.pointLongitude = pointLongitude;
|
this.pointLongitude = pointLongitude;
|
||||||
this.worlds = worlds;
|
this.worlds = worlds;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,7 +54,29 @@ public class GetStateTask extends BukkitRunnable {
|
||||||
world.setThundering(state.simple == ConditionSimple.THUNDER ? true : false);
|
world.setThundering(state.simple == ConditionSimple.THUNDER ? true : false);
|
||||||
world.setStorm(state.simple == ConditionSimple.CLEAR ? false : true);
|
world.setStorm(state.simple == ConditionSimple.CLEAR ? false : true);
|
||||||
}
|
}
|
||||||
|
} else if (source.equals("player")) {
|
||||||
|
try {
|
||||||
|
InetAddress playerIp;
|
||||||
|
Location location;
|
||||||
|
State state;
|
||||||
|
double lat, lon;
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
playerIp = p.getAddress().getAddress();
|
||||||
|
location = client.city(playerIp).getLocation();
|
||||||
|
lat = location.getLatitude();
|
||||||
|
lon = location.getLongitude();
|
||||||
|
logger.fine( String.format(
|
||||||
|
"%s's location is %f, %f", p.getName(), lat, lon
|
||||||
|
));
|
||||||
|
state = provider.request_state(lat, lon);
|
||||||
|
logger.fine( 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);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package pl.minecon724.realweather;
|
package pl.minecon724.realweather;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import com.maxmind.geoip2.WebServiceClient;
|
||||||
|
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
@ -13,6 +16,7 @@ import pl.minecon724.realweather.provider.OpenWeatherMapProvider;
|
||||||
|
|
||||||
public class RW extends JavaPlugin {
|
public class RW extends JavaPlugin {
|
||||||
FileConfiguration config;
|
FileConfiguration config;
|
||||||
|
WebServiceClient client = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
@ -31,6 +35,7 @@ public class RW extends JavaPlugin {
|
||||||
|
|
||||||
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");
|
||||||
|
|
||||||
double pointLatitude = point.getDouble("latitude");
|
double pointLatitude = point.getDouble("latitude");
|
||||||
double pointLongitude = point.getDouble("longitude");
|
double pointLongitude = point.getDouble("longitude");
|
||||||
|
@ -52,8 +57,15 @@ public class RW extends JavaPlugin {
|
||||||
}
|
}
|
||||||
provider.init();
|
provider.init();
|
||||||
|
|
||||||
|
if (source.equals("player")) {
|
||||||
|
this.getLogger().info("This product includes GeoLite2 data created by MaxMind, available from https://maxmind.com");
|
||||||
|
int accId = player.getInt("geolite2_accountId");
|
||||||
|
String license = player.getString("geolite2_apiKey");
|
||||||
|
client = new WebServiceClient.Builder(accId, license).build();
|
||||||
|
}
|
||||||
|
|
||||||
new GetStateTask(
|
new GetStateTask(
|
||||||
provider, source, pointLatitude, pointLongitude, worlds, this.getLogger()
|
provider, source, pointLatitude, pointLongitude, worlds, this.getLogger(), client
|
||||||
).runTaskTimerAsynchronously(this,
|
).runTaskTimerAsynchronously(this,
|
||||||
settingsSec.getLong("timeBeforeInitialRun"),
|
settingsSec.getLong("timeBeforeInitialRun"),
|
||||||
settingsSec.getLong("timeBetweenRecheck")
|
settingsSec.getLong("timeBetweenRecheck")
|
||||||
|
|
|
@ -11,6 +11,9 @@ weather:
|
||||||
point:
|
point:
|
||||||
latitude: 41.84201
|
latitude: 41.84201
|
||||||
longitude: -89.485937
|
longitude: -89.485937
|
||||||
|
player:
|
||||||
|
geolite2_accountId: 710438
|
||||||
|
geolite2_apiKey: 'qLeseHp4QNQcqRGn'
|
||||||
|
|
||||||
provider:
|
provider:
|
||||||
# Your provider choice
|
# Your provider choice
|
||||||
|
@ -19,7 +22,7 @@ provider:
|
||||||
# Provider settings here
|
# Provider settings here
|
||||||
# Unlike the previous option, these are case sensitive
|
# Unlike the previous option, these are case sensitive
|
||||||
openweathermap:
|
openweathermap:
|
||||||
apiKey: ''
|
apiKey: 'd3d37fd3511ef1d4b44c7d574e9b56b8'
|
||||||
# More providers soon!
|
# More providers soon!
|
||||||
|
|
||||||
settings:
|
settings:
|
||||||
|
|
|
@ -5,4 +5,5 @@ author: Minecon724
|
||||||
main: pl.minecon724.realweather.RW
|
main: pl.minecon724.realweather.RW
|
||||||
libraries:
|
libraries:
|
||||||
- org.json:json:20220320
|
- org.json:json:20220320
|
||||||
- org.bstats:bstats-bukkit:3.0.0
|
- org.bstats:bstats-bukkit:3.0.0
|
||||||
|
- com.maxmind.geoip2:geoip2:3.0.1
|
Loading…
Reference in a new issue