Compare commits

..

No commits in common. "aa100110bdd283b3b0d04ce9776c3f8854334b3e" and "975fdc80f2ad56140b6313af86d3ea9015ba4414" have entirely different histories.

9 changed files with 10 additions and 205 deletions

View file

@ -1,11 +1,9 @@
If you're using a firewall, you must allow the following hosts: If you're using a firewall, you must allow the following hosts:
- updater: - core functionality:
* git.724.rocks * rw-api.m724.eu
- weather: - weather:
* api.openweathermap.org * api.openweathermap.org
- thunder: - thunder:
* ws1.blitzortung.org * ws1.blitzortung.org
* ws7.blitzortung.org * ws7.blitzortung.org
* ws8.blitzortung.org * ws8.blitzortung.org
Subject to change!

View file

@ -29,12 +29,7 @@ TODO (no order):
### Building ### Building
To compile, clone this repo and `mvn clean package`. \ To compile, clone this repo and `mvn clean package`. \
JAR will be in `target/`. Use the one without `original-`. \ JAR will be in `target/`. Use the one without `original-`.
By default, it's signed with the test key.
#### Signing ### Versioning
A test (and default) keystore is provided: Basically, 0.9.x are prereleases
- keystore: `testkeystore`
- storepass: `123456`
- alias: `testkey`
You can override this by using `-Djarsigner.` arguments while compiling.

View file

@ -59,7 +59,7 @@
<artifactSet> <artifactSet>
<includes> <includes>
<include>eu.m724:wtapi</include> <include>eu.m724:wtapi</include>
<!-- <include>org.java-websocket:Java-WebSocket</include> --> <include>org.java-websocket:Java-WebSocket</include>
</includes> </includes>
</artifactSet> </artifactSet>
<filters> <filters>

View file

@ -17,12 +17,11 @@ import eu.m724.realweather.commands.LocalTimeCommand;
import eu.m724.realweather.mapper.Mapper; import eu.m724.realweather.mapper.Mapper;
import eu.m724.realweather.mapper.MapperConfig; import eu.m724.realweather.mapper.MapperConfig;
import eu.m724.realweather.object.UserException; import eu.m724.realweather.object.UserException;
import eu.m724.realweather.sign.SignatureValidator;
import eu.m724.realweather.thunder.ThunderConfig; import eu.m724.realweather.thunder.ThunderConfig;
import eu.m724.realweather.thunder.ThunderMaster; import eu.m724.realweather.thunder.ThunderMaster;
import eu.m724.realweather.time.TimeConfig; import eu.m724.realweather.time.TimeConfig;
import eu.m724.realweather.time.TimeMaster; import eu.m724.realweather.time.TimeMaster;
import eu.m724.realweather.updater.SignatureValidator;
import eu.m724.realweather.updater.Updater;
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.ProviderException; import eu.m724.wtapi.provider.exception.ProviderException;
@ -136,8 +135,6 @@ public class RealWeatherPlugin extends JavaPlugin {
if (GlobalConstants.timeConfig.enabled) if (GlobalConstants.timeConfig.enabled)
getCommand("localtime").setExecutor(new LocalTimeCommand()); getCommand("localtime").setExecutor(new LocalTimeCommand());
new Updater().init();
DebugLogger.info("ended loading", 1); DebugLogger.info("ended loading", 1);
} }

View file

@ -1,4 +1,4 @@
package eu.m724.realweather.updater; package eu.m724.realweather.sign;
import java.security.KeyFactory; import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;

View file

@ -1,62 +0,0 @@
package eu.m724.realweather.updater;
import java.net.ProxySelector;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpClient.Redirect;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.concurrent.CompletableFuture;
import org.bukkit.plugin.Plugin;
import com.google.gson.Gson;
public class MetadataRetriever {
private String version;
private CompletableFuture<VersionMetadata> currentMetadataCached = null;
public MetadataRetriever(Plugin plugin) {
this.version = plugin.getDescription().getVersion();
}
private CompletableFuture<VersionMetadata> getMetadataFromUrl(String url) {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("User-Agent", "rwu/1")
.build();
CompletableFuture<HttpResponse<String>> responseFuture =
HttpClient.newBuilder()
.followRedirects(Redirect.NORMAL)
.proxy(ProxySelector.getDefault()).build().
sendAsync(request, BodyHandlers.ofString());
CompletableFuture<VersionMetadata> metadataFuture =
responseFuture.thenApply(response -> {
if (response.statusCode() != 200)
return null;
VersionMetadata versionMetadata = new Gson().fromJson(response.body(), VersionMetadata.class);
return versionMetadata;
});
return metadataFuture;
}
public CompletableFuture<VersionMetadata> getLatestVersionMetadata() {
return getMetadataFromUrl("https://git.724.rocks/Minecon724/realweather-metadata/raw/branch/master/latest/latest-v1.json");
}
public CompletableFuture<VersionMetadata> getCurrentVersionMetadata() {
if (currentMetadataCached != null)
currentMetadataCached = getVersionMetadata(version);
return currentMetadataCached;
}
public CompletableFuture<VersionMetadata> getVersionMetadata(String version) {
return getMetadataFromUrl("https://git.724.rocks/Minecon724/realweather-metadata/raw/branch/master/releases/" + version + "/meta-v1.json");
}
}

View file

@ -1,91 +0,0 @@
package eu.m724.realweather.updater;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.CompletableFuture;
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;
import eu.m724.realweather.DebugLogger;
import eu.m724.realweather.GlobalConstants;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
public class Updater extends BukkitRunnable implements Listener {
private Plugin plugin = GlobalConstants.getPlugin();
private MetadataRetriever metadataRetriever = new MetadataRetriever(plugin);
private VersionMetadata availableUpdate = null;
private BaseComponent updateMessage = null;
private BaseComponent updateActionMessage =
new ComponentBuilder("To update: ").color(ChatColor.YELLOW)
.append("/rwadmin update").color(ChatColor.AQUA)
.build();
public void init() {
this.runTaskTimerAsynchronously(plugin, 0, 216000); // 3h
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
public boolean installUpdate() {
if (availableUpdate == null)
return false;
// TODO dont forget about verifictaion
return true;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (!player.hasPermission("realweather.update.notify")) return;
if (updateMessage != null) { // TODO make changelog somewhere
player.spigot().sendMessage(updateMessage);
if (player.hasPermission("realweather.admin"))
player.spigot().sendMessage(updateActionMessage);
}
}
@Override
public void run() {
DebugLogger.info("Checking for update...", 2);
CompletableFuture<VersionMetadata> currentMetadataFuture =
metadataRetriever.getCurrentVersionMetadata();
CompletableFuture<VersionMetadata> latestMetadataFuture =
metadataRetriever.getLatestVersionMetadata();
VersionMetadata currentMetadata = currentMetadataFuture.join();
VersionMetadata latestMetadata = latestMetadataFuture.join();
DebugLogger.info("Current version: %s (%d)", 2, currentMetadata.label, currentMetadata.id);
DebugLogger.info("Latest version: %s (%d)", 2, latestMetadata.label, latestMetadata.id);
if (currentMetadata.id >= latestMetadata.id) return;
availableUpdate = latestMetadata;
String formattedDate = new SimpleDateFormat("dd.MM").format(new Date(latestMetadata.timestamp));
updateMessage = new ComponentBuilder("An update is available!\n")
.color(ChatColor.YELLOW)
.append("RealWeather ").color(ChatColor.GOLD)
.append(latestMetadata.label).color(ChatColor.AQUA).bold(true)
.append(" released ").color(ChatColor.GOLD)
.append(formattedDate).color(ChatColor.AQUA)
.append("\nCurrent: ").color(ChatColor.GRAY)
.append(currentMetadata.label).color(ChatColor.DARK_AQUA)
.build();
DebugLogger.info(updateMessage.toString(), 0);
DebugLogger.info(updateActionMessage.toString(), 0);
}
}

View file

@ -1,29 +0,0 @@
package eu.m724.realweather.updater;
public class VersionMetadata {
/**
* metadata file version
*/
public final int spec = 1;
/**
* version id. increments with each version
*/
public int id;
/**
* release time of a version
*/
public long timestamp;
/**
* label aka version string
* example: 1.0.0
*/
public String label;
/**
* filename of the jar file in the version directory
*/
public String file;
}

View file

@ -4,13 +4,10 @@ version: ${project.version}
author: Minecon724 author: Minecon724
website: https://forum.m724.eu/topic/3/realweather-1-0 website: https://forum.m724.eu/topic/3/realweather-1-0
api-version: 1.21 api-version: 1.20
load: STARTUP load: STARTUP
main: eu.m724.realweather.RealWeatherPlugin main: eu.m724.realweather.RealWeatherPlugin
libraries:
- org.java-websocket:Java-WebSocket:1.5.6
commands: commands:
rwadmin: rwadmin:
description: RealWeather admin command description: RealWeather admin command