Compare commits
No commits in common. "6c691ef0b45a2ffb699ce11045ee00658124f11e" and "aa100110bdd283b3b0d04ce9776c3f8854334b3e" have entirely different histories.
6c691ef0b4
...
aa100110bd
14 changed files with 96 additions and 346 deletions
15
pom.xml
15
pom.xml
|
@ -2,7 +2,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>eu.m724</groupId>
|
<groupId>eu.m724</groupId>
|
||||||
<artifactId>realweather</artifactId>
|
<artifactId>realweather</artifactId>
|
||||||
<version>0.9-alpha.2</version>
|
<version>0.9-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
|
@ -11,11 +11,6 @@
|
||||||
<jarsigner.alias>testkey</jarsigner.alias>
|
<jarsigner.alias>testkey</jarsigner.alias>
|
||||||
<jarsigner.storepass>123456</jarsigner.storepass>
|
<jarsigner.storepass>123456</jarsigner.storepass>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<scm>
|
|
||||||
<developerConnection>scm:git:git@git.724.rocks:Minecon724/realweather.git</developerConnection>
|
|
||||||
<tag>realweather-0.9a2</tag>
|
|
||||||
</scm>
|
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
@ -50,14 +45,6 @@
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<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>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
#release configuration
|
|
||||||
#Tue Jun 18 13:22:44 CEST 2024
|
|
||||||
completedPhase=check-poms
|
|
||||||
exec.pomFileName=pom.xml
|
|
||||||
exec.snapshotReleasePluginAllowed=false
|
|
||||||
pinExternals=false
|
|
||||||
preparationGoals=clean verify
|
|
||||||
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.tagNameFormat=@{project.artifactId}-@{project.version}
|
|
||||||
scm.url=scm\:git\:git@git.724.rocks\:Minecon724/realweather.git
|
|
|
@ -13,6 +13,6 @@ public class DebugLogger {
|
||||||
|
|
||||||
public static void info(String message, int minDebugLevel, Object... format) {
|
public static void info(String message, int minDebugLevel, Object... format) {
|
||||||
if (debugLevel >= minDebugLevel)
|
if (debugLevel >= minDebugLevel)
|
||||||
baseLogger.info(message.formatted(format));
|
baseLogger.info(String.format(message, format));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import eu.m724.realweather.mapper.MapperConfig;
|
||||||
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.updater.UpdaterConfig;
|
|
||||||
import eu.m724.realweather.weather.PlayerWeatherDirectory;
|
import eu.m724.realweather.weather.PlayerWeatherDirectory;
|
||||||
import eu.m724.realweather.weather.WeatherConfig;
|
import eu.m724.realweather.weather.WeatherConfig;
|
||||||
|
|
||||||
|
@ -16,7 +15,6 @@ public class GlobalConstants {
|
||||||
static TimeConfig timeConfig;
|
static TimeConfig timeConfig;
|
||||||
static ThunderConfig thunderConfig;
|
static ThunderConfig thunderConfig;
|
||||||
static MapperConfig mapperConfig;
|
static MapperConfig mapperConfig;
|
||||||
static UpdaterConfig updaterConfig;
|
|
||||||
|
|
||||||
static ThunderMaster thunderMaster;
|
static ThunderMaster thunderMaster;
|
||||||
|
|
||||||
|
@ -36,9 +34,6 @@ public class GlobalConstants {
|
||||||
public static MapperConfig getMapperConfig() {
|
public static MapperConfig getMapperConfig() {
|
||||||
return mapperConfig;
|
return mapperConfig;
|
||||||
}
|
}
|
||||||
public static UpdaterConfig getUpdaterConfig() {
|
|
||||||
return updaterConfig;
|
|
||||||
}
|
|
||||||
public static ThunderMaster getThunderMaster() {
|
public static ThunderMaster getThunderMaster() {
|
||||||
return thunderMaster;
|
return thunderMaster;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ 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.UpdateCommand;
|
|
||||||
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;
|
||||||
|
@ -24,7 +23,6 @@ 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.SignatureValidator;
|
||||||
import eu.m724.realweather.updater.Updater;
|
import eu.m724.realweather.updater.Updater;
|
||||||
import eu.m724.realweather.updater.UpdaterConfig;
|
|
||||||
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;
|
||||||
|
@ -33,7 +31,6 @@ public class RealWeatherPlugin extends JavaPlugin {
|
||||||
private WeatherMaster weatherMaster;
|
private WeatherMaster weatherMaster;
|
||||||
private ThunderMaster thunderMaster;
|
private ThunderMaster thunderMaster;
|
||||||
private TimeMaster timeMaster;
|
private TimeMaster timeMaster;
|
||||||
private Updater updater;
|
|
||||||
|
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
|
||||||
|
@ -115,10 +112,6 @@ public class RealWeatherPlugin extends JavaPlugin {
|
||||||
GlobalConstants.timeConfig = TimeConfig.fromConfiguration(timeConfiguration);
|
GlobalConstants.timeConfig = TimeConfig.fromConfiguration(timeConfiguration);
|
||||||
timeMaster = new TimeMaster(GlobalConstants.timeConfig);
|
timeMaster = new TimeMaster(GlobalConstants.timeConfig);
|
||||||
timeMaster.init();
|
timeMaster.init();
|
||||||
|
|
||||||
GlobalConstants.updaterConfig = UpdaterConfig.fromConfiguration(configuration.getConfigurationSection("updater"));
|
|
||||||
updater = new Updater(GlobalConstants.updaterConfig);
|
|
||||||
updater.init();
|
|
||||||
} catch (UserException e) {
|
} catch (UserException e) {
|
||||||
logger.severe("There are errors in your config:");
|
logger.severe("There are errors in your config:");
|
||||||
logger.severe(e.getMessage());
|
logger.severe(e.getMessage());
|
||||||
|
@ -139,12 +132,13 @@ public class RealWeatherPlugin extends JavaPlugin {
|
||||||
GlobalConstants.thunderMaster = thunderMaster;
|
GlobalConstants.thunderMaster = thunderMaster;
|
||||||
|
|
||||||
getCommand("rwadmin").setExecutor(new AdminCommand());
|
getCommand("rwadmin").setExecutor(new AdminCommand());
|
||||||
getCommand("rwadmin update").setExecutor(new UpdateCommand(updater));
|
|
||||||
getCommand("geo").setExecutor(new GeoCommand());
|
getCommand("geo").setExecutor(new GeoCommand());
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
package eu.m724.realweather.commands;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import eu.m724.realweather.updater.Updater;
|
|
||||||
import eu.m724.realweather.updater.metadata.VersionMetadata;
|
|
||||||
|
|
||||||
public class UpdateCommand implements CommandExecutor {
|
|
||||||
private Updater updater;
|
|
||||||
|
|
||||||
public UpdateCommand(Updater updater) {
|
|
||||||
this.updater = updater;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
||||||
sender.sendMessage("Please wait");
|
|
||||||
CompletableFuture<VersionMetadata> latestFuture = updater.getLatestVersion();
|
|
||||||
|
|
||||||
latestFuture.thenAccept(metadata -> {
|
|
||||||
if (metadata != null) {
|
|
||||||
sender.sendMessage("An update is available!");
|
|
||||||
sender.sendMessage("RealWeather %s released %s".formatted(metadata.label, metadata.getFormattedDate()));
|
|
||||||
sender.sendMessage("To download: /rwadmin update download");
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("No new updates"); // TODO color
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
package eu.m724.realweather.updater;
|
package eu.m724.realweather.updater;
|
||||||
|
|
||||||
import java.util.List;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.CompletionException;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
@ -10,25 +10,18 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import eu.m724.realweather.DebugLogger;
|
import eu.m724.realweather.DebugLogger;
|
||||||
import eu.m724.realweather.GlobalConstants;
|
import eu.m724.realweather.GlobalConstants;
|
||||||
import eu.m724.realweather.object.UserException;
|
|
||||||
import eu.m724.realweather.updater.metadata.MetadataRetriever;
|
|
||||||
import eu.m724.realweather.updater.metadata.MetadataServerException;
|
|
||||||
import eu.m724.realweather.updater.metadata.VersionMetadata;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
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 Updater extends BukkitRunnable implements Listener {
|
public class Updater extends BukkitRunnable implements Listener {
|
||||||
private UpdaterConfig updaterConfig;
|
|
||||||
private MetadataRetriever metadataRetriever;
|
|
||||||
|
|
||||||
private Plugin plugin = GlobalConstants.getPlugin();
|
private Plugin plugin = GlobalConstants.getPlugin();
|
||||||
|
private MetadataRetriever metadataRetriever = new MetadataRetriever(plugin);
|
||||||
|
|
||||||
private VersionMetadata currentMetadata;
|
private VersionMetadata availableUpdate = null;
|
||||||
private VersionMetadata latestMetadata;
|
|
||||||
private long checkCacheExpires;
|
|
||||||
|
|
||||||
private BaseComponent updateMessage = null;
|
private BaseComponent updateMessage = null;
|
||||||
private BaseComponent updateActionMessage =
|
private BaseComponent updateActionMessage =
|
||||||
|
@ -36,91 +29,19 @@ public class Updater extends BukkitRunnable implements Listener {
|
||||||
.append("/rwadmin update").color(ChatColor.AQUA)
|
.append("/rwadmin update").color(ChatColor.AQUA)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public Updater(UpdaterConfig updaterConfig) {
|
public void init() {
|
||||||
this.updaterConfig = updaterConfig;
|
this.runTaskTimerAsynchronously(plugin, 0, 216000); // 3h
|
||||||
this.metadataRetriever = new MetadataRetriever(plugin, updaterConfig.channel);
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
}
|
|
||||||
|
|
||||||
public void init() throws UserException {
|
|
||||||
try {
|
|
||||||
DebugLogger.info("probing for channels...", 1);
|
|
||||||
|
|
||||||
List<String> channels = metadataRetriever.getChannels().join();
|
|
||||||
if (!channels.contains(updaterConfig.channel)) {
|
|
||||||
throw new UserException(
|
|
||||||
"Invalid channel: %s. Valid ones are: %s"
|
|
||||||
.formatted(updaterConfig.channel, String.join(", ", channels))); // WHY DID NOBODY TELL ME ABOUT .formatted
|
|
||||||
}
|
|
||||||
|
|
||||||
currentMetadata = metadataRetriever.getCurrentVersionMetadata().join();
|
|
||||||
DebugLogger.info("current: %d", 1, currentMetadata.id);
|
|
||||||
} catch (CompletionException e) {
|
|
||||||
int statusCode = ((MetadataServerException) e.getCause()).getStatusCode();
|
|
||||||
if (statusCode >= 500) {
|
|
||||||
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);
|
|
||||||
} else {
|
|
||||||
DebugLogger.info("Update server returned unexpected status code! %d", 0, statusCode);
|
|
||||||
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);
|
|
||||||
} else {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updaterConfig.notify) {
|
|
||||||
this.runTaskTimerAsynchronously(plugin, 0, 216000); // 3h
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
|
||||||
DebugLogger.info("updater will notify", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
DebugLogger.info("updater loaded", 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean installUpdate() {
|
public boolean installUpdate() {
|
||||||
if (latestMetadata == null)
|
if (availableUpdate == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// TODO dont forget about verifictaion
|
// TODO dont forget about verifictaion
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<VersionMetadata> getLatestVersion() {
|
|
||||||
if (System.currentTimeMillis() < checkCacheExpires)
|
|
||||||
return CompletableFuture.completedFuture(latestMetadata);
|
|
||||||
else
|
|
||||||
return checkForNewVersion().handle((result, ex) -> null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* this can throw completionexception
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private CompletableFuture<VersionMetadata> checkForNewVersion() {
|
|
||||||
CompletableFuture<VersionMetadata> latestMetadataFuture =
|
|
||||||
metadataRetriever.getLatestVersionMetadata();
|
|
||||||
|
|
||||||
CompletableFuture<VersionMetadata> newMetadataFuture =
|
|
||||||
latestMetadataFuture.thenApply(latestMetadata -> {
|
|
||||||
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) {
|
|
||||||
this.latestMetadata = latestMetadata;
|
|
||||||
this.checkCacheExpires = System.currentTimeMillis() + 10800000;
|
|
||||||
return latestMetadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.checkCacheExpires = System.currentTimeMillis() + 3600000;
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
return newMetadataFuture;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
@ -136,22 +57,30 @@ public class Updater extends BukkitRunnable implements Listener {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
DebugLogger.info("Checking for update...", 2);
|
DebugLogger.info("Checking for update...", 2);
|
||||||
|
CompletableFuture<VersionMetadata> currentMetadataFuture =
|
||||||
|
metadataRetriever.getCurrentVersionMetadata();
|
||||||
|
|
||||||
|
CompletableFuture<VersionMetadata> latestMetadataFuture =
|
||||||
|
metadataRetriever.getLatestVersionMetadata();
|
||||||
|
|
||||||
CompletableFuture<VersionMetadata> newVersionFuture = checkForNewVersion();
|
VersionMetadata currentMetadata = currentMetadataFuture.join();
|
||||||
|
VersionMetadata latestMetadata = latestMetadataFuture.join();
|
||||||
|
|
||||||
try {
|
DebugLogger.info("Current version: %s (%d)", 2, currentMetadata.label, currentMetadata.id);
|
||||||
newVersionFuture.join();
|
DebugLogger.info("Latest version: %s (%d)", 2, latestMetadata.label, latestMetadata.id);
|
||||||
} catch (CompletionException e) {
|
|
||||||
int statusCode = ((MetadataServerException) e.getCause()).getStatusCode();
|
if (currentMetadata.id >= latestMetadata.id) return;
|
||||||
DebugLogger.info("Couldn't check for updates: %d", 0, statusCode);
|
|
||||||
}
|
availableUpdate = latestMetadata;
|
||||||
|
|
||||||
|
String formattedDate = new SimpleDateFormat("dd.MM").format(new Date(latestMetadata.timestamp));
|
||||||
|
|
||||||
updateMessage = new ComponentBuilder("An update is available!\n")
|
updateMessage = new ComponentBuilder("An update is available!\n")
|
||||||
.color(ChatColor.YELLOW)
|
.color(ChatColor.YELLOW)
|
||||||
.append("RealWeather ").color(ChatColor.GOLD)
|
.append("RealWeather ").color(ChatColor.GOLD)
|
||||||
.append(latestMetadata.label).color(ChatColor.AQUA).bold(true)
|
.append(latestMetadata.label).color(ChatColor.AQUA).bold(true)
|
||||||
.append(" released ").color(ChatColor.GOLD)
|
.append(" released ").color(ChatColor.GOLD)
|
||||||
.append(latestMetadata.getFormattedDate()).color(ChatColor.AQUA)
|
.append(formattedDate).color(ChatColor.AQUA)
|
||||||
.append("\nCurrent: ").color(ChatColor.GRAY)
|
.append("\nCurrent: ").color(ChatColor.GRAY)
|
||||||
.append(currentMetadata.label).color(ChatColor.DARK_AQUA)
|
.append(currentMetadata.label).color(ChatColor.DARK_AQUA)
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
package eu.m724.realweather.updater;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
|
|
||||||
public class UpdaterConfig {
|
|
||||||
public boolean notify;
|
|
||||||
public String channel;
|
|
||||||
|
|
||||||
public static UpdaterConfig fromConfiguration(ConfigurationSection configuration) {
|
|
||||||
UpdaterConfig updaterConfig = new UpdaterConfig();
|
|
||||||
|
|
||||||
updaterConfig.notify = configuration.getBoolean("notify");
|
|
||||||
updaterConfig.channel = configuration.getString("channel");
|
|
||||||
|
|
||||||
return updaterConfig;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,4 @@
|
||||||
package eu.m724.realweather.updater.metadata;
|
package eu.m724.realweather.updater;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class VersionMetadata {
|
public class VersionMetadata {
|
||||||
/**
|
/**
|
||||||
|
@ -29,10 +26,4 @@ public class VersionMetadata {
|
||||||
* filename of the jar file in the version directory
|
* filename of the jar file in the version directory
|
||||||
*/
|
*/
|
||||||
public String file;
|
public String file;
|
||||||
|
|
||||||
public String sha256;
|
|
||||||
|
|
||||||
public String getFormattedDate() {
|
|
||||||
return new SimpleDateFormat("dd.MM").format(new Date(timestamp));
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,107 +0,0 @@
|
||||||
package eu.m724.realweather.updater.metadata;
|
|
||||||
|
|
||||||
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.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.CompletionException;
|
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
|
|
||||||
public class MetadataRetriever {
|
|
||||||
private String version;
|
|
||||||
private String channel;
|
|
||||||
|
|
||||||
private CompletableFuture<VersionMetadata> currentMetadataCached = null;
|
|
||||||
|
|
||||||
public MetadataRetriever(Plugin plugin, String channel) {
|
|
||||||
this.version = plugin.getDescription().getVersion();
|
|
||||||
this.channel = channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the completablefuture can throw a completionexception with {@link eu.m724.realweather.updater.metadata.MetadataServerException}
|
|
||||||
*/
|
|
||||||
private CompletableFuture<VersionMetadata> getMetadataOf(String version) {
|
|
||||||
String url = String.format(
|
|
||||||
"https://git.724.rocks/Minecon724/realweather-metadata/raw/branch/master/data/%s/%s/%s",
|
|
||||||
channel, version, "meta-v1.json");
|
|
||||||
|
|
||||||
HttpRequest request = HttpRequest.newBuilder()
|
|
||||||
.uri(URI.create(url))
|
|
||||||
.header("User-Agent", "rwu/1") // real weather updater v1
|
|
||||||
.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)
|
|
||||||
throw new CompletionException(new MetadataServerException(response.statusCode()));
|
|
||||||
|
|
||||||
VersionMetadata versionMetadata = new Gson().fromJson(response.body(), VersionMetadata.class);
|
|
||||||
return versionMetadata;
|
|
||||||
});
|
|
||||||
|
|
||||||
return metadataFuture;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<List<String>> getChannels() {
|
|
||||||
String url = "https://git.724.rocks/Minecon724/realweather-metadata/raw/branch/master/data/channels.txt";
|
|
||||||
|
|
||||||
HttpRequest request = HttpRequest.newBuilder()
|
|
||||||
.uri(URI.create(url))
|
|
||||||
.header("User-Agent", "rwu/1") // real weather updater v1
|
|
||||||
.build();
|
|
||||||
|
|
||||||
CompletableFuture<HttpResponse<String>> responseFuture =
|
|
||||||
HttpClient.newBuilder()
|
|
||||||
.followRedirects(Redirect.NORMAL)
|
|
||||||
.proxy(ProxySelector.getDefault()).build().
|
|
||||||
sendAsync(request, BodyHandlers.ofString());
|
|
||||||
|
|
||||||
CompletableFuture<List<String>> channelsFuture =
|
|
||||||
responseFuture.thenApply(response -> {
|
|
||||||
if (response.statusCode() != 200)
|
|
||||||
throw new CompletionException(new MetadataServerException(response.statusCode()));
|
|
||||||
|
|
||||||
return response.body().lines().toList();
|
|
||||||
});
|
|
||||||
|
|
||||||
return channelsFuture; // TODO remove repeated code?
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the {@link CompletableFuture} can throw a {@link CompletionException} with {@link MetadataServerException}
|
|
||||||
*/
|
|
||||||
public CompletableFuture<VersionMetadata> getLatestVersionMetadata() {
|
|
||||||
return getVersionMetadata("latest");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the completablefuture can throw a completionexception with {@link MetadataServerException}
|
|
||||||
*/
|
|
||||||
public CompletableFuture<VersionMetadata> getCurrentVersionMetadata() {
|
|
||||||
if (currentMetadataCached == null)
|
|
||||||
currentMetadataCached = getVersionMetadata(version);
|
|
||||||
return currentMetadataCached; // TODO reconsider this
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the completablefuture can throw a completionexception with {@link MetadataServerException}
|
|
||||||
*/
|
|
||||||
public CompletableFuture<VersionMetadata> getVersionMetadata(String version) {
|
|
||||||
return getMetadataOf(version); // TODO remove this and rename that function?
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package eu.m724.realweather.updater.metadata;
|
|
||||||
|
|
||||||
public class MetadataServerException extends Exception {
|
|
||||||
private int statusCode;
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -782470406494196579L;
|
|
||||||
|
|
||||||
public MetadataServerException(int statusCode) {
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStatusCode() {
|
|
||||||
return statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -6,14 +6,9 @@
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
updater:
|
updater:
|
||||||
# Notify players and console about plugin updates
|
# notify players about plugin updates
|
||||||
# This also controls automatic checking
|
# revelant permission node: realweather.update.notify
|
||||||
# You can still update with /rwadmin update
|
|
||||||
# Revelant permission node: realweather.update.notify
|
|
||||||
notify: true
|
notify: true
|
||||||
# stable for stable releases
|
|
||||||
# testing for latest builds (untested hence the name)
|
|
||||||
channel: testing
|
|
||||||
|
|
||||||
# 0 - no debug
|
# 0 - no debug
|
||||||
# 1 - debug loading modules
|
# 1 - debug loading modules
|
||||||
|
|
|
@ -16,15 +16,12 @@ commands:
|
||||||
description: RealWeather admin command
|
description: RealWeather admin command
|
||||||
permission: realweather.admin
|
permission: realweather.admin
|
||||||
permission-message: You do not have permission to use this command.
|
permission-message: You do not have permission to use this command.
|
||||||
rwadmin update:
|
# usage is processed in code
|
||||||
description: Update RealWeather
|
|
||||||
permission: realweather.admin.update
|
|
||||||
permission-message: You do not have permission to use this command.
|
|
||||||
|
|
||||||
geo:
|
geo:
|
||||||
description: Convert lat,lon to x,y,z and vice versa
|
description: Convert lat,lon to x,y,z and vice versa
|
||||||
permission: realweather.command.geo
|
permission: realweather.command.geo
|
||||||
permission-message: You do not have permission to use this command.
|
permission-message: You do not have permission to use this command.
|
||||||
|
# usage is processed in code
|
||||||
localtime:
|
localtime:
|
||||||
description: Get real time in current location
|
description: Get real time in current location
|
||||||
permission: realweather.command.localtime
|
permission: realweather.command.localtime
|
||||||
|
@ -35,8 +32,6 @@ permissions:
|
||||||
|
|
||||||
realweather.admin:
|
realweather.admin:
|
||||||
description: Allows admin management with /rwadmin
|
description: Allows admin management with /rwadmin
|
||||||
realweather.admin.update:
|
|
||||||
description: Allows installing updates with /rwadmin update
|
|
||||||
|
|
||||||
realweather.command.geo:
|
realweather.command.geo:
|
||||||
description: Allows /geo
|
description: Allows /geo
|
||||||
|
|
Loading…
Reference in a new issue