it is monday and it means SCHOOL yay finally I don't have time
This commit is contained in:
Minecon724 2024-06-03 16:33:06 +02:00
parent af0972f69f
commit 883ce366d1
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
7 changed files with 102 additions and 36 deletions

View file

@ -22,13 +22,21 @@
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>eu.m724:wtapi</include>
<include>org.java-websocket:Java-WebSocket</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>eu.m724:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
</filters>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>

58
pom.xml
View file

@ -34,37 +34,45 @@
</dependency>
</dependencies>
<build>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>eu.m724:wtapi</include>
<include>org.java-websocket:Java-WebSocket</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>eu.m724:wtapi</include>
<include>org.java-websocket:Java-WebSocket</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>eu.m724:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
</filters>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View file

@ -5,6 +5,7 @@ import org.bukkit.plugin.Plugin;
import eu.m724.realweather.mapper.Mapper;
import eu.m724.realweather.thunder.ThunderConfig;
import eu.m724.realweather.time.TimeConfig;
import eu.m724.realweather.weather.PlayerWeatherDirectory;
import eu.m724.realweather.weather.WeatherConfig;
public class GlobalConstants {
@ -13,6 +14,7 @@ public class GlobalConstants {
static ThunderConfig thunderConfig;
static Mapper mapper;
static Plugin plugin;
static PlayerWeatherDirectory playerWeatherDirectory;
public static WeatherConfig getWeatherConfig() {
return weatherConfig;
@ -29,5 +31,8 @@ public class GlobalConstants {
public static Plugin getPlugin() {
return plugin;
}
public static PlayerWeatherDirectory getPlayerWeatherDirectory() {
return playerWeatherDirectory;
}
}

View file

@ -8,6 +8,9 @@ import java.util.stream.Collectors;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
@ -19,21 +22,22 @@ import eu.m724.wtapi.object.Coordinates;
import eu.m724.wtapi.object.Weather;
import eu.m724.wtapi.provider.WeatherProvider;
public class AsyncWeatherRetrieveTask extends BukkitRunnable {
public class AsyncWeatherRetriever extends BukkitRunnable implements Listener { // TODO split this
private WeatherProvider weatherProvider;
private boolean dynamic; // TODO handle config some other way
private boolean dynamic = GlobalConstants.getWeatherConfig().dynamic;
private Mapper mapper = GlobalConstants.getMapper();
private Plugin plugin = GlobalConstants.getPlugin();
private Server server = plugin.getServer();
private PlayerWeatherDirectory playerWeatherDirectory = GlobalConstants.getPlayerWeatherDirectory();
public AsyncWeatherRetrieveTask(WeatherProvider weatherProvider, boolean dynamic) {
public AsyncWeatherRetriever(WeatherProvider weatherProvider) {
this.weatherProvider = weatherProvider;
this.dynamic = dynamic;
}
@Override
public void run() {
DebugLogger.info("Weather retrieval", 3);
long delay = 6000;
if (dynamic) {
@ -62,14 +66,13 @@ public class AsyncWeatherRetrieveTask extends BukkitRunnable {
Player player = players.get(i);
Weather weather = weathers[i];
playerWeatherDirectory.weathers.put(player, weather);
AsyncWeatherUpdateEvent event =
new AsyncWeatherUpdateEvent(player, weather);
server.getPluginManager().callEvent(event);
// the event applies weather
}
/*DynamicWeatherApplier applier = new DynamicWeatherApplier(players, );
applier.runTask(plugin);*/
} catch (CompletionException e) { // TODO handle finer exceptions
DebugLogger.info("failed to retrieve weather data", 1);
@ -100,7 +103,27 @@ public class AsyncWeatherRetrieveTask extends BukkitRunnable {
}
DebugLogger.info("Scheduling restart with delay %d", 3, delay);
runTaskLaterAsynchronously(plugin, delay);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
Coordinates coordinates = mapper.locationToCoordinates(player.getLocation());
CompletableFuture<Weather> weatherFuture = weatherProvider.getWeather(coordinates);
DebugLogger.info("A player joined so I requested weather", 3);
weatherFuture.thenAccept(weather -> {
playerWeatherDirectory.weathers.put(player, weather);
AsyncWeatherUpdateEvent weatherEvent =
new AsyncWeatherUpdateEvent(player, weather);
server.getPluginManager().callEvent(weatherEvent);
}); // TODO is this really safe?
}
}

View file

@ -12,6 +12,7 @@ import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
// TODO this class is currently unused and it will probably be removed or replaced
public class DynamicWeatherApplier extends BukkitRunnable {
private List<Player> players;
private Weather[] weathers;
@ -43,7 +44,7 @@ public class DynamicWeatherApplier extends BukkitRunnable {
player.setPlayerWeather(WeatherType.DOWNFALL);
} else {
player.setPlayerWeather(WeatherType.CLEAR);
} // TODO
}
}
}

View file

@ -0,0 +1,15 @@
package eu.m724.realweather.weather;
import java.util.HashMap;
import org.bukkit.entity.Player;
import eu.m724.wtapi.object.Weather;
public class PlayerWeatherDirectory {
HashMap<Player, Weather> weathers = new HashMap<>();
public Weather getWeather(Player player) {
return weathers.get(player); // TODO concurrent exception?
}
}

View file

@ -1,5 +1,7 @@
package eu.m724.realweather.weather;
import org.bukkit.plugin.Plugin;
import eu.m724.realweather.DebugLogger;
import eu.m724.realweather.GlobalConstants;
import eu.m724.realweather.mapper.Mapper;
@ -12,6 +14,7 @@ public class WeatherMaster {
private WeatherConfig config;
private WeatherProvider provider;
private Mapper mapper = GlobalConstants.getMapper();
private Plugin plugin = GlobalConstants.getPlugin();
public WeatherMaster(WeatherConfig config) {
this.config = config;
@ -33,7 +36,10 @@ public class WeatherMaster {
provider.init();
// TODO start task
AsyncWeatherRetriever retriever = new AsyncWeatherRetriever(provider);
retriever.runTaskAsynchronously(plugin);
plugin.getServer().getPluginManager().registerEvents(retriever, plugin);
DebugLogger.info("weather loaded", 1);
}