preparing for 0.4

This commit is contained in:
Minecon724 2022-06-11 14:49:25 +00:00
parent be2b69e30c
commit 4e3f04ee79
7 changed files with 91 additions and 3 deletions

View file

@ -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.3.0</version> <version>0.4.0</version>
<properties> <properties>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>

View file

@ -126,7 +126,7 @@ public class GetStateTask extends BukkitRunnable {
coords = mapUtils.playerPosAsCoords(p.getLocation(), scaleLat, scaleLon, onExceed); coords = mapUtils.playerPosAsCoords(p.getLocation(), scaleLat, scaleLon, onExceed);
lon = coords[0]; lon = coords[0];
lat = coords[1]; lat = coords[1];
logger.info( String.format( "%s's location is %f, %f", p.getName(), lat, lon )); if (debug) logger.info( String.format( "%s's location is %f, %f", p.getName(), lat, lon ));
state = provider.request_state(lat, lon); state = provider.request_state(lat, lon);
if (debug) logger.info( String.format( if (debug) logger.info( String.format(
"Provider returned state %s %s for %f, %f", state.condition.name(), state.level.name(), lat, lon "Provider returned state %s %s for %f, %f", state.condition.name(), state.level.name(), lat, lon

View file

@ -1,5 +1,6 @@
package pl.minecon724.realweather; package pl.minecon724.realweather;
import java.time.ZoneId;
import java.util.List; import java.util.List;
import com.maxmind.geoip2.WebServiceClient; import com.maxmind.geoip2.WebServiceClient;
@ -9,7 +10,9 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import pl.minecon724.realweather.commands.RealWeatherCommand;
import pl.minecon724.realweather.provider.OpenWeatherMapProvider; import pl.minecon724.realweather.provider.OpenWeatherMapProvider;
import pl.minecon724.realweather.realtime.RTTask;
import pl.minecon724.realweather.thirdparty.Metrics; import pl.minecon724.realweather.thirdparty.Metrics;
public class RW extends JavaPlugin { public class RW extends JavaPlugin {
@ -28,6 +31,7 @@ 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");
ConfigurationSection messagesSec = config.getConfigurationSection("messages"); ConfigurationSection messagesSec = config.getConfigurationSection("messages");
ConfigurationSection realtimeSec = config.getConfigurationSection("realtime");
String source = weatherSec.getString("source"); String source = weatherSec.getString("source");
ConfigurationSection point = weatherSec.getConfigurationSection("point"); ConfigurationSection point = weatherSec.getConfigurationSection("point");
@ -61,6 +65,8 @@ public class RW extends JavaPlugin {
client = new WebServiceClient.Builder(accId, license).host("geolite.info").build(); client = new WebServiceClient.Builder(accId, license).host("geolite.info").build();
} }
getCommand("realweather").setExecutor(new RealWeatherCommand());
double scale_lat = map.getDouble("scale_lat"); double scale_lat = map.getDouble("scale_lat");
double scale_lon = map.getDouble("scale_lon"); double scale_lon = map.getDouble("scale_lon");
int on_exceed = map.getInt("on_exceed"); int on_exceed = map.getInt("on_exceed");
@ -77,6 +83,20 @@ public class RW extends JavaPlugin {
settingsSec.getLong("timeBetweenRecheck") settingsSec.getLong("timeBetweenRecheck")
); );
if (realtimeSec.getBoolean("enabled")) {
ZoneId zone;
try {
zone = ZoneId.of(realtimeSec.getString("timezone"));
} catch (Exception e) {
zone = ZoneId.systemDefault();
}
new RTTask(
realtimeSec.getDouble("timeScale"),
zone,
realtimeSec.getStringList("worlds")
).runTaskTimerAsynchronously(this, 0, realtimeSec.getLong("interval"));
}
Metrics metrics = new Metrics(this, 15020); Metrics metrics = new Metrics(this, 15020);
metrics.addCustomChart(new Metrics.SimplePie("source_type", () -> { metrics.addCustomChart(new Metrics.SimplePie("source_type", () -> {
return source; return source;

View file

@ -0,0 +1,15 @@
package pl.minecon724.realweather.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class RealWeatherCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
sender.sendMessage("TODO");
return true;
}
}

View file

@ -0,0 +1,36 @@
package pl.minecon724.realweather.realtime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.scheduler.BukkitRunnable;
public class RTTask extends BukkitRunnable {
double timeScale;
ZoneId timezone;
List<World> worlds;
public RTTask(double timeScale, ZoneId timezone, List<String> worlds) {
this.timeScale = timeScale;
this.timezone = timezone;
this.worlds = new ArrayList<World>();
for (String s : worlds) {
World world = Bukkit.getWorld(s);
if (world == null) continue;
this.worlds.add(world);
}
}
@Override
public void run() {
double time = OffsetDateTime.now(timezone).toEpochSecond() / (72 * timeScale) - 18000;
Bukkit.getLogger().info(Double.toString(time));
for (World w : worlds) {
w.setTime((long)time);
}
}
}

View file

@ -42,6 +42,19 @@ provider:
apiKey: 'd3d37fd3511ef1d4b44c7d574e9b56b8' apiKey: 'd3d37fd3511ef1d4b44c7d574e9b56b8'
# More providers soon! # More providers soon!
realtime:
enabled: true
worlds:
- world
# "auto" to use server's timezone
# Alternatively choose one of these: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
timezone: 'auto'
# x day cycles / 24 hrs
timeScale: 1.0
# How often should we recalculate the time (in ticks)
# Very minimal, if any, impact on performance
interval: 1
settings: settings:
# Delay between rechecking weather # Delay between rechecking weather
# 20 is one second # 20 is one second

View file

@ -5,4 +5,8 @@ author: Minecon724
main: pl.minecon724.realweather.RW main: pl.minecon724.realweather.RW
libraries: libraries:
- org.json:json:20220320 - org.json:json:20220320
- com.maxmind.geoip2:geoip2:3.0.1 - com.maxmind.geoip2:geoip2:3.0.1
commands:
realweather:
alias: rw
description: RealWeather main command