This commit is contained in:
		
					parent
					
						
							
								8430d3ef6d
							
						
					
				
			
			
				commit
				
					
						3f11d235b1
					
				
			
		
					 10 changed files with 43 additions and 19 deletions
				
			
		|  | @ -7,7 +7,7 @@ jobs: | |||
|       - name: Prepare for installation | ||||
|         run: apt update | ||||
|       - name: Install JDK | ||||
|         run: apt install --no-install-recommends -y openjdk-21-jdk-headless maven git | ||||
|         run: apt install --no-install-recommends -y openjdk-21-jdk-headless maven git nodejs | ||||
| 
 | ||||
|       - name: Clone repository | ||||
|         run: git clone https://git.m724.eu/Minecon724/realweather.git . | ||||
|  |  | |||
|  | @ -53,8 +53,8 @@ public class LocalTimeCommand implements CommandExecutor { | |||
| 			long offsetTimeTicks = timeConverter.millisToTicks(offsetTime); | ||||
| 			boolean negative = offsetTime < 0; | ||||
| 			 | ||||
| 			Duration localTimeDuration = worldTimeDuration.plus(offsetTime, ChronoUnit.MILLIS); | ||||
| 			Duration offsetTimeDuration = Duration.ofMillis(negative ? -offsetTime : offsetTime); | ||||
| 			Duration localTimeDuration = Duration.ofMillis(Math.floorMod(worldTime + offsetTime, 86400000)); | ||||
| 			Duration offsetTimeDuration = Duration.ofMillis(Math.floorMod(negative ? -offsetTime : offsetTime, 86400000)); | ||||
| 			 | ||||
| 			String offsetTimeFormatted = String.format("%s%d:%02d:%02d", | ||||
| 					(negative ? "-" : "+"), | ||||
|  |  | |||
|  | @ -24,9 +24,9 @@ public class LocalWeatherCommand implements CommandExecutor { | |||
| 		} | ||||
| 
 | ||||
|         Weather weather = playerWeatherCache.getWeather(player); | ||||
| 		long lastUpdate = playerWeatherCache.getLastUpdate(player); | ||||
| 		 | ||||
| 		if (weather != null) { | ||||
| 			long lastUpdate = playerWeatherCache.getLastUpdate(player); | ||||
| 			player.sendMessage(weather.description); | ||||
| 			 | ||||
| 			if (weather.rainSeverity != null) | ||||
|  | @ -49,7 +49,7 @@ public class LocalWeatherCommand implements CommandExecutor { | |||
| 			player.sendMessage("Last update: %s UTC".formatted(formatTime(lastUpdate))); | ||||
| 			 | ||||
| 		} else { | ||||
| 			player.sendMessage("No weather for you"); | ||||
| 			player.sendMessage("Weather not retrieved yet"); | ||||
| 		} | ||||
| 		 | ||||
| 		return true; | ||||
|  |  | |||
|  | @ -13,9 +13,11 @@ public class SyncTimeUpdateTask extends BukkitRunnable { | |||
| 	private final Mapper mapper = GlobalConstants.getMapper(); | ||||
| 
 | ||||
| 	private final TimeConverter timeConverter; | ||||
| 	private final long zoneOffset; | ||||
| 
 | ||||
| 	SyncTimeUpdateTask(TimeConverter timeConverter) { | ||||
| 	SyncTimeUpdateTask(TimeConverter timeConverter, boolean dynamic) { | ||||
| 		this.timeConverter = timeConverter; | ||||
| 		this.zoneOffset = !dynamic ? timeConverter.calculateZoneOffset(mapper.getPoint().longitude) : 0; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
|  | @ -23,7 +25,7 @@ public class SyncTimeUpdateTask extends BukkitRunnable { | |||
| 		long time = System.currentTimeMillis(); | ||||
| 		time = timeConverter.scale(time); | ||||
| 
 | ||||
| 		long ticks = timeConverter.millisToTicks(time); | ||||
| 		long ticks = timeConverter.millisToTicks(time + zoneOffset); | ||||
| 
 | ||||
| 		DebugLogger.info("Updating time: %d", 2, ticks); | ||||
| 		 | ||||
|  |  | |||
|  | @ -46,6 +46,6 @@ public class TimeConverter { | |||
|      * @return milliseconds of offset from the center of the world (0) | ||||
|      */ | ||||
|     public long calculateZoneOffset(double longitude) { | ||||
|         return (long) (longitude * 3600000); | ||||
|         return (long) (longitude * 240000); | ||||
|     } | ||||
| } | ||||
|  | @ -35,7 +35,7 @@ public class TimeMaster { | |||
| 			DebugLogger.info("Warning: RealTime scale is not optimal. Time will be out of sync.", 0); | ||||
| 		} | ||||
| 		 | ||||
| 		new SyncTimeUpdateTask(timeConverter).runTaskTimer(plugin, 0, period); | ||||
| 		new SyncTimeUpdateTask(timeConverter, timeConfig.dynamic()).runTaskTimer(plugin, 0, period); | ||||
| 		 | ||||
| 		if (timeConfig.dynamic()) | ||||
| 			new AsyncPlayerTimeTask(timeConverter).runTaskTimerAsynchronously(plugin, 0, 60); // 5 seconds | ||||
|  |  | |||
|  | @ -9,6 +9,7 @@ import org.bukkit.entity.Player; | |||
| import org.bukkit.event.EventHandler; | ||||
| import org.bukkit.event.Listener; | ||||
| import org.bukkit.event.player.PlayerJoinEvent; | ||||
| import org.bukkit.event.player.PlayerTeleportEvent; | ||||
| import org.bukkit.plugin.Plugin; | ||||
| import org.bukkit.scheduler.BukkitRunnable; | ||||
| 
 | ||||
|  | @ -54,7 +55,8 @@ public class DynamicWeatherRetriever extends BukkitRunnable implements Listener | |||
| 			if (!player.hasPermission("realweather.dynamic")) continue; | ||||
| 			if (!mapper.getWorlds().contains(player.getWorld())) continue; | ||||
| 
 | ||||
| 			if (now - playerWeatherCache.getLastUpdate(player) < 10000) continue; | ||||
| 			Long lastUpdate = playerWeatherCache.getLastUpdate(player); | ||||
| 			if (lastUpdate != null && now - lastUpdate < 10000) continue; | ||||
| 
 | ||||
| 			Coordinates coordinates = mapper.locationToCoordinates(player.getLocation()); | ||||
| 			Coordinates closestCoordinates = null; | ||||
|  | @ -94,7 +96,9 @@ public class DynamicWeatherRetriever extends BukkitRunnable implements Listener | |||
| 			DebugLogger.info("Next update in %d", 3, nextUpdate); | ||||
| 		} else { // immediate update for those that need it right now | ||||
| 			if (neededUpdate.isEmpty()) return; | ||||
| 			DebugLogger.info("Players in need of update: %d", 2, neededUpdate.size()); | ||||
| 			coordinates = makeCoordinates(neededUpdate); | ||||
| 			neededUpdate.clear(); | ||||
| 		} | ||||
| 		Coordinates[] coordinatesArray = coordinates.coordinatesPlayersMap().keySet().toArray(Coordinates[]::new); | ||||
| 
 | ||||
|  | @ -123,7 +127,6 @@ public class DynamicWeatherRetriever extends BukkitRunnable implements Listener | |||
|         } | ||||
| 
 | ||||
|         DebugLogger.info("dynamic retriever done", 3); | ||||
| 		runTaskLaterAsynchronously(plugin, 1000); | ||||
| 	} | ||||
| 	 | ||||
| 	@EventHandler | ||||
|  | @ -131,5 +134,4 @@ public class DynamicWeatherRetriever extends BukkitRunnable implements Listener | |||
| 		Player player = event.getPlayer(); | ||||
| 		neededUpdate.add(player); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -4,26 +4,46 @@ import eu.m724.realweather.DebugLogger; | |||
| import eu.m724.realweather.GlobalConstants; | ||||
| import eu.m724.realweather.api.weather.AsyncWeatherUpdateEvent; | ||||
| import eu.m724.realweather.mapper.Mapper; | ||||
| import eu.m724.wtapi.object.Weather; | ||||
| import org.bukkit.WeatherType; | ||||
| import org.bukkit.entity.Player; | ||||
| import org.bukkit.event.EventHandler; | ||||
| import org.bukkit.event.Listener; | ||||
| 
 | ||||
| // TODO make weather more comprehensive | ||||
| public class WeatherChanger implements Listener { | ||||
|     private final Mapper mapper = GlobalConstants.getMapper(); | ||||
| 
 | ||||
|     @EventHandler | ||||
|     public void onWeatherUpdate(AsyncWeatherUpdateEvent event) { | ||||
|         Player player = event.getPlayer(); | ||||
|         Weather weather = event.getWeather(); | ||||
| 
 | ||||
|         if (player != null) { // dynamic mode | ||||
|             DebugLogger.info("Changing weather for player %s", 2, player.getName()); | ||||
| 
 | ||||
|             // TODO change weather | ||||
|             if (weather.isThundering() || weather.isSnowing() || weather.isRaining()) { | ||||
|                 player.setPlayerWeather(WeatherType.DOWNFALL); | ||||
|             } else { | ||||
|                 player.setPlayerWeather(WeatherType.CLEAR); | ||||
|             } | ||||
|         } else { // static mode | ||||
|             DebugLogger.info("Changing weather static", 3); | ||||
|             mapper.getWorlds().forEach(w -> { | ||||
|                 DebugLogger.info("Changing weather static in world %s", 2, w.getName()); | ||||
|                 // TODO change weather | ||||
|                 if (weather.isThundering()) { | ||||
|                     w.setClearWeatherDuration(0); | ||||
|                     w.setWeatherDuration(120000); | ||||
|                     w.setThunderDuration(120000); | ||||
|                 } else if (weather.isRaining() || weather.isSnowing()) { | ||||
|                     w.setClearWeatherDuration(0); | ||||
|                     w.setWeatherDuration(120000); | ||||
|                     w.setThunderDuration(0); | ||||
|                 } else { | ||||
|                     w.setClearWeatherDuration(120000); | ||||
|                     w.setWeatherDuration(0); | ||||
|                     w.setThunderDuration(0); | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|     } | ||||
|  |  | |||
|  | @ -9,6 +9,6 @@ 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 constant lag, | ||||
| # But if you put it too high it will process a lot of data at once so you'll have lag spikes | ||||
| # 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 | ||||
|  |  | |||
|  | @ -2,9 +2,9 @@ | |||
| ###   WEATHER SETTINGS   ### | ||||
| ############################ | ||||
| 
 | ||||
| # Weather in Minecraft is limited, it can only rain or not rain, thunder or not thunder. | ||||
| # In real life, there is a scale, and many more weather conditions in general, like blizzard. | ||||
| # This plugin tries hard to do something about it, but it's not perfect, because it's just impossible. | ||||
| # 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. | ||||
| # This plugin will improve in the future, but there's other stuff to work on currently. I hope you understand. | ||||
| 
 | ||||
| enabled: false | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Minecon724
				Minecon724