This commit is contained in:
		
					parent
					
						
							
								6be00362fb
							
						
					
				
			
			
				commit
				
					
						5d53237ae0
					
				
			
		
					 5 changed files with 48 additions and 86 deletions
				
			
		| 
						 | 
				
			
			@ -126,7 +126,7 @@ public class RealWeatherPlugin extends JavaPlugin {
 | 
			
		|||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		getCommand("rwadmin").setExecutor(new AdminCommand(updater, thunderMaster, timeMaster.getTimeConverter()));
 | 
			
		||||
		getCommand("rwadmin").setExecutor(new AdminCommand(updater, thunderMaster));
 | 
			
		||||
		getCommand("geo").setExecutor(new GeoCommand());
 | 
			
		||||
 | 
			
		||||
		if (Configs.timeConfig.enabled())
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,6 @@
 | 
			
		|||
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;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
| 
						 | 
				
			
			@ -17,9 +14,6 @@ import eu.m724.realweather.time.TimeConfig;
 | 
			
		|||
import eu.m724.realweather.updater.PluginUpdater;
 | 
			
		||||
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;
 | 
			
		||||
 | 
			
		||||
// TODO unmess this all
 | 
			
		||||
public class AdminCommand implements CommandExecutor {
 | 
			
		||||
| 
						 | 
				
			
			@ -32,88 +26,48 @@ public class AdminCommand implements CommandExecutor {
 | 
			
		|||
	private final MapperConfig mapperConfig = Configs.mapperConfig();
 | 
			
		||||
	
 | 
			
		||||
	private final ThunderMaster thunderMaster;
 | 
			
		||||
	private final TimeConverter timeConverter;
 | 
			
		||||
	
 | 
			
		||||
	public AdminCommand(PluginUpdater updater, ThunderMaster thunderMaster, TimeConverter timeConverter) {
 | 
			
		||||
	public AdminCommand(PluginUpdater updater, ThunderMaster thunderMaster) {
 | 
			
		||||
		this.updateCommand = new UpdateCommand(updater);
 | 
			
		||||
		this.thunderMaster = thunderMaster;
 | 
			
		||||
		this.timeConverter = timeConverter;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
			
		||||
		
 | 
			
		||||
		if (args.length > 0 && args[0].equals("update")) {
 | 
			
		||||
			return updateCommand.onCommand(sender, command, label, 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(truthComponent(weatherConfig.enabled()));
 | 
			
		||||
		colorize(sender, "\n&eRealWeather %s\n\n", plugin.getDescription().getVersion().replace("-SNAPSHOT", "&c-SNAPSHOT"));
 | 
			
		||||
 | 
			
		||||
		colorize(sender, "&6Coordinate scale: &b%d, %d &7blocks / deg", mapperConfig.scaleLatitude, mapperConfig.scaleLongitude);
 | 
			
		||||
 | 
			
		||||
		colorize(sender, "\n&6Weather: %s", weatherConfig.enabled() ? (weatherConfig.dynamic() ? "&aYes, dynamic" : "&aYes, static") : "&cDisabled");
 | 
			
		||||
		
 | 
			
		||||
		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(truthComponent(weatherConfig.dynamic()));
 | 
			
		||||
			colorize(sender, " &6Provider: &b%s", weatherConfig.provider());
 | 
			
		||||
			colorize(sender, " &6/localweather to see current weather");
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		componentBuilder.append("\nTime: ").color(ChatColor.GOLD);
 | 
			
		||||
		componentBuilder.append(truthComponent(timeConfig.enabled()));
 | 
			
		||||
 | 
			
		||||
		colorize(sender, "\n&6Time: %s", timeConfig.enabled() ? (timeConfig.dynamic() ? "&aYes, dynamic" : "&aYes, static") : "&cDisabled");
 | 
			
		||||
		
 | 
			
		||||
		if (timeConfig.enabled()) {
 | 
			
		||||
			componentBuilder.append(" Scale: ").color(ChatColor.GOLD);
 | 
			
		||||
			componentBuilder.append(timeConfig.scale() + "\n").color(ChatColor.AQUA);
 | 
			
		||||
 | 
			
		||||
			long worldTime = System.currentTimeMillis();
 | 
			
		||||
			worldTime = timeConverter.scale(worldTime) % 86400000;
 | 
			
		||||
			long worldTimeTicks = timeConverter.millisToTicks(worldTime);
 | 
			
		||||
 | 
			
		||||
			Duration worldTimeDuration = Duration.ofMillis(worldTime);
 | 
			
		||||
			
 | 
			
		||||
			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\n".formatted(worldTimeTicks)).color(ChatColor.GRAY);
 | 
			
		||||
 | 
			
		||||
			componentBuilder.append(" Dynamic: ").color(ChatColor.GOLD);
 | 
			
		||||
			componentBuilder.append(truthComponent(timeConfig.dynamic()));
 | 
			
		||||
			colorize(sender, " &6Scale: &b%s&7x", timeConfig.scale());
 | 
			
		||||
			colorize(sender, " &6/localtime to see current time");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		componentBuilder.append("\nThunder: ").color(ChatColor.GOLD);
 | 
			
		||||
		componentBuilder.append(truthComponent(thunderConfig.enabled()));
 | 
			
		||||
		colorize(sender, "\n&6Thunder: %s", thunderConfig.enabled() ? "&aYes, dynamic" : "&cDisabled");
 | 
			
		||||
		
 | 
			
		||||
		if (thunderConfig.enabled()) {
 | 
			
		||||
			componentBuilder.append(" Provider: ").color(ChatColor.GOLD);
 | 
			
		||||
			componentBuilder.append(thunderConfig.provider() + "\n").color(ChatColor.AQUA);
 | 
			
		||||
 | 
			
		||||
			componentBuilder.append(" Refreshed every ").color(ChatColor.GOLD);
 | 
			
		||||
			componentBuilder.append(String.format("%d ticks\n", thunderConfig.refreshPeriod())).color(ChatColor.AQUA);
 | 
			
		||||
			
 | 
			
		||||
			componentBuilder.append(" API latency: ").color(ChatColor.GOLD);
 | 
			
		||||
			componentBuilder.append(String.format("%dms\n", thunderMaster.getLatency())).color(ChatColor.AQUA);
 | 
			
		||||
			
 | 
			
		||||
			colorize(sender, " &6Provider: &b%s", thunderConfig.provider());
 | 
			
		||||
			colorize(sender, " &6Refresh period: &b%d &7ticks", thunderConfig.refreshPeriod());
 | 
			
		||||
			colorize(sender, " &6API latency: &b%d&7ms", thunderMaster.getLatency());
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		sender.spigot().sendMessage(componentBuilder.create());
 | 
			
		||||
		
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private BaseComponent[] truthComponent(boolean truth) {
 | 
			
		||||
		return truth ?
 | 
			
		||||
				TextComponent.fromLegacyText("YES\n", ChatColor.GREEN)
 | 
			
		||||
				: TextComponent.fromLegacyText("NO\n", ChatColor.RED);
 | 
			
		||||
	private void colorize(CommandSender sender, String text, Object... format) {
 | 
			
		||||
		sender.sendMessage(ChatColor.translateAlternateColorCodes('&', text.formatted(format)));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
package eu.m724.realweather.commands;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import net.md_5.bungee.api.chat.ClickEvent;
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
| 
						 | 
				
			
			@ -16,6 +16,7 @@ import net.md_5.bungee.api.ChatColor;
 | 
			
		|||
import net.md_5.bungee.api.chat.BaseComponent;
 | 
			
		||||
import net.md_5.bungee.api.chat.ComponentBuilder;
 | 
			
		||||
 | 
			
		||||
// TODO unmess components here
 | 
			
		||||
public class GeoCommand implements CommandExecutor {
 | 
			
		||||
	private PlayerWeatherCache playerWeatherCache = GlobalConstants.getPlayerWeatherCache();
 | 
			
		||||
	private Mapper mapper = GlobalConstants.getMapper();
 | 
			
		||||
| 
						 | 
				
			
			@ -38,7 +39,7 @@ public class GeoCommand implements CommandExecutor {
 | 
			
		|||
						.append("x: %f, z: %f\n".formatted(location.getX(), location.getZ())).color(ChatColor.DARK_AQUA)
 | 
			
		||||
						.append("Address: ").color(ChatColor.GRAY)
 | 
			
		||||
						.append(address + "\n").color(ChatColor.DARK_AQUA)
 | 
			
		||||
						.create(); // TODO improve readability
 | 
			
		||||
						.create();
 | 
			
		||||
					
 | 
			
		||||
				player.spigot().sendMessage(component);
 | 
			
		||||
				
 | 
			
		||||
| 
						 | 
				
			
			@ -60,7 +61,11 @@ public class GeoCommand implements CommandExecutor {
 | 
			
		|||
			Location location = mapper.coordinatesToLocation(player.getWorld(), coordinates);
 | 
			
		||||
			
 | 
			
		||||
			BaseComponent[] component = new ComponentBuilder("\nPosition: ").color(ChatColor.GOLD)
 | 
			
		||||
					.append("x: %f, z: %f\n".formatted(location.getX(), location.getZ())).color(ChatColor.AQUA)
 | 
			
		||||
					.append(
 | 
			
		||||
							new ComponentBuilder("x: %f, z: %f\n".formatted(location.getX(), location.getZ()))
 | 
			
		||||
									.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/tp %f ~ %f".formatted(location.getX(), location.getZ())))
 | 
			
		||||
									.create()
 | 
			
		||||
					).color(ChatColor.AQUA)
 | 
			
		||||
					.append("Geolocation: ").color(ChatColor.GRAY)
 | 
			
		||||
					.append("lat: %f, lon: %f\n".formatted(coordinates.latitude, coordinates.longitude)).color(ChatColor.DARK_AQUA)
 | 
			
		||||
					.create();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,7 @@ import java.time.Instant;
 | 
			
		|||
import java.time.ZoneOffset;
 | 
			
		||||
import java.time.format.DateTimeFormatter;
 | 
			
		||||
 | 
			
		||||
import net.md_5.bungee.api.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
| 
						 | 
				
			
			@ -27,35 +28,39 @@ public class LocalWeatherCommand implements CommandExecutor {
 | 
			
		|||
		
 | 
			
		||||
		if (weather != null) {
 | 
			
		||||
			long lastUpdate = playerWeatherCache.getLastUpdate(player);
 | 
			
		||||
			player.sendMessage(weather.description);
 | 
			
		||||
			colorize(sender, "\n&e" + weather.description);
 | 
			
		||||
			
 | 
			
		||||
			if (weather.rainSeverity != null)
 | 
			
		||||
				player.sendMessage("Rain: %s".formatted(weather.rainSeverity.toString()));
 | 
			
		||||
				colorize(sender, "&6Rain: &b%s", weather.rainSeverity.toString());
 | 
			
		||||
			if (weather.drizzleSeverity != null)
 | 
			
		||||
				player.sendMessage("Drizzle: %s".formatted(weather.drizzleSeverity.toString()));
 | 
			
		||||
				colorize(sender, "&6Drizzle: &b%s", weather.drizzleSeverity.toString());
 | 
			
		||||
			if (weather.sleetSeverity != null)
 | 
			
		||||
				player.sendMessage("Sleet: %s".formatted(weather.sleetSeverity.toString()));
 | 
			
		||||
				colorize(sender, "&6Sleet: &b%s", weather.sleetSeverity.toString());
 | 
			
		||||
			if (weather.snowSeverity != null)
 | 
			
		||||
				player.sendMessage("Snow: %s".formatted(weather.snowSeverity.toString()));
 | 
			
		||||
				colorize(sender, "&6Snow: &b%s", weather.snowSeverity.toString());
 | 
			
		||||
			if (weather.thunderstormSeverity != null)
 | 
			
		||||
				player.sendMessage("Thunderstorm: %s".formatted(weather.thunderstormSeverity.toString()));
 | 
			
		||||
				colorize(sender, "&6Thunderstorm: &b%s", weather.thunderstormSeverity.toString());
 | 
			
		||||
			if (weather.shower)
 | 
			
		||||
				player.sendMessage("Shower: yes");
 | 
			
		||||
			
 | 
			
		||||
			player.sendMessage("Cloudiness: %f%%".formatted(weather.cloudiness * 100));
 | 
			
		||||
			player.sendMessage("Humidity: %f%%".formatted(weather.humidity * 100));
 | 
			
		||||
			player.sendMessage("Temperature: %fC (feels like %fC)".formatted(weather.temperature - 273.15, weather.temperatureApparent - 273.15));
 | 
			
		||||
			player.sendMessage("Wind: %fm/s (gust %fm/s) ".formatted(weather.windSpeed, weather.windGust));
 | 
			
		||||
			player.sendMessage("Last update: %s UTC".formatted(formatTime(lastUpdate)));
 | 
			
		||||
				colorize(sender, "&6Shower");
 | 
			
		||||
 | 
			
		||||
			colorize(sender, "&6Cloudiness: &b%f%&7%", weather.cloudiness * 100);
 | 
			
		||||
			colorize(sender, "&6Humidity: &b%f%&7%", weather.humidity * 100);
 | 
			
		||||
			colorize(sender, "&6Temperature: &b%f&7°C (feels like %f°C)", weather.temperature - 273.15, weather.temperatureApparent - 273.15);
 | 
			
		||||
			colorize(sender, "&6Wind: &b%f&7m/s (gust %fm/s)", weather.windSpeed, weather.windGust);
 | 
			
		||||
			colorize(sender, "&6Last update: &b%s UTC\n", formatTime(lastUpdate));
 | 
			
		||||
			
 | 
			
		||||
		} else {
 | 
			
		||||
			player.sendMessage("Weather not retrieved yet");
 | 
			
		||||
			colorize(sender, "&6No weather for you, try again in a second");
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void colorize(CommandSender sender, String text, Object... format) {
 | 
			
		||||
		sender.sendMessage(ChatColor.translateAlternateColorCodes('&', text.formatted(format)));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private String formatTime(long timestamp) { // TODO move this
 | 
			
		||||
	private String formatTime(long timestamp) {
 | 
			
		||||
		return DateTimeFormatter.ofPattern("HH:mm:ss").format(Instant.ofEpochMilli(timestamp).atZone(ZoneOffset.UTC));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,7 @@ commands:
 | 
			
		|||
    permission-message: You do not have permission to use this command.
 | 
			
		||||
    
 | 
			
		||||
  geo:
 | 
			
		||||
    description: Convert lat,lon to x,y,z and vice versa
 | 
			
		||||
    description: Convert lat,lon <=> x,y,z
 | 
			
		||||
    permission: realweather.command.geo
 | 
			
		||||
    permission-message: You do not have permission to use this command.
 | 
			
		||||
  localtime:
 | 
			
		||||
| 
						 | 
				
			
			@ -41,8 +41,6 @@ permissions:
 | 
			
		|||
  realweather.command.geo:
 | 
			
		||||
    description: Allows /geo
 | 
			
		||||
    default: true
 | 
			
		||||
  realweather.command.geo.tp:
 | 
			
		||||
    description: Allows teleportation using /geo
 | 
			
		||||
  realweather.command.localtime:
 | 
			
		||||
    description: Allows /localtime
 | 
			
		||||
    default: true
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue