diff --git a/pom.xml b/pom.xml index 801095c..cd79c05 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ eu.m724 wtapi - 0.4 + 0.5 diff --git a/src/main/java/eu/m724/realweather/GlobalConstants.java b/src/main/java/eu/m724/realweather/GlobalConstants.java index abbd9fe..649bb18 100644 --- a/src/main/java/eu/m724/realweather/GlobalConstants.java +++ b/src/main/java/eu/m724/realweather/GlobalConstants.java @@ -3,7 +3,9 @@ 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.thunder.ThunderMaster; import eu.m724.realweather.time.TimeConfig; import eu.m724.realweather.weather.PlayerWeatherDirectory; import eu.m724.realweather.weather.WeatherConfig; @@ -12,6 +14,10 @@ public class GlobalConstants { static WeatherConfig weatherConfig; static TimeConfig timeConfig; static ThunderConfig thunderConfig; + static MapperConfig mapperConfig; + + static ThunderMaster thunderMaster; + static Mapper mapper; static Plugin plugin; static PlayerWeatherDirectory playerWeatherDirectory; @@ -25,6 +31,12 @@ public class GlobalConstants { public static ThunderConfig getThunderConfig() { return thunderConfig; } + public static MapperConfig getMapperConfig() { + return mapperConfig; + } + public static ThunderMaster getThunderMaster() { + return thunderMaster; + } 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 370326f..a77b301 100644 --- a/src/main/java/eu/m724/realweather/RealWeatherPlugin.java +++ b/src/main/java/eu/m724/realweather/RealWeatherPlugin.java @@ -11,11 +11,11 @@ import org.bukkit.plugin.java.JavaPlugin; import com.google.common.base.Charsets; +import eu.m724.realweather.commands.AdminCommand; import eu.m724.realweather.commands.GeoCommand; import eu.m724.realweather.commands.LocalTimeCommand; import eu.m724.realweather.mapper.Mapper; import eu.m724.realweather.mapper.MapperConfig; -import eu.m724.realweather.mapper.MapperEventHandler; import eu.m724.realweather.object.UserException; import eu.m724.realweather.thunder.ThunderConfig; import eu.m724.realweather.thunder.ThunderMaster; @@ -26,7 +26,6 @@ import eu.m724.realweather.weather.WeatherMaster; import eu.m724.wtapi.provider.exception.ProviderException; public class RealWeatherPlugin extends JavaPlugin { - private Mapper mapper; private WeatherMaster weatherMaster; private ThunderMaster thunderMaster; private TimeMaster timeMaster; @@ -81,8 +80,8 @@ public class RealWeatherPlugin extends JavaPlugin { GlobalConstants.plugin = this; DebugLogger.info("loading mapper", 1); - GlobalConstants.mapper = new Mapper( - MapperConfig.fromConfiguration(mapConfiguration)); + GlobalConstants.mapperConfig = MapperConfig.fromConfiguration(mapConfiguration); + GlobalConstants.mapper = new Mapper(); GlobalConstants.mapper.registerEvents(this); try { @@ -117,6 +116,9 @@ public class RealWeatherPlugin extends JavaPlugin { return; } + GlobalConstants.thunderMaster = thunderMaster; + + getCommand("rwadmin").setExecutor(new AdminCommand()); getCommand("geo").setExecutor(new GeoCommand()); if (GlobalConstants.timeConfig.enabled) diff --git a/src/main/java/eu/m724/realweather/commands/AdminCommand.java b/src/main/java/eu/m724/realweather/commands/AdminCommand.java new file mode 100644 index 0000000..59a3ad3 --- /dev/null +++ b/src/main/java/eu/m724/realweather/commands/AdminCommand.java @@ -0,0 +1,97 @@ +package eu.m724.realweather.commands; + +import java.time.Duration; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; + +import eu.m724.realweather.GlobalConstants; +import eu.m724.realweather.mapper.MapperConfig; +import eu.m724.realweather.thunder.ThunderConfig; +import eu.m724.realweather.thunder.ThunderMaster; +import eu.m724.realweather.time.TimeConfig; +import eu.m724.realweather.weather.WeatherConfig; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.TextComponent; + +public class AdminCommand implements CommandExecutor { + private Plugin plugin = GlobalConstants.getPlugin(); + + private WeatherConfig weatherConfig = GlobalConstants.getWeatherConfig(); + private TimeConfig timeConfig = GlobalConstants.getTimeConfig(); + private ThunderConfig thunderConfig = GlobalConstants.getThunderConfig(); + private MapperConfig mapperConfig = GlobalConstants.getMapperConfig(); + + private ThunderMaster thunderMaster = GlobalConstants.getThunderMaster(); + + private BaseComponent enabledComponent = TextComponent.fromLegacy("YES\n", ChatColor.GREEN); + private BaseComponent disabledComponent = TextComponent.fromLegacy("NO\n", ChatColor.RED); + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + ComponentBuilder componentBuilder = + new ComponentBuilder("\nRealWeather " + plugin.getDescription().getVersion() + "\n\n") + .color(ChatColor.YELLOW); + + componentBuilder.append("Coordinate scale: ").color(ChatColor.GOLD); + componentBuilder.append(String.format("%d, %d blocks / deg\n", mapperConfig.scaleLatitude, mapperConfig.scaleLongitude)).color(ChatColor.AQUA); + + componentBuilder.append("\nWeather: ").color(ChatColor.GOLD); + componentBuilder.append(weatherConfig.enabled ? enabledComponent : disabledComponent); + + if (weatherConfig.enabled) { + componentBuilder.append(" Provider: ").color(ChatColor.GOLD); + componentBuilder.append(weatherConfig.provider + "\n").color(ChatColor.AQUA); + + componentBuilder.append(" Dynamic: ").color(ChatColor.GOLD); + componentBuilder.append(weatherConfig.dynamic ? enabledComponent : disabledComponent); + } + + componentBuilder.append("\nTime: ").color(ChatColor.GOLD); + componentBuilder.append(timeConfig.enabled ? enabledComponent : disabledComponent); + + if (timeConfig.enabled) { + componentBuilder.append(" Scale: ").color(ChatColor.GOLD); + componentBuilder.append(Double.toString(timeConfig.scale) + "\n").color(ChatColor.AQUA); + + long worldTime = timeConfig.calculateWorldTimeSeconds(); + Duration worldTimeDuration = Duration.ofSeconds(worldTime); + + String worldTimeFormatted = String.format("%d:%02d:%02d\n", + worldTimeDuration.toHours(), + worldTimeDuration.toMinutesPart(), + worldTimeDuration.toSecondsPart()); + + componentBuilder.append(" World time: ").color(ChatColor.GOLD); + componentBuilder.append(worldTimeFormatted).color(ChatColor.AQUA); + + componentBuilder.append(" Dynamic: ").color(ChatColor.GOLD); + componentBuilder.append(timeConfig.dynamic ? enabledComponent : disabledComponent); + } + + componentBuilder.append("\nThunder: ").color(ChatColor.GOLD); + componentBuilder.append(thunderConfig.enabled ? enabledComponent : disabledComponent); + + if (thunderConfig.enabled) { + componentBuilder.append(" Provider: ").color(ChatColor.GOLD); + 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(" Latency: ").color(ChatColor.GOLD); + componentBuilder.append(String.format("avg %dms\n", thunderMaster.getLatency())).color(ChatColor.AQUA); + + } + + sender.spigot().sendMessage(componentBuilder.create()); + + return true; + } + +} diff --git a/src/main/java/eu/m724/realweather/commands/GeoCommand.java b/src/main/java/eu/m724/realweather/commands/GeoCommand.java index 1ca8d5b..9ce6785 100644 --- a/src/main/java/eu/m724/realweather/commands/GeoCommand.java +++ b/src/main/java/eu/m724/realweather/commands/GeoCommand.java @@ -12,7 +12,6 @@ import eu.m724.wtapi.object.Coordinates; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.TextComponent; public class GeoCommand implements CommandExecutor { diff --git a/src/main/java/eu/m724/realweather/commands/LocalTimeCommand.java b/src/main/java/eu/m724/realweather/commands/LocalTimeCommand.java index d7bb8f0..358ad27 100644 --- a/src/main/java/eu/m724/realweather/commands/LocalTimeCommand.java +++ b/src/main/java/eu/m724/realweather/commands/LocalTimeCommand.java @@ -2,8 +2,6 @@ package eu.m724.realweather.commands; import java.time.Duration; import java.time.temporal.ChronoUnit; -import java.time.temporal.TemporalUnit; - import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; diff --git a/src/main/java/eu/m724/realweather/mapper/Mapper.java b/src/main/java/eu/m724/realweather/mapper/Mapper.java index 1ef8966..3657ad7 100644 --- a/src/main/java/eu/m724/realweather/mapper/Mapper.java +++ b/src/main/java/eu/m724/realweather/mapper/Mapper.java @@ -1,31 +1,24 @@ package eu.m724.realweather.mapper; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; import java.util.function.Consumer; -import org.bukkit.GameRule; 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 MapperConfig config; + private MapperConfig config = GlobalConstants.getMapperConfig(); private List worlds = new ArrayList<>(); private List> worldLoadConsumers = new ArrayList<>(); private List> worldUnloadConsumers = new ArrayList<>(); // TODO game rules - public Mapper(MapperConfig config) { - this.config = config; - } - /** * Registers a consumer which will be called on world load * @param consumer diff --git a/src/main/java/eu/m724/realweather/mapper/MapperConfig.java b/src/main/java/eu/m724/realweather/mapper/MapperConfig.java index bbe33cb..cb6ad6f 100644 --- a/src/main/java/eu/m724/realweather/mapper/MapperConfig.java +++ b/src/main/java/eu/m724/realweather/mapper/MapperConfig.java @@ -7,8 +7,6 @@ import org.bukkit.configuration.ConfigurationSection; import eu.m724.wtapi.object.Coordinates; public class MapperConfig { - public boolean enabled; - public boolean worldBlacklist; public List worlds; @@ -20,8 +18,6 @@ public class MapperConfig { public static MapperConfig fromConfiguration(ConfigurationSection configuration) { MapperConfig mapperConfig = new MapperConfig(); - mapperConfig.enabled = configuration.getBoolean("enabled"); - mapperConfig.worldBlacklist = configuration.getBoolean("worldBlacklist"); mapperConfig.worlds = configuration.getStringList("worlds"); diff --git a/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java b/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java index b2d5dc2..e08a2d0 100644 --- a/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java +++ b/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java @@ -1,12 +1,9 @@ package eu.m724.realweather.thunder; -import java.util.ArrayList; - import org.bukkit.plugin.Plugin; import eu.m724.realweather.DebugLogger; import eu.m724.realweather.GlobalConstants; -import eu.m724.realweather.mapper.Mapper; import eu.m724.realweather.object.UserException; import eu.m724.wtapi.provider.exception.ProviderException; import eu.m724.wtapi.thunder.ThunderProvider; @@ -17,7 +14,6 @@ public class ThunderMaster { private ThunderProvider provider; private ThunderTask thunderTask; - private Mapper mapper = GlobalConstants.getMapper(); private Plugin plugin = GlobalConstants.getPlugin(); public ThunderMaster(ThunderConfig config) { @@ -55,4 +51,8 @@ public class ThunderMaster { return null; } + + public long getLatency() { + return provider.getLatency(); + } } diff --git a/src/main/java/eu/m724/realweather/thunder/ThunderTask.java b/src/main/java/eu/m724/realweather/thunder/ThunderTask.java index cc1fc86..1d29daf 100644 --- a/src/main/java/eu/m724/realweather/thunder/ThunderTask.java +++ b/src/main/java/eu/m724/realweather/thunder/ThunderTask.java @@ -3,7 +3,6 @@ package eu.m724.realweather.thunder; import java.util.ArrayList; import org.bukkit.Location; -import org.bukkit.entity.EntityType; import org.bukkit.scheduler.BukkitRunnable; import eu.m724.realweather.DebugLogger; diff --git a/src/main/java/eu/m724/realweather/time/AsyncPlayerTimeTask.java b/src/main/java/eu/m724/realweather/time/AsyncPlayerTimeTask.java index 23d54ba..740f2c4 100644 --- a/src/main/java/eu/m724/realweather/time/AsyncPlayerTimeTask.java +++ b/src/main/java/eu/m724/realweather/time/AsyncPlayerTimeTask.java @@ -7,13 +7,9 @@ import org.bukkit.scheduler.BukkitRunnable; import eu.m724.realweather.DebugLogger; import eu.m724.realweather.GlobalConstants; import eu.m724.realweather.mapper.Mapper; -import eu.m724.realweather.weather.PlayerWeatherDirectory; import eu.m724.wtapi.object.Coordinates; -import eu.m724.wtapi.object.Weather; public class AsyncPlayerTimeTask extends BukkitRunnable { - private PlayerWeatherDirectory playerWeatherDirectory = - GlobalConstants.getPlayerWeatherDirectory(); private Server server = GlobalConstants.getPlugin().getServer(); private Mapper mapper = GlobalConstants.getMapper(); diff --git a/src/main/java/eu/m724/realweather/time/TimeMaster.java b/src/main/java/eu/m724/realweather/time/TimeMaster.java index ace14c6..ced4488 100644 --- a/src/main/java/eu/m724/realweather/time/TimeMaster.java +++ b/src/main/java/eu/m724/realweather/time/TimeMaster.java @@ -5,7 +5,6 @@ import org.bukkit.plugin.Plugin; import eu.m724.realweather.DebugLogger; import eu.m724.realweather.GlobalConstants; -import eu.m724.realweather.commands.LocalTimeCommand; import eu.m724.realweather.mapper.Mapper; import eu.m724.realweather.object.UserException; diff --git a/src/main/java/eu/m724/realweather/weather/AsyncWeatherRetriever.java b/src/main/java/eu/m724/realweather/weather/AsyncWeatherRetriever.java index c47f9b3..f2ddec1 100644 --- a/src/main/java/eu/m724/realweather/weather/AsyncWeatherRetriever.java +++ b/src/main/java/eu/m724/realweather/weather/AsyncWeatherRetriever.java @@ -3,7 +3,6 @@ package eu.m724.realweather.weather; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; -import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; import org.bukkit.Server; diff --git a/src/main/java/eu/m724/realweather/weather/WeatherConfig.java b/src/main/java/eu/m724/realweather/weather/WeatherConfig.java index ea82d53..cd7a13f 100644 --- a/src/main/java/eu/m724/realweather/weather/WeatherConfig.java +++ b/src/main/java/eu/m724/realweather/weather/WeatherConfig.java @@ -10,8 +10,6 @@ public class WeatherConfig { // state is per player public boolean dynamic; - // prevent other stuff from changing weather - public boolean lock; public static WeatherConfig fromConfiguration(ConfigurationSection configuration) { WeatherConfig weatherConfig = new WeatherConfig(); @@ -22,7 +20,6 @@ public class WeatherConfig { weatherConfig.apiKey = configuration.getString("apiKey"); weatherConfig.dynamic = configuration.getBoolean("dynamic"); - weatherConfig.lock = configuration.getBoolean("lock"); return weatherConfig; } diff --git a/src/main/resources/modules/weather.yml b/src/main/resources/modules/weather.yml index 18969d6..5ac80c7 100644 --- a/src/main/resources/modules/weather.yml +++ b/src/main/resources/modules/weather.yml @@ -13,7 +13,4 @@ apiKey: REPLACE ME # - static (false): weather is the same across the world # - dynamic (true): weather is per player, however it's only cosmetical so it will not match mobs spawning etc # settings for both are in map.yml -dynamic: true - -# prevent the game, players or other plugins from changing the weather -lock: true \ No newline at end of file +dynamic: true \ No newline at end of file