parent
3f11d235b1
commit
ab70e0d3c1
20 changed files with 144 additions and 131 deletions
|
@ -1,5 +1,22 @@
|
||||||
package eu.m724.realweather;
|
package eu.m724.realweather;
|
||||||
|
|
||||||
|
import eu.m724.realweather.mapper.MapperConfig;
|
||||||
|
import eu.m724.realweather.thunder.ThunderConfig;
|
||||||
|
import eu.m724.realweather.time.TimeConfig;
|
||||||
|
import eu.m724.realweather.updater.UpdaterConfig;
|
||||||
|
import eu.m724.realweather.weather.WeatherConfig;
|
||||||
|
|
||||||
// TODO replaces GlobalConstants for configs
|
// TODO replaces GlobalConstants for configs
|
||||||
public class Configs {
|
public class Configs {
|
||||||
|
static WeatherConfig weatherConfig;
|
||||||
|
static TimeConfig timeConfig;
|
||||||
|
static ThunderConfig thunderConfig;
|
||||||
|
static MapperConfig mapperConfig;
|
||||||
|
static UpdaterConfig updaterConfig;
|
||||||
|
|
||||||
|
public static WeatherConfig weatherConfig() { return weatherConfig; }
|
||||||
|
public static TimeConfig timeConfig() { return timeConfig; }
|
||||||
|
public static ThunderConfig thunderConfig() { return thunderConfig; }
|
||||||
|
public static MapperConfig mapperConfig() { return mapperConfig; }
|
||||||
|
public static UpdaterConfig updaterConfig() { return updaterConfig; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,36 +3,15 @@ package eu.m724.realweather;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import eu.m724.realweather.mapper.Mapper;
|
import eu.m724.realweather.mapper.Mapper;
|
||||||
import eu.m724.realweather.mapper.MapperConfig;
|
|
||||||
import eu.m724.realweather.thunder.ThunderConfig;
|
|
||||||
import eu.m724.realweather.time.TimeConfig;
|
|
||||||
import eu.m724.realweather.updater.UpdaterConfig;
|
|
||||||
import eu.m724.realweather.weather.PlayerWeatherCache;
|
import eu.m724.realweather.weather.PlayerWeatherCache;
|
||||||
|
|
||||||
// perhaps replace with a singleton
|
// perhaps replace with a singleton
|
||||||
// TODO actually, remove it altogether
|
// TODO actually, remove it altogether
|
||||||
public class GlobalConstants {
|
public class GlobalConstants {
|
||||||
static TimeConfig timeConfig;
|
|
||||||
static ThunderConfig thunderConfig;
|
|
||||||
static MapperConfig mapperConfig;
|
|
||||||
static UpdaterConfig updaterConfig;
|
|
||||||
|
|
||||||
static Mapper mapper;
|
static Mapper mapper;
|
||||||
static Plugin plugin;
|
static Plugin plugin;
|
||||||
static PlayerWeatherCache playerWeatherCache;
|
static PlayerWeatherCache playerWeatherCache;
|
||||||
|
|
||||||
public static TimeConfig getTimeConfig() {
|
|
||||||
return timeConfig;
|
|
||||||
}
|
|
||||||
public static ThunderConfig getThunderConfig() {
|
|
||||||
return thunderConfig;
|
|
||||||
}
|
|
||||||
public static MapperConfig getMapperConfig() {
|
|
||||||
return mapperConfig;
|
|
||||||
}
|
|
||||||
public static UpdaterConfig getUpdaterConfig() {
|
|
||||||
return updaterConfig;
|
|
||||||
}
|
|
||||||
public static Mapper getMapper() {
|
public static Mapper getMapper() {
|
||||||
return mapper;
|
return mapper;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,6 @@ public class RealWeatherPlugin extends JavaPlugin {
|
||||||
private TimeMaster timeMaster;
|
private TimeMaster timeMaster;
|
||||||
private PluginUpdater updater;
|
private PluginUpdater updater;
|
||||||
|
|
||||||
private WeatherConfig weatherConfig;
|
|
||||||
|
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -88,29 +86,29 @@ public class RealWeatherPlugin extends JavaPlugin {
|
||||||
GlobalConstants.playerWeatherCache = new PlayerWeatherCache();
|
GlobalConstants.playerWeatherCache = new PlayerWeatherCache();
|
||||||
|
|
||||||
DebugLogger.info("loading mapper", 1);
|
DebugLogger.info("loading mapper", 1);
|
||||||
GlobalConstants.mapperConfig = MapperConfig.fromConfiguration(mapConfiguration);
|
Configs.mapperConfig = MapperConfig.fromConfiguration(mapConfiguration);
|
||||||
GlobalConstants.mapper = new Mapper();
|
GlobalConstants.mapper = new Mapper();
|
||||||
GlobalConstants.mapper.registerEvents(this);
|
GlobalConstants.mapper.registerEvents(this);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DebugLogger.info("loading weather", 1);
|
DebugLogger.info("loading weather", 1);
|
||||||
weatherConfig = WeatherConfig.fromConfiguration(weatherConfiguration);
|
Configs.weatherConfig = WeatherConfig.fromConfiguration(weatherConfiguration);
|
||||||
weatherMaster = new WeatherMaster(weatherConfig);
|
weatherMaster = new WeatherMaster();
|
||||||
weatherMaster.init(this);
|
weatherMaster.init(this);
|
||||||
|
|
||||||
DebugLogger.info("loading thunder", 1);
|
DebugLogger.info("loading thunder", 1);
|
||||||
GlobalConstants.thunderConfig = ThunderConfig.fromConfiguration(thunderConfiguration);
|
Configs.thunderConfig = ThunderConfig.fromConfiguration(thunderConfiguration);
|
||||||
thunderMaster = new ThunderMaster(GlobalConstants.thunderConfig);
|
thunderMaster = new ThunderMaster();
|
||||||
thunderMaster.init(this);
|
thunderMaster.init(this);
|
||||||
|
|
||||||
DebugLogger.info("loading time", 1);
|
DebugLogger.info("loading time", 1);
|
||||||
GlobalConstants.timeConfig = TimeConfig.fromConfiguration(timeConfiguration);
|
Configs.timeConfig = TimeConfig.fromConfiguration(timeConfiguration);
|
||||||
timeMaster = new TimeMaster(GlobalConstants.timeConfig);
|
timeMaster = new TimeMaster();
|
||||||
timeMaster.init();
|
timeMaster.init();
|
||||||
|
|
||||||
GlobalConstants.updaterConfig = UpdaterConfig.fromConfiguration(configuration.getConfigurationSection("updater"));
|
Configs.updaterConfig = UpdaterConfig.fromConfiguration(configuration.getConfigurationSection("updater"));
|
||||||
updater = PluginUpdater.build(this, this.getFile(), GlobalConstants.updaterConfig);
|
updater = PluginUpdater.build(this, this.getFile());
|
||||||
updater.init();
|
//updater.init();
|
||||||
} catch (UserError | NoSuchProviderException e) {
|
} catch (UserError | NoSuchProviderException e) {
|
||||||
logger.severe("There are errors in your config:");
|
logger.severe("There are errors in your config:");
|
||||||
logger.severe(e.getMessage());
|
logger.severe(e.getMessage());
|
||||||
|
@ -128,13 +126,13 @@ public class RealWeatherPlugin extends JavaPlugin {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getCommand("rwadmin").setExecutor(new AdminCommand(updater, weatherConfig, thunderMaster, timeMaster.getTimeConverter()));
|
getCommand("rwadmin").setExecutor(new AdminCommand(updater, thunderMaster, timeMaster.getTimeConverter()));
|
||||||
getCommand("geo").setExecutor(new GeoCommand());
|
getCommand("geo").setExecutor(new GeoCommand());
|
||||||
|
|
||||||
if (GlobalConstants.timeConfig.enabled())
|
if (Configs.timeConfig.enabled())
|
||||||
getCommand("localtime").setExecutor(new LocalTimeCommand(timeMaster.getTimeConverter()));
|
getCommand("localtime").setExecutor(new LocalTimeCommand(timeMaster.getTimeConverter()));
|
||||||
|
|
||||||
if (weatherConfig.enabled()) {
|
if (Configs.weatherConfig.enabled()) {
|
||||||
getCommand("localweather").setExecutor(new LocalWeatherCommand());
|
getCommand("localweather").setExecutor(new LocalWeatherCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.m724.realweather.api.weather;
|
package eu.m724.realweather.api.weather;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
@ -8,14 +9,16 @@ import eu.m724.wtapi.object.Weather;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired when a weather state is retrieved<br>
|
* Fired when a weather state is retrieved<br>
|
||||||
* Not necessarily a change
|
* It doesn't mean the weather has changed, just that we retrieved the state<br>
|
||||||
*/
|
*/
|
||||||
public class AsyncWeatherUpdateEvent extends Event {
|
public class AsyncWeatherUpdateEvent extends Event implements Cancellable {
|
||||||
private static final HandlerList HANDLERS = new HandlerList();
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final Weather weather;
|
private final Weather weather;
|
||||||
|
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
public AsyncWeatherUpdateEvent(Player player, Weather weather) {
|
public AsyncWeatherUpdateEvent(Player player, Weather weather) {
|
||||||
super(true);
|
super(true);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
@ -23,13 +26,15 @@ public class AsyncWeatherUpdateEvent extends Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return a player that the weather is for, null if worldwide (static mode)
|
||||||
* @return a player that the weather is for, null if not dynamic
|
|
||||||
*/
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the weather state that was just changed
|
||||||
|
*/
|
||||||
public Weather getWeather() {
|
public Weather getWeather() {
|
||||||
return weather;
|
return weather;
|
||||||
}
|
}
|
||||||
|
@ -42,4 +47,19 @@ public class AsyncWeatherUpdateEvent extends Event {
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return HANDLERS;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel weather change<br>
|
||||||
|
* It will only cancel changing the actual weather by the plugin, not retrieving and caching it
|
||||||
|
* @param cancelled to cancel or not
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancelled) {
|
||||||
|
this.cancelled = cancelled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package eu.m724.realweather.commands;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
||||||
|
import eu.m724.realweather.Configs;
|
||||||
import eu.m724.realweather.time.TimeConverter;
|
import eu.m724.realweather.time.TimeConverter;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
@ -25,17 +26,16 @@ public class AdminCommand implements CommandExecutor {
|
||||||
private final UpdateCommand updateCommand;
|
private final UpdateCommand updateCommand;
|
||||||
private final Plugin plugin = GlobalConstants.getPlugin();
|
private final Plugin plugin = GlobalConstants.getPlugin();
|
||||||
|
|
||||||
private final WeatherConfig weatherConfig;
|
private final WeatherConfig weatherConfig = Configs.weatherConfig();
|
||||||
private final TimeConfig timeConfig = GlobalConstants.getTimeConfig();
|
private final TimeConfig timeConfig = Configs.timeConfig();
|
||||||
private final ThunderConfig thunderConfig = GlobalConstants.getThunderConfig();
|
private final ThunderConfig thunderConfig = Configs.thunderConfig();
|
||||||
private final MapperConfig mapperConfig = GlobalConstants.getMapperConfig();
|
private final MapperConfig mapperConfig = Configs.mapperConfig();
|
||||||
|
|
||||||
private final ThunderMaster thunderMaster;
|
private final ThunderMaster thunderMaster;
|
||||||
private final TimeConverter timeConverter;
|
private final TimeConverter timeConverter;
|
||||||
|
|
||||||
public AdminCommand(PluginUpdater updater, WeatherConfig weatherConfig, ThunderMaster thunderMaster, TimeConverter timeConverter) {
|
public AdminCommand(PluginUpdater updater, ThunderMaster thunderMaster, TimeConverter timeConverter) {
|
||||||
this.updateCommand = new UpdateCommand(updater);
|
this.updateCommand = new UpdateCommand(updater);
|
||||||
this.weatherConfig = weatherConfig;
|
|
||||||
this.thunderMaster = thunderMaster;
|
this.thunderMaster = thunderMaster;
|
||||||
this.timeConverter = timeConverter;
|
this.timeConverter = timeConverter;
|
||||||
}
|
}
|
||||||
|
@ -78,31 +78,31 @@ public class AdminCommand implements CommandExecutor {
|
||||||
|
|
||||||
Duration worldTimeDuration = Duration.ofMillis(worldTime);
|
Duration worldTimeDuration = Duration.ofMillis(worldTime);
|
||||||
|
|
||||||
String worldTimeFormatted = String.format("%d:%02d:%02d\n",
|
String worldTimeFormatted = String.format("%d:%02d:%02d",
|
||||||
worldTimeDuration.toHours(),
|
worldTimeDuration.toHours(),
|
||||||
worldTimeDuration.toMinutesPart(),
|
worldTimeDuration.toMinutesPart(),
|
||||||
worldTimeDuration.toSecondsPart());
|
worldTimeDuration.toSecondsPart());
|
||||||
|
|
||||||
componentBuilder.append(" World time: ").color(ChatColor.GOLD);
|
componentBuilder.append(" World time: ").color(ChatColor.GOLD);
|
||||||
componentBuilder.append(worldTimeFormatted).color(ChatColor.AQUA);
|
componentBuilder.append(worldTimeFormatted).color(ChatColor.AQUA);
|
||||||
componentBuilder.append(" %d ticks".formatted(worldTimeTicks)).color(ChatColor.GRAY);
|
componentBuilder.append(" %d ticks\n".formatted(worldTimeTicks)).color(ChatColor.GRAY);
|
||||||
|
|
||||||
componentBuilder.append(" Dynamic: ").color(ChatColor.GOLD);
|
componentBuilder.append(" Dynamic: ").color(ChatColor.GOLD);
|
||||||
componentBuilder.append(truthComponent(timeConfig.dynamic()));
|
componentBuilder.append(truthComponent(timeConfig.dynamic()));
|
||||||
}
|
}
|
||||||
|
|
||||||
componentBuilder.append("\nThunder: ").color(ChatColor.GOLD);
|
componentBuilder.append("\nThunder: ").color(ChatColor.GOLD);
|
||||||
componentBuilder.append(truthComponent(thunderConfig.enabled));
|
componentBuilder.append(truthComponent(thunderConfig.enabled()));
|
||||||
|
|
||||||
if (thunderConfig.enabled) {
|
if (thunderConfig.enabled()) {
|
||||||
componentBuilder.append(" Provider: ").color(ChatColor.GOLD);
|
componentBuilder.append(" Provider: ").color(ChatColor.GOLD);
|
||||||
componentBuilder.append(thunderConfig.provider + "\n").color(ChatColor.AQUA);
|
componentBuilder.append(thunderConfig.provider() + "\n").color(ChatColor.AQUA);
|
||||||
|
|
||||||
componentBuilder.append(" Refresh: ").color(ChatColor.GOLD);
|
componentBuilder.append(" Refreshed every ").color(ChatColor.GOLD);
|
||||||
componentBuilder.append(String.format("%d ticks\n", thunderConfig.refresh)).color(ChatColor.AQUA);
|
componentBuilder.append(String.format("%d ticks\n", thunderConfig.refreshPeriod())).color(ChatColor.AQUA);
|
||||||
|
|
||||||
componentBuilder.append(" Latency: ").color(ChatColor.GOLD);
|
componentBuilder.append(" API latency: ").color(ChatColor.GOLD);
|
||||||
componentBuilder.append(String.format("avg %dms\n", thunderMaster.getLatency())).color(ChatColor.AQUA);
|
componentBuilder.append(String.format("%dms\n", thunderMaster.getLatency())).color(ChatColor.AQUA);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package eu.m724.realweather.commands;
|
package eu.m724.realweather.commands;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
|
|
||||||
|
import eu.m724.realweather.Configs;
|
||||||
import eu.m724.realweather.time.TimeConverter;
|
import eu.m724.realweather.time.TimeConverter;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
@ -19,7 +19,7 @@ import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
|
||||||
public class LocalTimeCommand implements CommandExecutor {
|
public class LocalTimeCommand implements CommandExecutor {
|
||||||
private final Mapper mapper = GlobalConstants.getMapper();
|
private final Mapper mapper = GlobalConstants.getMapper();
|
||||||
private final TimeConfig timeConfig = GlobalConstants.getTimeConfig();
|
private final TimeConfig timeConfig = Configs.timeConfig();
|
||||||
private final TimeConverter timeConverter;
|
private final TimeConverter timeConverter;
|
||||||
|
|
||||||
public LocalTimeCommand(TimeConverter timeConverter) {
|
public LocalTimeCommand(TimeConverter timeConverter) {
|
||||||
|
|
|
@ -4,15 +4,15 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import eu.m724.realweather.Configs;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import eu.m724.realweather.GlobalConstants;
|
|
||||||
import eu.m724.wtapi.object.Coordinates;
|
import eu.m724.wtapi.object.Coordinates;
|
||||||
|
|
||||||
public class Mapper {
|
public class Mapper {
|
||||||
private final MapperConfig config = GlobalConstants.getMapperConfig();
|
private final MapperConfig config = Configs.mapperConfig();
|
||||||
private final List<World> worlds = new ArrayList<>();
|
private final List<World> worlds = new ArrayList<>();
|
||||||
|
|
||||||
private final List<Consumer<World>> worldLoadConsumers = new ArrayList<>();
|
private final List<Consumer<World>> worldLoadConsumers = new ArrayList<>();
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.bukkit.event.world.WorldLoadEvent;
|
||||||
import org.bukkit.event.world.WorldUnloadEvent;
|
import org.bukkit.event.world.WorldUnloadEvent;
|
||||||
|
|
||||||
public class MapperEventHandler implements Listener {
|
public class MapperEventHandler implements Listener {
|
||||||
private Mapper mapper;
|
private final Mapper mapper;
|
||||||
|
|
||||||
public MapperEventHandler(Mapper mapper) {
|
public MapperEventHandler(Mapper mapper) {
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
|
|
|
@ -2,22 +2,22 @@ package eu.m724.realweather.thunder;
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
public class ThunderConfig {
|
/**
|
||||||
public boolean enabled;
|
*
|
||||||
|
* @param enabled is thunder module enabled
|
||||||
public String provider;
|
* @param provider The provider name, may or may not exist, if it doesn't, an error is thrown later
|
||||||
|
* @param refreshPeriod how often probe for strikes, in ticks
|
||||||
// how often refresh in ms
|
*/
|
||||||
public int refresh;
|
public record ThunderConfig(
|
||||||
|
boolean enabled,
|
||||||
|
String provider,
|
||||||
|
int refreshPeriod
|
||||||
|
) {
|
||||||
public static ThunderConfig fromConfiguration(ConfigurationSection configuration) {
|
public static ThunderConfig fromConfiguration(ConfigurationSection configuration) {
|
||||||
ThunderConfig thunderConfig = new ThunderConfig();
|
return new ThunderConfig(
|
||||||
|
configuration.getBoolean("enabled"),
|
||||||
thunderConfig.enabled = configuration.getBoolean("enabled");
|
configuration.getString("provider"),
|
||||||
thunderConfig.provider = configuration.getString("provider");
|
configuration.getInt("refreshPeriod")
|
||||||
|
);
|
||||||
thunderConfig.refresh = configuration.getInt("refresh");
|
|
||||||
|
|
||||||
return thunderConfig;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.m724.realweather.thunder;
|
package eu.m724.realweather.thunder;
|
||||||
|
|
||||||
|
import eu.m724.realweather.Configs;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import eu.m724.realweather.DebugLogger;
|
import eu.m724.realweather.DebugLogger;
|
||||||
|
@ -9,28 +10,24 @@ import eu.m724.wtapi.provider.exception.ProviderException;
|
||||||
import eu.m724.wtapi.provider.thunder.ThunderProvider;
|
import eu.m724.wtapi.provider.thunder.ThunderProvider;
|
||||||
|
|
||||||
public class ThunderMaster {
|
public class ThunderMaster {
|
||||||
private final ThunderConfig config;
|
private final ThunderConfig config = Configs.thunderConfig();
|
||||||
private ThunderProvider provider;
|
private ThunderProvider provider;
|
||||||
|
|
||||||
public ThunderMaster(ThunderConfig config) {
|
|
||||||
this.config = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initializes, tests and starts
|
* initializes, tests and starts
|
||||||
* @throws ProviderException if provider initialization failed
|
* @throws ProviderException if provider initialization failed
|
||||||
* @throws NoSuchProviderException config issue
|
* @throws NoSuchProviderException config issue
|
||||||
*/
|
*/
|
||||||
public void init(Plugin plugin) throws ProviderException, NoSuchProviderException {
|
public void init(Plugin plugin) throws ProviderException, NoSuchProviderException {
|
||||||
if (!config.enabled)
|
if (!config.enabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
provider = Providers.getThunderProvider(config.provider, null);
|
provider = Providers.getThunderProvider(config.provider(), null);
|
||||||
provider.init();
|
provider.init();
|
||||||
|
|
||||||
ThunderTask thunderTask = new ThunderTask(provider);
|
ThunderTask thunderTask = new ThunderTask(provider);
|
||||||
thunderTask.init();
|
thunderTask.init();
|
||||||
thunderTask.runTaskTimer(plugin, 0, config.refresh);
|
thunderTask.runTaskTimer(plugin, 0, config.refreshPeriod());
|
||||||
|
|
||||||
DebugLogger.info("thunder loaded", 1);
|
DebugLogger.info("thunder loaded", 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,19 +2,22 @@ package eu.m724.realweather.time;
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param enabled is time module enabled
|
||||||
|
* @param dynamic is time dynamic, that is per player
|
||||||
|
* @param scale timescale, time goes Nx slower (0.5 - 2x faster)
|
||||||
|
*/
|
||||||
public record TimeConfig(
|
public record TimeConfig(
|
||||||
boolean enabled,
|
boolean enabled,
|
||||||
|
|
||||||
boolean dynamic,
|
boolean dynamic,
|
||||||
|
|
||||||
double scale
|
double scale
|
||||||
) {
|
) {
|
||||||
public static TimeConfig fromConfiguration(ConfigurationSection configuration) {
|
public static TimeConfig fromConfiguration(ConfigurationSection configuration) {
|
||||||
boolean enabled = configuration.getBoolean("enabled");
|
return new TimeConfig(
|
||||||
|
configuration.getBoolean("enabled"),
|
||||||
boolean dynamic = configuration.getBoolean("dynamic");
|
configuration.getBoolean("dynamic"),
|
||||||
double scale = configuration.getDouble("scale");
|
configuration.getDouble("scale")
|
||||||
|
);
|
||||||
return new TimeConfig(enabled, dynamic, scale);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.m724.realweather.time;
|
package eu.m724.realweather.time;
|
||||||
|
|
||||||
|
import eu.m724.realweather.Configs;
|
||||||
import org.bukkit.GameRule;
|
import org.bukkit.GameRule;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
@ -10,14 +11,10 @@ import eu.m724.realweather.mapper.Mapper;
|
||||||
public class TimeMaster {
|
public class TimeMaster {
|
||||||
private final Mapper mapper = GlobalConstants.getMapper();
|
private final Mapper mapper = GlobalConstants.getMapper();
|
||||||
private final Plugin plugin = GlobalConstants.getPlugin();
|
private final Plugin plugin = GlobalConstants.getPlugin();
|
||||||
|
private final TimeConfig timeConfig = Configs.timeConfig();
|
||||||
|
|
||||||
private final TimeConfig timeConfig;
|
// TODO I don't want to initialize this here
|
||||||
private final TimeConverter timeConverter;
|
private final TimeConverter timeConverter = new TimeConverter(timeConfig.scale());
|
||||||
|
|
||||||
public TimeMaster(TimeConfig timeConfig) {
|
|
||||||
this.timeConfig = timeConfig;
|
|
||||||
this.timeConverter = new TimeConverter(timeConfig.scale());
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO this is only used once
|
// TODO this is only used once
|
||||||
public TimeConverter getTimeConverter() {
|
public TimeConverter getTimeConverter() {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import eu.m724.jarupdater.environment.ConstantEnvironment;
|
||||||
import eu.m724.jarupdater.updater.Updater;
|
import eu.m724.jarupdater.updater.Updater;
|
||||||
import eu.m724.jarupdater.verify.SignatureVerifier;
|
import eu.m724.jarupdater.verify.SignatureVerifier;
|
||||||
import eu.m724.jarupdater.verify.Verifier;
|
import eu.m724.jarupdater.verify.Verifier;
|
||||||
import eu.m724.realweather.GlobalConstants;
|
import eu.m724.realweather.Configs;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import eu.m724.jarupdater.download.Downloader;
|
import eu.m724.jarupdater.download.Downloader;
|
||||||
|
@ -19,20 +19,19 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class PluginUpdater extends Updater {
|
public class PluginUpdater extends Updater {
|
||||||
private final UpdaterConfig updaterConfig;
|
private final UpdaterConfig updaterConfig = Configs.updaterConfig();
|
||||||
|
|
||||||
final Plugin plugin;
|
final Plugin plugin;
|
||||||
|
|
||||||
PluginUpdater(Plugin plugin, Environment environment, MetadataFacade metadataProvider, Downloader downloader, Verifier verifier, UpdaterConfig updaterConfig) {
|
PluginUpdater(Plugin plugin, Environment environment, MetadataFacade metadataProvider, Downloader downloader, Verifier verifier) {
|
||||||
super(environment, metadataProvider, downloader, verifier);
|
super(environment, metadataProvider, downloader, verifier);
|
||||||
this.updaterConfig = updaterConfig;
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PluginUpdater build(Plugin plugin, File file, UpdaterConfig updaterConfig) {
|
public static PluginUpdater build(Plugin plugin, File file) {
|
||||||
Environment environment = new ConstantEnvironment(
|
Environment environment = new ConstantEnvironment(
|
||||||
plugin.getDescription().getVersion(),
|
plugin.getDescription().getVersion(),
|
||||||
GlobalConstants.getUpdaterConfig().channel,
|
Configs.updaterConfig().channel(),
|
||||||
file.toPath()
|
file.toPath()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -47,11 +46,11 @@ public class PluginUpdater extends Updater {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PluginUpdater(plugin, environment, metadataFacade, downloader, verifier, updaterConfig);
|
return new PluginUpdater(plugin, environment, metadataFacade, downloader, verifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
if (!updaterConfig.notify) return;
|
if (!updaterConfig.alert()) return;
|
||||||
|
|
||||||
UpdateNotifier updateNotifier = new UpdateNotifier(this, (version) -> {});
|
UpdateNotifier updateNotifier = new UpdateNotifier(this, (version) -> {});
|
||||||
updateNotifier.register();
|
updateNotifier.register();
|
||||||
|
|
|
@ -2,16 +2,19 @@ package eu.m724.realweather.updater;
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
public class UpdaterConfig {
|
/**
|
||||||
public boolean notify;
|
*
|
||||||
public String channel;
|
* @param alert alert admins about updates
|
||||||
|
* @param channel update channel
|
||||||
|
*/
|
||||||
|
public record UpdaterConfig(
|
||||||
|
boolean alert, // this is different because I can't use notify in records sadly
|
||||||
|
String channel
|
||||||
|
) {
|
||||||
public static UpdaterConfig fromConfiguration(ConfigurationSection configuration) {
|
public static UpdaterConfig fromConfiguration(ConfigurationSection configuration) {
|
||||||
UpdaterConfig updaterConfig = new UpdaterConfig();
|
return new UpdaterConfig(
|
||||||
|
configuration.getBoolean("notify"),
|
||||||
updaterConfig.notify = configuration.getBoolean("notify");
|
configuration.getString("channel")
|
||||||
updaterConfig.channel = configuration.getString("channel");
|
);
|
||||||
|
|
||||||
return updaterConfig;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,14 @@ import eu.m724.wtapi.object.Weather;
|
||||||
import org.bukkit.WeatherType;
|
import org.bukkit.WeatherType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
// TODO make weather more comprehensive
|
// TODO make weather more comprehensive
|
||||||
public class WeatherChanger implements Listener {
|
public class WeatherChanger implements Listener {
|
||||||
private final Mapper mapper = GlobalConstants.getMapper();
|
private final Mapper mapper = GlobalConstants.getMapper();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onWeatherUpdate(AsyncWeatherUpdateEvent event) {
|
public void onWeatherUpdate(AsyncWeatherUpdateEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Weather weather = event.getWeather();
|
Weather weather = event.getWeather();
|
||||||
|
|
|
@ -7,15 +7,13 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||||
*
|
*
|
||||||
* @param enabled Is weather module enabled
|
* @param enabled Is weather module enabled
|
||||||
* @param provider The provider name, may or may not exist, if it doesn't, an error is thrown later
|
* @param provider The provider name, may or may not exist, if it doesn't, an error is thrown later
|
||||||
* @param apiKey API key for the provider,
|
* @param apiKey API key for the provider
|
||||||
* @param dynamic dynamic mode, weather is per player or global
|
* @param dynamic dynamic mode, weather is per player or global
|
||||||
*/
|
*/
|
||||||
public record WeatherConfig(
|
public record WeatherConfig(
|
||||||
boolean enabled,
|
boolean enabled,
|
||||||
|
|
||||||
String provider,
|
String provider,
|
||||||
String apiKey, // TODO don't expose that, I mean it's only used in one place in init
|
String apiKey, // TODO don't expose that, I mean it's only used in one place in init
|
||||||
|
|
||||||
boolean dynamic
|
boolean dynamic
|
||||||
) {
|
) {
|
||||||
public static WeatherConfig fromConfiguration(ConfigurationSection configuration) {
|
public static WeatherConfig fromConfiguration(ConfigurationSection configuration) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.m724.realweather.weather;
|
package eu.m724.realweather.weather;
|
||||||
|
|
||||||
|
import eu.m724.realweather.Configs;
|
||||||
import org.bukkit.GameRule;
|
import org.bukkit.GameRule;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
@ -12,13 +13,9 @@ import eu.m724.wtapi.provider.exception.ProviderException;
|
||||||
import eu.m724.wtapi.provider.weather.WeatherProvider;
|
import eu.m724.wtapi.provider.weather.WeatherProvider;
|
||||||
|
|
||||||
public class WeatherMaster {
|
public class WeatherMaster {
|
||||||
private final WeatherConfig config;
|
private final WeatherConfig config = Configs.weatherConfig();
|
||||||
private final Mapper mapper = GlobalConstants.getMapper();
|
private final Mapper mapper = GlobalConstants.getMapper();
|
||||||
|
|
||||||
public WeatherMaster(WeatherConfig config) {
|
|
||||||
this.config = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initializes, tests and starts
|
* initializes, tests and starts
|
||||||
* @throws ProviderException if provider initialization failed
|
* @throws ProviderException if provider initialization failed
|
||||||
|
|
|
@ -9,6 +9,7 @@ provider: blitzortung
|
||||||
|
|
||||||
# How often should we poll for updates and spawn lightning
|
# How often should we poll for updates and spawn lightning
|
||||||
# This is a synchronous task
|
# This is a synchronous task
|
||||||
# If you put it too low you'll have lag,
|
# Exaggerating, if you put it too low you'll have lag,
|
||||||
# But if you put it too high you'll have lag spikes and weird lightning
|
# But if you put it too high you'll have lag spikes and weird lightning
|
||||||
refresh: 100 # ticks
|
# In ticks, default 100 is 5 seconds so reduce if lightning seems weird, in my testing even 5 ticks is fine
|
||||||
|
refreshPeriod: 100
|
||||||
|
|
|
@ -15,5 +15,7 @@ enabled: false
|
||||||
dynamic: true
|
dynamic: true
|
||||||
|
|
||||||
# x in game day cycles in 1 irl day cycle
|
# x in game day cycles in 1 irl day cycle
|
||||||
# Time will no longer be in sync
|
# 2.0 - time goes 2x SLOWER
|
||||||
|
# 0.5 - time goes 2x FASTER
|
||||||
|
# If modified, time will no longer be in sync with real life
|
||||||
scale: 1.0
|
scale: 1.0
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
# In Minecraft, it can only rain or not rain (or snow - but not both) and thunder or not thunder.
|
# In Minecraft, it can only rain or not rain (or snow - but not both) and thunder or not thunder.
|
||||||
# In real life, rain, thunder, snow can be heavy, moderate, light and in between and can coexist. That's excluding many other conditions.
|
# In real life, rain, thunder, snow can be heavy, moderate, light and in between and can coexist. That's excluding many other conditions.
|
||||||
|
# For now, there's just rain and thunder
|
||||||
# This plugin will improve in the future, but there's other stuff to work on currently. I hope you understand.
|
# This plugin will improve in the future, but there's other stuff to work on currently. I hope you understand.
|
||||||
|
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
Loading…
Reference in a new issue