From ab70e0d3c1e31cb63ae43d00927c780a90f5081b Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Sat, 2 Nov 2024 11:37:32 +0100 Subject: [PATCH] Small update 2 --- .../java/eu/m724/realweather/Configs.java | 17 ++++++++++ .../eu/m724/realweather/GlobalConstants.java | 21 ------------ .../m724/realweather/RealWeatherPlugin.java | 30 ++++++++--------- .../api/weather/AsyncWeatherUpdateEvent.java | 30 ++++++++++++++--- .../realweather/commands/AdminCommand.java | 30 ++++++++--------- .../commands/LocalTimeCommand.java | 4 +-- .../eu/m724/realweather/mapper/Mapper.java | 4 +-- .../mapper/MapperEventHandler.java | 2 +- .../realweather/thunder/ThunderConfig.java | 32 +++++++++---------- .../realweather/thunder/ThunderMaster.java | 13 +++----- .../eu/m724/realweather/time/TimeConfig.java | 19 ++++++----- .../eu/m724/realweather/time/TimeMaster.java | 11 +++---- .../realweather/updater/PluginUpdater.java | 15 ++++----- .../realweather/updater/UpdaterConfig.java | 23 +++++++------ .../realweather/weather/WeatherChanger.java | 3 +- .../realweather/weather/WeatherConfig.java | 4 +-- .../realweather/weather/WeatherMaster.java | 7 ++-- src/main/resources/modules/thunder.yml | 5 +-- src/main/resources/modules/time.yml | 4 ++- src/main/resources/modules/weather.yml | 1 + 20 files changed, 144 insertions(+), 131 deletions(-) diff --git a/src/main/java/eu/m724/realweather/Configs.java b/src/main/java/eu/m724/realweather/Configs.java index 47e4c82..18ebb52 100644 --- a/src/main/java/eu/m724/realweather/Configs.java +++ b/src/main/java/eu/m724/realweather/Configs.java @@ -1,5 +1,22 @@ 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 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; } } diff --git a/src/main/java/eu/m724/realweather/GlobalConstants.java b/src/main/java/eu/m724/realweather/GlobalConstants.java index 75a2486..e6c1d0b 100644 --- a/src/main/java/eu/m724/realweather/GlobalConstants.java +++ b/src/main/java/eu/m724/realweather/GlobalConstants.java @@ -3,36 +3,15 @@ package eu.m724.realweather; import org.bukkit.plugin.Plugin; 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; // perhaps replace with a singleton // TODO actually, remove it altogether public class GlobalConstants { - static TimeConfig timeConfig; - static ThunderConfig thunderConfig; - static MapperConfig mapperConfig; - static UpdaterConfig updaterConfig; - static Mapper mapper; static Plugin plugin; 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() { return mapper; } diff --git a/src/main/java/eu/m724/realweather/RealWeatherPlugin.java b/src/main/java/eu/m724/realweather/RealWeatherPlugin.java index 958d4f6..09a08f6 100644 --- a/src/main/java/eu/m724/realweather/RealWeatherPlugin.java +++ b/src/main/java/eu/m724/realweather/RealWeatherPlugin.java @@ -35,8 +35,6 @@ public class RealWeatherPlugin extends JavaPlugin { private ThunderMaster thunderMaster; private TimeMaster timeMaster; private PluginUpdater updater; - - private WeatherConfig weatherConfig; private Logger logger; @@ -88,29 +86,29 @@ public class RealWeatherPlugin extends JavaPlugin { GlobalConstants.playerWeatherCache = new PlayerWeatherCache(); DebugLogger.info("loading mapper", 1); - GlobalConstants.mapperConfig = MapperConfig.fromConfiguration(mapConfiguration); + Configs.mapperConfig = MapperConfig.fromConfiguration(mapConfiguration); GlobalConstants.mapper = new Mapper(); GlobalConstants.mapper.registerEvents(this); try { DebugLogger.info("loading weather", 1); - weatherConfig = WeatherConfig.fromConfiguration(weatherConfiguration); - weatherMaster = new WeatherMaster(weatherConfig); + Configs.weatherConfig = WeatherConfig.fromConfiguration(weatherConfiguration); + weatherMaster = new WeatherMaster(); weatherMaster.init(this); DebugLogger.info("loading thunder", 1); - GlobalConstants.thunderConfig = ThunderConfig.fromConfiguration(thunderConfiguration); - thunderMaster = new ThunderMaster(GlobalConstants.thunderConfig); + Configs.thunderConfig = ThunderConfig.fromConfiguration(thunderConfiguration); + thunderMaster = new ThunderMaster(); thunderMaster.init(this); DebugLogger.info("loading time", 1); - GlobalConstants.timeConfig = TimeConfig.fromConfiguration(timeConfiguration); - timeMaster = new TimeMaster(GlobalConstants.timeConfig); + Configs.timeConfig = TimeConfig.fromConfiguration(timeConfiguration); + timeMaster = new TimeMaster(); timeMaster.init(); - - GlobalConstants.updaterConfig = UpdaterConfig.fromConfiguration(configuration.getConfigurationSection("updater")); - updater = PluginUpdater.build(this, this.getFile(), GlobalConstants.updaterConfig); - updater.init(); + + Configs.updaterConfig = UpdaterConfig.fromConfiguration(configuration.getConfigurationSection("updater")); + updater = PluginUpdater.build(this, this.getFile()); + //updater.init(); } catch (UserError | NoSuchProviderException e) { logger.severe("There are errors in your config:"); logger.severe(e.getMessage()); @@ -128,13 +126,13 @@ public class RealWeatherPlugin extends JavaPlugin { 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()); - if (GlobalConstants.timeConfig.enabled()) + if (Configs.timeConfig.enabled()) getCommand("localtime").setExecutor(new LocalTimeCommand(timeMaster.getTimeConverter())); - if (weatherConfig.enabled()) { + if (Configs.weatherConfig.enabled()) { getCommand("localweather").setExecutor(new LocalWeatherCommand()); } diff --git a/src/main/java/eu/m724/realweather/api/weather/AsyncWeatherUpdateEvent.java b/src/main/java/eu/m724/realweather/api/weather/AsyncWeatherUpdateEvent.java index 78fa16b..0ba4dea 100644 --- a/src/main/java/eu/m724/realweather/api/weather/AsyncWeatherUpdateEvent.java +++ b/src/main/java/eu/m724/realweather/api/weather/AsyncWeatherUpdateEvent.java @@ -1,6 +1,7 @@ package eu.m724.realweather.api.weather; import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -8,14 +9,16 @@ import eu.m724.wtapi.object.Weather; /** * Fired when a weather state is retrieved
- * Not necessarily a change + * It doesn't mean the weather has changed, just that we retrieved the state
*/ -public class AsyncWeatherUpdateEvent extends Event { +public class AsyncWeatherUpdateEvent extends Event implements Cancellable { private static final HandlerList HANDLERS = new HandlerList(); private final Player player; private final Weather weather; - + + private boolean cancelled; + public AsyncWeatherUpdateEvent(Player player, Weather weather) { super(true); this.player = player; @@ -23,13 +26,15 @@ public class AsyncWeatherUpdateEvent extends Event { } /** - * - * @return a player that the weather is for, null if not dynamic + * @return a player that the weather is for, null if worldwide (static mode) */ public Player getPlayer() { return player; } + /** + * @return the weather state that was just changed + */ public Weather getWeather() { return weather; } @@ -42,4 +47,19 @@ public class AsyncWeatherUpdateEvent extends Event { public HandlerList getHandlers() { return HANDLERS; } + + @Override + public boolean isCancelled() { + return cancelled; + } + + /** + * Cancel weather change
+ * 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; + } } diff --git a/src/main/java/eu/m724/realweather/commands/AdminCommand.java b/src/main/java/eu/m724/realweather/commands/AdminCommand.java index 99b0a1a..fc064dc 100644 --- a/src/main/java/eu/m724/realweather/commands/AdminCommand.java +++ b/src/main/java/eu/m724/realweather/commands/AdminCommand.java @@ -2,6 +2,7 @@ package eu.m724.realweather.commands; import java.time.Duration; +import eu.m724.realweather.Configs; import eu.m724.realweather.time.TimeConverter; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -25,17 +26,16 @@ public class AdminCommand implements CommandExecutor { private final UpdateCommand updateCommand; private final Plugin plugin = GlobalConstants.getPlugin(); - private final WeatherConfig weatherConfig; - private final TimeConfig timeConfig = GlobalConstants.getTimeConfig(); - private final ThunderConfig thunderConfig = GlobalConstants.getThunderConfig(); - private final MapperConfig mapperConfig = GlobalConstants.getMapperConfig(); + private final WeatherConfig weatherConfig = Configs.weatherConfig(); + private final TimeConfig timeConfig = Configs.timeConfig(); + private final ThunderConfig thunderConfig = Configs.thunderConfig(); + private final MapperConfig mapperConfig = Configs.mapperConfig(); private final ThunderMaster thunderMaster; 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.weatherConfig = weatherConfig; this.thunderMaster = thunderMaster; this.timeConverter = timeConverter; } @@ -78,31 +78,31 @@ public class AdminCommand implements CommandExecutor { Duration worldTimeDuration = Duration.ofMillis(worldTime); - String worldTimeFormatted = String.format("%d:%02d:%02d\n", + String worldTimeFormatted = String.format("%d:%02d:%02d", worldTimeDuration.toHours(), worldTimeDuration.toMinutesPart(), worldTimeDuration.toSecondsPart()); componentBuilder.append(" World time: ").color(ChatColor.GOLD); 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(truthComponent(timeConfig.dynamic())); } 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(thunderConfig.provider + "\n").color(ChatColor.AQUA); + componentBuilder.append(thunderConfig.provider() + "\n").color(ChatColor.AQUA); - componentBuilder.append(" Refresh: ").color(ChatColor.GOLD); - componentBuilder.append(String.format("%d ticks\n", thunderConfig.refresh)).color(ChatColor.AQUA); + componentBuilder.append(" Refreshed every ").color(ChatColor.GOLD); + componentBuilder.append(String.format("%d ticks\n", thunderConfig.refreshPeriod())).color(ChatColor.AQUA); - componentBuilder.append(" Latency: ").color(ChatColor.GOLD); - componentBuilder.append(String.format("avg %dms\n", thunderMaster.getLatency())).color(ChatColor.AQUA); + componentBuilder.append(" API latency: ").color(ChatColor.GOLD); + componentBuilder.append(String.format("%dms\n", thunderMaster.getLatency())).color(ChatColor.AQUA); } diff --git a/src/main/java/eu/m724/realweather/commands/LocalTimeCommand.java b/src/main/java/eu/m724/realweather/commands/LocalTimeCommand.java index ef49a25..310de58 100644 --- a/src/main/java/eu/m724/realweather/commands/LocalTimeCommand.java +++ b/src/main/java/eu/m724/realweather/commands/LocalTimeCommand.java @@ -1,8 +1,8 @@ package eu.m724.realweather.commands; import java.time.Duration; -import java.time.temporal.ChronoUnit; +import eu.m724.realweather.Configs; import eu.m724.realweather.time.TimeConverter; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -19,7 +19,7 @@ import net.md_5.bungee.api.chat.ComponentBuilder; public class LocalTimeCommand implements CommandExecutor { private final Mapper mapper = GlobalConstants.getMapper(); - private final TimeConfig timeConfig = GlobalConstants.getTimeConfig(); + private final TimeConfig timeConfig = Configs.timeConfig(); private final TimeConverter timeConverter; public LocalTimeCommand(TimeConverter timeConverter) { diff --git a/src/main/java/eu/m724/realweather/mapper/Mapper.java b/src/main/java/eu/m724/realweather/mapper/Mapper.java index 9039d93..06b772d 100644 --- a/src/main/java/eu/m724/realweather/mapper/Mapper.java +++ b/src/main/java/eu/m724/realweather/mapper/Mapper.java @@ -4,15 +4,15 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; +import eu.m724.realweather.Configs; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.plugin.Plugin; -import eu.m724.realweather.GlobalConstants; import eu.m724.wtapi.object.Coordinates; public class Mapper { - private final MapperConfig config = GlobalConstants.getMapperConfig(); + private final MapperConfig config = Configs.mapperConfig(); private final List worlds = new ArrayList<>(); private final List> worldLoadConsumers = new ArrayList<>(); diff --git a/src/main/java/eu/m724/realweather/mapper/MapperEventHandler.java b/src/main/java/eu/m724/realweather/mapper/MapperEventHandler.java index 499420c..e2c1892 100644 --- a/src/main/java/eu/m724/realweather/mapper/MapperEventHandler.java +++ b/src/main/java/eu/m724/realweather/mapper/MapperEventHandler.java @@ -6,7 +6,7 @@ import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldUnloadEvent; public class MapperEventHandler implements Listener { - private Mapper mapper; + private final Mapper mapper; public MapperEventHandler(Mapper mapper) { this.mapper = mapper; diff --git a/src/main/java/eu/m724/realweather/thunder/ThunderConfig.java b/src/main/java/eu/m724/realweather/thunder/ThunderConfig.java index 1a54d70..9fbd146 100644 --- a/src/main/java/eu/m724/realweather/thunder/ThunderConfig.java +++ b/src/main/java/eu/m724/realweather/thunder/ThunderConfig.java @@ -2,22 +2,22 @@ package eu.m724.realweather.thunder; import org.bukkit.configuration.ConfigurationSection; -public class ThunderConfig { - public boolean enabled; - - public String provider; - - // how often refresh in ms - public int refresh; - +/** + * + * @param enabled is thunder module enabled + * @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 + */ +public record ThunderConfig( + boolean enabled, + String provider, + int refreshPeriod +) { public static ThunderConfig fromConfiguration(ConfigurationSection configuration) { - ThunderConfig thunderConfig = new ThunderConfig(); - - thunderConfig.enabled = configuration.getBoolean("enabled"); - thunderConfig.provider = configuration.getString("provider"); - - thunderConfig.refresh = configuration.getInt("refresh"); - - return thunderConfig; + return new ThunderConfig( + configuration.getBoolean("enabled"), + configuration.getString("provider"), + configuration.getInt("refreshPeriod") + ); } } diff --git a/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java b/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java index 4b8b252..eb3b815 100644 --- a/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java +++ b/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java @@ -1,5 +1,6 @@ package eu.m724.realweather.thunder; +import eu.m724.realweather.Configs; import org.bukkit.plugin.Plugin; import eu.m724.realweather.DebugLogger; @@ -9,28 +10,24 @@ import eu.m724.wtapi.provider.exception.ProviderException; import eu.m724.wtapi.provider.thunder.ThunderProvider; public class ThunderMaster { - private final ThunderConfig config; + private final ThunderConfig config = Configs.thunderConfig(); private ThunderProvider provider; - public ThunderMaster(ThunderConfig config) { - this.config = config; - } - /** * initializes, tests and starts * @throws ProviderException if provider initialization failed * @throws NoSuchProviderException config issue */ public void init(Plugin plugin) throws ProviderException, NoSuchProviderException { - if (!config.enabled) + if (!config.enabled()) return; - provider = Providers.getThunderProvider(config.provider, null); + provider = Providers.getThunderProvider(config.provider(), null); provider.init(); ThunderTask thunderTask = new ThunderTask(provider); thunderTask.init(); - thunderTask.runTaskTimer(plugin, 0, config.refresh); + thunderTask.runTaskTimer(plugin, 0, config.refreshPeriod()); DebugLogger.info("thunder loaded", 1); } diff --git a/src/main/java/eu/m724/realweather/time/TimeConfig.java b/src/main/java/eu/m724/realweather/time/TimeConfig.java index ecd013c..c88fe5f 100644 --- a/src/main/java/eu/m724/realweather/time/TimeConfig.java +++ b/src/main/java/eu/m724/realweather/time/TimeConfig.java @@ -2,19 +2,22 @@ package eu.m724.realweather.time; 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( boolean enabled, - boolean dynamic, - double scale ) { public static TimeConfig fromConfiguration(ConfigurationSection configuration) { - boolean enabled = configuration.getBoolean("enabled"); - - boolean dynamic = configuration.getBoolean("dynamic"); - double scale = configuration.getDouble("scale"); - - return new TimeConfig(enabled, dynamic, scale); + return new TimeConfig( + configuration.getBoolean("enabled"), + configuration.getBoolean("dynamic"), + configuration.getDouble("scale") + ); } } diff --git a/src/main/java/eu/m724/realweather/time/TimeMaster.java b/src/main/java/eu/m724/realweather/time/TimeMaster.java index 84f1a5d..8edbf97 100644 --- a/src/main/java/eu/m724/realweather/time/TimeMaster.java +++ b/src/main/java/eu/m724/realweather/time/TimeMaster.java @@ -1,5 +1,6 @@ package eu.m724.realweather.time; +import eu.m724.realweather.Configs; import org.bukkit.GameRule; import org.bukkit.plugin.Plugin; @@ -10,14 +11,10 @@ import eu.m724.realweather.mapper.Mapper; public class TimeMaster { private final Mapper mapper = GlobalConstants.getMapper(); private final Plugin plugin = GlobalConstants.getPlugin(); + private final TimeConfig timeConfig = Configs.timeConfig(); - private final TimeConfig timeConfig; - private final TimeConverter timeConverter; - - public TimeMaster(TimeConfig timeConfig) { - this.timeConfig = timeConfig; - this.timeConverter = new TimeConverter(timeConfig.scale()); - } + // TODO I don't want to initialize this here + private final TimeConverter timeConverter = new TimeConverter(timeConfig.scale()); // TODO this is only used once public TimeConverter getTimeConverter() { diff --git a/src/main/java/eu/m724/realweather/updater/PluginUpdater.java b/src/main/java/eu/m724/realweather/updater/PluginUpdater.java index a17eae2..7108a9b 100644 --- a/src/main/java/eu/m724/realweather/updater/PluginUpdater.java +++ b/src/main/java/eu/m724/realweather/updater/PluginUpdater.java @@ -4,7 +4,7 @@ import eu.m724.jarupdater.environment.ConstantEnvironment; import eu.m724.jarupdater.updater.Updater; import eu.m724.jarupdater.verify.SignatureVerifier; import eu.m724.jarupdater.verify.Verifier; -import eu.m724.realweather.GlobalConstants; +import eu.m724.realweather.Configs; import org.bukkit.plugin.Plugin; import eu.m724.jarupdater.download.Downloader; @@ -19,20 +19,19 @@ import java.io.IOException; import java.io.InputStream; public class PluginUpdater extends Updater { - private final UpdaterConfig updaterConfig; + private final UpdaterConfig updaterConfig = Configs.updaterConfig(); 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); - this.updaterConfig = updaterConfig; 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( plugin.getDescription().getVersion(), - GlobalConstants.getUpdaterConfig().channel, + Configs.updaterConfig().channel(), file.toPath() ); @@ -47,11 +46,11 @@ public class PluginUpdater extends Updater { throw new RuntimeException(e); } - return new PluginUpdater(plugin, environment, metadataFacade, downloader, verifier, updaterConfig); + return new PluginUpdater(plugin, environment, metadataFacade, downloader, verifier); } public void init() { - if (!updaterConfig.notify) return; + if (!updaterConfig.alert()) return; UpdateNotifier updateNotifier = new UpdateNotifier(this, (version) -> {}); updateNotifier.register(); diff --git a/src/main/java/eu/m724/realweather/updater/UpdaterConfig.java b/src/main/java/eu/m724/realweather/updater/UpdaterConfig.java index 162c629..19a4d3d 100644 --- a/src/main/java/eu/m724/realweather/updater/UpdaterConfig.java +++ b/src/main/java/eu/m724/realweather/updater/UpdaterConfig.java @@ -2,16 +2,19 @@ package eu.m724.realweather.updater; 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) { - UpdaterConfig updaterConfig = new UpdaterConfig(); - - updaterConfig.notify = configuration.getBoolean("notify"); - updaterConfig.channel = configuration.getString("channel"); - - return updaterConfig; + return new UpdaterConfig( + configuration.getBoolean("notify"), + configuration.getString("channel") + ); } } diff --git a/src/main/java/eu/m724/realweather/weather/WeatherChanger.java b/src/main/java/eu/m724/realweather/weather/WeatherChanger.java index fc9b2d6..3c7676c 100644 --- a/src/main/java/eu/m724/realweather/weather/WeatherChanger.java +++ b/src/main/java/eu/m724/realweather/weather/WeatherChanger.java @@ -8,13 +8,14 @@ import eu.m724.wtapi.object.Weather; import org.bukkit.WeatherType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; // TODO make weather more comprehensive public class WeatherChanger implements Listener { private final Mapper mapper = GlobalConstants.getMapper(); - @EventHandler + @EventHandler(priority = EventPriority.LOWEST) public void onWeatherUpdate(AsyncWeatherUpdateEvent event) { Player player = event.getPlayer(); Weather weather = event.getWeather(); diff --git a/src/main/java/eu/m724/realweather/weather/WeatherConfig.java b/src/main/java/eu/m724/realweather/weather/WeatherConfig.java index e7d56ba..ffcd497 100644 --- a/src/main/java/eu/m724/realweather/weather/WeatherConfig.java +++ b/src/main/java/eu/m724/realweather/weather/WeatherConfig.java @@ -7,15 +7,13 @@ import org.bukkit.configuration.ConfigurationSection; * * @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 apiKey API key for the provider, + * @param apiKey API key for the provider * @param dynamic dynamic mode, weather is per player or global */ public record WeatherConfig( boolean enabled, - String provider, String apiKey, // TODO don't expose that, I mean it's only used in one place in init - boolean dynamic ) { public static WeatherConfig fromConfiguration(ConfigurationSection configuration) { diff --git a/src/main/java/eu/m724/realweather/weather/WeatherMaster.java b/src/main/java/eu/m724/realweather/weather/WeatherMaster.java index 41889b7..6b9b71f 100644 --- a/src/main/java/eu/m724/realweather/weather/WeatherMaster.java +++ b/src/main/java/eu/m724/realweather/weather/WeatherMaster.java @@ -1,5 +1,6 @@ package eu.m724.realweather.weather; +import eu.m724.realweather.Configs; import org.bukkit.GameRule; import org.bukkit.plugin.Plugin; @@ -12,12 +13,8 @@ import eu.m724.wtapi.provider.exception.ProviderException; import eu.m724.wtapi.provider.weather.WeatherProvider; public class WeatherMaster { - private final WeatherConfig config; + private final WeatherConfig config = Configs.weatherConfig(); private final Mapper mapper = GlobalConstants.getMapper(); - - public WeatherMaster(WeatherConfig config) { - this.config = config; - } /** * initializes, tests and starts diff --git a/src/main/resources/modules/thunder.yml b/src/main/resources/modules/thunder.yml index 406437b..5293ffc 100644 --- a/src/main/resources/modules/thunder.yml +++ b/src/main/resources/modules/thunder.yml @@ -9,6 +9,7 @@ provider: blitzortung # How often should we poll for updates and spawn lightning # 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 -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 diff --git a/src/main/resources/modules/time.yml b/src/main/resources/modules/time.yml index 2a1df3a..bbc768f 100644 --- a/src/main/resources/modules/time.yml +++ b/src/main/resources/modules/time.yml @@ -15,5 +15,7 @@ enabled: false dynamic: true # 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 \ No newline at end of file diff --git a/src/main/resources/modules/weather.yml b/src/main/resources/modules/weather.yml index d0740a0..9ca0ebc 100644 --- a/src/main/resources/modules/weather.yml +++ b/src/main/resources/modules/weather.yml @@ -4,6 +4,7 @@ # 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. +# 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. enabled: false