parent
3f11d235b1
commit
ab70e0d3c1
20 changed files with 144 additions and 131 deletions
|
@ -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; }
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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<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 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<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 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);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<World> worlds = 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;
|
||||
|
||||
public class MapperEventHandler implements Listener {
|
||||
private Mapper mapper;
|
||||
private final Mapper mapper;
|
||||
|
||||
public MapperEventHandler(Mapper mapper) {
|
||||
this.mapper = mapper;
|
||||
|
|
|
@ -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")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue