fix /geo
This commit is contained in:
		
					parent
					
						
							
								4df951b726
							
						
					
				
			
			
				commit
				
					
						a6bd920d17
					
				
			
		
					 5 changed files with 33 additions and 17 deletions
				
			
		
							
								
								
									
										2
									
								
								pom.xml
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
										
									
									
									
								
							| 
						 | 
					@ -49,7 +49,7 @@
 | 
				
			||||||
		<dependency>
 | 
							<dependency>
 | 
				
			||||||
			<groupId>eu.m724</groupId>
 | 
								<groupId>eu.m724</groupId>
 | 
				
			||||||
		    <artifactId>wtapi</artifactId>
 | 
							    <artifactId>wtapi</artifactId>
 | 
				
			||||||
		    <version>0.6</version>
 | 
							    <version>0.7</version>
 | 
				
			||||||
		</dependency>
 | 
							</dependency>
 | 
				
			||||||
	</dependencies>
 | 
						</dependencies>
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,7 @@ import eu.m724.realweather.time.TimeMaster;
 | 
				
			||||||
import eu.m724.realweather.updater.SignatureValidator;
 | 
					import eu.m724.realweather.updater.SignatureValidator;
 | 
				
			||||||
import eu.m724.realweather.updater.Updater;
 | 
					import eu.m724.realweather.updater.Updater;
 | 
				
			||||||
import eu.m724.realweather.updater.UpdaterConfig;
 | 
					import eu.m724.realweather.updater.UpdaterConfig;
 | 
				
			||||||
 | 
					import eu.m724.realweather.weather.PlayerWeatherDirectory;
 | 
				
			||||||
import eu.m724.realweather.weather.WeatherConfig;
 | 
					import eu.m724.realweather.weather.WeatherConfig;
 | 
				
			||||||
import eu.m724.realweather.weather.WeatherMaster;
 | 
					import eu.m724.realweather.weather.WeatherMaster;
 | 
				
			||||||
import eu.m724.wtapi.provider.exception.NoSuchProviderException;
 | 
					import eu.m724.wtapi.provider.exception.NoSuchProviderException;
 | 
				
			||||||
| 
						 | 
					@ -94,6 +95,7 @@ public class RealWeatherPlugin extends JavaPlugin {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		GlobalConstants.plugin = this;
 | 
							GlobalConstants.plugin = this;
 | 
				
			||||||
 | 
							GlobalConstants.playerWeatherDirectory = new PlayerWeatherDirectory();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		DebugLogger.info("loading mapper", 1);
 | 
							DebugLogger.info("loading mapper", 1);
 | 
				
			||||||
		GlobalConstants.mapperConfig = MapperConfig.fromConfiguration(mapConfiguration);
 | 
							GlobalConstants.mapperConfig = MapperConfig.fromConfiguration(mapConfiguration);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,7 @@ import org.bukkit.command.CommandSender;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import eu.m724.realweather.GlobalConstants;
 | 
					import eu.m724.realweather.GlobalConstants;
 | 
				
			||||||
 | 
					import eu.m724.realweather.mapper.Mapper;
 | 
				
			||||||
import eu.m724.realweather.weather.PlayerWeatherDirectory;
 | 
					import eu.m724.realweather.weather.PlayerWeatherDirectory;
 | 
				
			||||||
import eu.m724.wtapi.object.Coordinates;
 | 
					import eu.m724.wtapi.object.Coordinates;
 | 
				
			||||||
import eu.m724.wtapi.object.Weather;
 | 
					import eu.m724.wtapi.object.Weather;
 | 
				
			||||||
| 
						 | 
					@ -16,8 +17,8 @@ import net.md_5.bungee.api.chat.BaseComponent;
 | 
				
			||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
 | 
					import net.md_5.bungee.api.chat.ComponentBuilder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class GeoCommand implements CommandExecutor {
 | 
					public class GeoCommand implements CommandExecutor {
 | 
				
			||||||
	PlayerWeatherDirectory playerWeatherDirectory =
 | 
						private PlayerWeatherDirectory playerWeatherDirectory = GlobalConstants.getPlayerWeatherDirectory();
 | 
				
			||||||
			GlobalConstants.getPlayerWeatherDirectory();
 | 
						private Mapper mapper = GlobalConstants.getMapper();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
						public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
| 
						 | 
					@ -26,22 +27,21 @@ public class GeoCommand implements CommandExecutor {
 | 
				
			||||||
		if (args.length == 0) {
 | 
							if (args.length == 0) {
 | 
				
			||||||
			if (player != null)  {
 | 
								if (player != null)  {
 | 
				
			||||||
				Location location = player.getLocation();
 | 
									Location location = player.getLocation();
 | 
				
			||||||
				Coordinates coordinates = GlobalConstants.getMapper().locationToCoordinates(location);
 | 
									Coordinates coordinates = mapper.locationToCoordinates(location);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									Weather weather = playerWeatherDirectory.getWeather(player);
 | 
				
			||||||
 | 
									String address = formatAddress(weather);
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				BaseComponent[] component = new ComponentBuilder("\nGeolocation: ").color(ChatColor.GOLD)
 | 
									BaseComponent[] component = new ComponentBuilder("\nGeolocation: ").color(ChatColor.GOLD)
 | 
				
			||||||
						.append("lat: %f, lon: %f\n".formatted(coordinates.latitude, coordinates.longitude)).color(ChatColor.AQUA)
 | 
											.append("lat: %f, lon: %f\n".formatted(coordinates.latitude, coordinates.longitude)).color(ChatColor.AQUA)
 | 
				
			||||||
						.append("Position: ").color(ChatColor.GRAY)
 | 
											.append("Position: ").color(ChatColor.GRAY)
 | 
				
			||||||
						.append("x: %f, z: %f".formatted(location.getX(), location.getZ())).color(ChatColor.DARK_AQUA)
 | 
											.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(); // TODO improve readability
 | 
				
			||||||
					
 | 
										
 | 
				
			||||||
				player.spigot().sendMessage(component);
 | 
									player.spigot().sendMessage(component);
 | 
				
			||||||
				Weather weather = playerWeatherDirectory.getWeather(player);
 | 
									
 | 
				
			||||||
				if (weather != null) {
 | 
					 | 
				
			||||||
					component = new ComponentBuilder("You're in ").color(ChatColor.GRAY)
 | 
					 | 
				
			||||||
							.append(weather.city + "\n").color(ChatColor.DARK_AQUA)
 | 
					 | 
				
			||||||
							.create();
 | 
					 | 
				
			||||||
					player.spigot().sendMessage(component);
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				sender.sendMessage("Add arguments to use this command in console");
 | 
									sender.sendMessage("Add arguments to use this command in console");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					@ -57,7 +57,7 @@ public class GeoCommand implements CommandExecutor {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			Coordinates coordinates = new Coordinates(latitude, longitude);
 | 
								Coordinates coordinates = new Coordinates(latitude, longitude);
 | 
				
			||||||
			Location location = GlobalConstants.getMapper().coordinatesToLocation(player.getWorld(), coordinates);
 | 
								Location location = mapper.coordinatesToLocation(player.getWorld(), coordinates);
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			BaseComponent[] component = new ComponentBuilder("\nPosition: ").color(ChatColor.GOLD)
 | 
								BaseComponent[] component = new ComponentBuilder("\nPosition: ").color(ChatColor.GOLD)
 | 
				
			||||||
					.append("x: %f, z: %f\n".formatted(location.getX(), location.getZ())).color(ChatColor.AQUA)
 | 
										.append("x: %f, z: %f\n".formatted(location.getX(), location.getZ())).color(ChatColor.AQUA)
 | 
				
			||||||
| 
						 | 
					@ -72,6 +72,7 @@ public class GeoCommand implements CommandExecutor {
 | 
				
			||||||
					Location targetLoc =
 | 
										Location targetLoc =
 | 
				
			||||||
							location.getWorld().getHighestBlockAt(location).getLocation().add(0, 1, 0);
 | 
												location.getWorld().getHighestBlockAt(location).getLocation().add(0, 1, 0);
 | 
				
			||||||
					player.teleport(targetLoc);
 | 
										player.teleport(targetLoc);
 | 
				
			||||||
 | 
										player.sendMessage("Teleporting... The server will freeze for a second");
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
| 
						 | 
					@ -81,4 +82,17 @@ public class GeoCommand implements CommandExecutor {
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						private String formatAddress(Weather weather) {
 | 
				
			||||||
 | 
							if (weather == null) return "Weather not retrieved yet";
 | 
				
			||||||
 | 
							Coordinates coordinates = weather.coordinates;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if (coordinates.country == null && coordinates.city == null)
 | 
				
			||||||
 | 
								return "Unknown";
 | 
				
			||||||
 | 
							else if (coordinates.city == null)
 | 
				
			||||||
 | 
								return "Country: " + coordinates.country;
 | 
				
			||||||
 | 
							else if (coordinates.country == null)
 | 
				
			||||||
 | 
								return coordinates.city;
 | 
				
			||||||
 | 
							return coordinates.city + ", " + coordinates.country;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -69,9 +69,9 @@ public class Updater extends BukkitRunnable implements Listener {
 | 
				
			||||||
				DebugLogger.info("Unable to contact the update server! %d", 0, statusCode);
 | 
									DebugLogger.info("Unable to contact the update server! %d", 0, statusCode);
 | 
				
			||||||
				DebugLogger.info("As it's a server error, it's probably temporary and not a configuration issue, so proceeding.", 0);
 | 
									DebugLogger.info("As it's a server error, it's probably temporary and not a configuration issue, so proceeding.", 0);
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				DebugLogger.info("Update server returned unexpected status code! %d", 0, statusCode);
 | 
									DebugLogger.info("Update server returned unexpected status code: %d", 0, statusCode);
 | 
				
			||||||
				if (plugin.getDescription().getVersion().endsWith("SNAPSHOT")) {
 | 
									if (plugin.getDescription().getVersion().endsWith("SNAPSHOT")) {
 | 
				
			||||||
					DebugLogger.info("It looks like this is a development snapshot, possibly built from source. So actually this is expected.", 0);
 | 
										DebugLogger.info("Ignore as you're running a development snapshot.", 0);
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					DebugLogger.info("This is probably critical. RealWeather will continue without updater.", 0);
 | 
										DebugLogger.info("This is probably critical. RealWeather will continue without updater.", 0);
 | 
				
			||||||
					DebugLogger.info("Try restarting the server. If that doesn't help, contact support.", 0);
 | 
										DebugLogger.info("Try restarting the server. If that doesn't help, contact support.", 0);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,7 +33,7 @@ public class DynamicWeatherApplier extends BukkitRunnable {
 | 
				
			||||||
			if (player.hasPermission("realweather.actionbar")) {
 | 
								if (player.hasPermission("realweather.actionbar")) {
 | 
				
			||||||
				String text = String.format("%f %f (%s) - %s",
 | 
									String text = String.format("%f %f (%s) - %s",
 | 
				
			||||||
					weather.coordinates.latitude, weather.coordinates.longitude,
 | 
										weather.coordinates.latitude, weather.coordinates.longitude,
 | 
				
			||||||
					weather.city, weather.description);
 | 
										weather.coordinates.getAddress(), weather.description);
 | 
				
			||||||
				BaseComponent component = TextComponent.fromLegacy(text);
 | 
									BaseComponent component = TextComponent.fromLegacy(text);
 | 
				
			||||||
				player.spigot().sendMessage(ChatMessageType.ACTION_BAR, component);
 | 
									player.spigot().sendMessage(ChatMessageType.ACTION_BAR, component);
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue