new command

This commit is contained in:
Minecon724 2024-06-27 16:31:36 +02:00
parent ef498f1f01
commit 572788d5bf
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
8 changed files with 86 additions and 213 deletions

View file

@ -1,136 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.m724</groupId>
<artifactId>realweather</artifactId>
<version>0.9.5-SNAPSHOT</version>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<jarsigner.keystore>${project.basedir}/testkeystore</jarsigner.keystore>
<jarsigner.alias>testkey</jarsigner.alias>
<jarsigner.storepass>123456</jarsigner.storepass>
</properties>
<scm>
<developerConnection>scm:git:git@git.724.rocks:Minecon724/realweather.git</developerConnection>
<tag>HEAD</tag>
</scm>
<distributionManagement>
<repository>
<id>724rocks</id>
<url>https://git.724.rocks/api/packages/Minecon724/maven</url>
</repository>
<snapshotRepository>
<id>724rocks</id>
<url>https://git.724.rocks/api/packages/Minecon724/maven</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>724rocks</id>
<url>https://git.724.rocks/api/packages/Minecon724/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>eu.m724</groupId>
<artifactId>wtapi</artifactId>
<version>0.7</version>
</dependency>
<dependency>
<groupId>eu.m724</groupId>
<artifactId>jarupdater</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<allowTimestampedSnapshots>true</allowTimestampedSnapshots>
</configuration>
</plugin>
<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>eu.m724:jarupdater</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>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>sign</id>
<goals>
<goal>sign</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>${jarsigner.keystore}</keystore>
<alias>${jarsigner.alias}</alias>
<storepass>${jarsigner.storepass}</storepass>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -1,24 +0,0 @@
#release configuration
#Wed Jun 26 15:17:02 CEST 2024
completedPhase=end-release
exec.pomFileName=pom.xml
exec.snapshotReleasePluginAllowed=false
pinExternals=false
preparationGoals=clean verify
project.dev.eu.m724\:realweather=0.9.6-SNAPSHOT
project.rel.eu.m724\:realweather=0.9.5
project.scm.eu.m724\:realweather.developerConnection=scm\:git\:git@git.724.rocks\:Minecon724/realweather.git
project.scm.eu.m724\:realweather.tag=HEAD
projectVersionPolicyConfig=<projectVersionPolicyConfig>${projectVersionPolicyConfig}</projectVersionPolicyConfig>\n
projectVersionPolicyId=default
pushChanges=true
releaseStrategyId=default
remoteTagging=true
scm.branchCommitComment=@{prefix} prepare branch @{releaseLabel}
scm.commentPrefix=[maven-release-plugin]
scm.developmentCommitComment=@{prefix} prepare for next development iteration
scm.releaseCommitComment=@{prefix} prepare release @{releaseLabel}
scm.rollbackCommitComment=@{prefix} rollback the release of @{releaseLabel}
scm.tag=realweather-0.9.5
scm.tagNameFormat=@{project.artifactId}-@{project.version}
scm.url=scm\:git\:git@git.724.rocks\:Minecon724/realweather.git

View file

@ -14,6 +14,7 @@ import com.google.common.base.Charsets;
import eu.m724.realweather.commands.AdminCommand; import eu.m724.realweather.commands.AdminCommand;
import eu.m724.realweather.commands.GeoCommand; import eu.m724.realweather.commands.GeoCommand;
import eu.m724.realweather.commands.LocalTimeCommand; import eu.m724.realweather.commands.LocalTimeCommand;
import eu.m724.realweather.commands.LocalWeatherCommand;
import eu.m724.realweather.exception.UserError; import eu.m724.realweather.exception.UserError;
import eu.m724.realweather.mapper.Mapper; import eu.m724.realweather.mapper.Mapper;
import eu.m724.realweather.mapper.MapperConfig; import eu.m724.realweather.mapper.MapperConfig;
@ -134,6 +135,9 @@ public class RealWeatherPlugin extends JavaPlugin {
if (GlobalConstants.timeConfig.enabled) if (GlobalConstants.timeConfig.enabled)
getCommand("localtime").setExecutor(new LocalTimeCommand()); getCommand("localtime").setExecutor(new LocalTimeCommand());
if (GlobalConstants.weatherConfig.enabled)
getCommand("localweather").setExecutor(new LocalWeatherCommand());
DebugLogger.info("ended loading", 1); DebugLogger.info("ended loading", 1);
} }

View file

@ -0,0 +1,62 @@
package eu.m724.realweather.commands;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import eu.m724.realweather.GlobalConstants;
import eu.m724.realweather.weather.PlayerWeatherDirectory;
import eu.m724.wtapi.object.Weather;
public class LocalWeatherCommand implements CommandExecutor {
private PlayerWeatherDirectory playerWeatherDirectory = GlobalConstants.getPlayerWeatherDirectory();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("You must be a player to use this command");
return true;
}
Player player = (Player) sender;
Weather weather = playerWeatherDirectory.getWeather(player);
long lastUpdate = playerWeatherDirectory.getLastUpdate(player);
if (weather != null) {
player.sendMessage(weather.description);
if (weather.rainSeverity != null)
player.sendMessage("Rain: %s".formatted(weather.rainSeverity.toString()));
if (weather.drizzleSeverity != null)
player.sendMessage("Drizzle: %s".formatted(weather.drizzleSeverity.toString()));
if (weather.sleetSeverity != null)
player.sendMessage("Sleet: %s".formatted(weather.sleetSeverity.toString()));
if (weather.snowSeverity != null)
player.sendMessage("Snow: %s".formatted(weather.snowSeverity.toString()));
if (weather.thunderstormSeverity != null)
player.sendMessage("Thunderstorm: %s".formatted(weather.thunderstormSeverity.toString()));
if (weather.shower)
player.sendMessage("Shower: yes");
player.sendMessage("Cloudiness: %d%%".formatted(weather.cloudiness * 100));
player.sendMessage("Humidity: %d%%".formatted(weather.humidity * 100));
player.sendMessage("Temperature: %f (feels like %f) K".formatted(weather.temperature - 273.15, weather.temperatureApparent - 273.15));
player.sendMessage("Wind: %f (gust %f) m/s".formatted(weather.windSpeed, weather.windGust));
player.sendMessage("Last update: %s UTC".formatted(formatTime(lastUpdate)));
} else {
player.sendMessage("No weather for you");
}
return true;
}
private String formatTime(long timestamp) { // TODO move this
return DateTimeFormatter.ofPattern("HH:mm:ss").format(Instant.ofEpochSecond(timestamp));
}
}

View file

@ -37,6 +37,7 @@ public class AsyncWeatherRetriever extends BukkitRunnable implements Listener {
@Override @Override
public void run() { public void run() {
DebugLogger.info("Weather retrieval", 3); DebugLogger.info("Weather retrieval", 3);
long now = System.currentTimeMillis();
long delay = 6000; long delay = 6000;
if (dynamic) { if (dynamic) {
@ -65,7 +66,7 @@ public class AsyncWeatherRetriever extends BukkitRunnable implements Listener {
Player player = players.get(i); Player player = players.get(i);
Weather weather = weathers[i]; Weather weather = weathers[i];
playerWeatherDirectory.weathers.put(player, weather); playerWeatherDirectory.put(player, weather, now);
AsyncWeatherUpdateEvent event = AsyncWeatherUpdateEvent event =
new AsyncWeatherUpdateEvent(player, weather); new AsyncWeatherUpdateEvent(player, weather);
@ -116,7 +117,7 @@ public class AsyncWeatherRetriever extends BukkitRunnable implements Listener {
DebugLogger.info("A player joined so I requested weather", 3); DebugLogger.info("A player joined so I requested weather", 3);
weatherFuture.thenAccept(weather -> { weatherFuture.thenAccept(weather -> {
playerWeatherDirectory.weathers.put(player, weather); playerWeatherDirectory.put(player, weather, System.currentTimeMillis());
AsyncWeatherUpdateEvent weatherEvent = AsyncWeatherUpdateEvent weatherEvent =
new AsyncWeatherUpdateEvent(player, weather); new AsyncWeatherUpdateEvent(player, weather);

View file

@ -1,51 +0,0 @@
package eu.m724.realweather.weather;
import java.util.List;
import org.bukkit.WeatherType;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import eu.m724.realweather.DebugLogger;
import eu.m724.wtapi.object.Weather;
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;
public DynamicWeatherApplier(List<Player> players, Weather[] weathers) {
this.players = players;
this.weathers = weathers;
}
@Override
public void run() {
DebugLogger.info("applying weather for %d players", 2, players.size());
for (int i=0; i<players.size(); i++) {
Player player = players.get(i);
Weather weather = weathers[i];
if (player.hasPermission("realweather.actionbar")) {
String text = String.format("%f %f (%s) - %s",
weather.coordinates.latitude, weather.coordinates.longitude,
weather.coordinates.getAddress(), weather.description);
BaseComponent component = TextComponent.fromLegacy(text);
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, component);
DebugLogger.info("%s has actionbar permission so they received status", 2, player.getName());
}
if (weather.isRaining()) {
player.setPlayerWeather(WeatherType.DOWNFALL);
} else {
player.setPlayerWeather(WeatherType.CLEAR);
}
}
}
}

View file

@ -8,8 +8,18 @@ import eu.m724.wtapi.object.Weather;
public class PlayerWeatherDirectory { public class PlayerWeatherDirectory {
HashMap<Player, Weather> weathers = new HashMap<>(); HashMap<Player, Weather> weathers = new HashMap<>();
HashMap<Player, Long> lastUpdates = new HashMap<>();
void put(Player player, Weather weather, Long lastUpdate) {
weathers.put(player, weather);
lastUpdates.put(player, lastUpdate);
}
public Weather getWeather(Player player) { public Weather getWeather(Player player) {
return weathers.get(player); // TODO concurrent exception? return weathers.get(player); // TODO concurrent exception?
} }
public Long getLastUpdate(Player player) {
return lastUpdates.get(player); // TODO concurrent exception?
}
} }

View file

@ -25,6 +25,10 @@ commands:
description: Get real time in current location description: Get real time in current location
permission: realweather.command.localtime permission: realweather.command.localtime
permission-message: You do not have permission to use this command. permission-message: You do not have permission to use this command.
localweather:
description: Get weather in current location
permission: realweather.command.localweather
permission-message: You do not have permission to use this command.
permissions: permissions:
# Commands # Commands
@ -42,6 +46,9 @@ permissions:
realweather.command.localtime: realweather.command.localtime:
description: Allows /localtime description: Allows /localtime
default: true default: true
realweather.command.localweather:
description: Allows /localweather
default: true
# Engine # Engine