Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new download API and jar file checksum #99

Merged
merged 9 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.projectg</groupId>
<name>GeyserUpdater</name>
<artifactId>GeyserUpdater</artifactId>
<version>1.6.2</version>
<version>1.6.3</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -70,6 +70,13 @@
<version>2.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
20 changes: 8 additions & 12 deletions src/main/java/com/projectg/geyserupdater/bungee/BungeeUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,17 @@ public void onDisable() {
try {
deleteGeyserJar();
break;
} catch (IOException ioException) {
logger.warn("An I/O error occurred while attempting to delete an unnecessary Geyser jar! Trying again " + (2 - i) + " more times.");
ioException.printStackTrace();
} catch (Exception e) {
logger.warn("An error occurred while attempting to delete an unnecessary Geyser jar! Trying again " + (2 - i) + " more times.");
try {
Thread.sleep(50);
} catch (InterruptedException interruptException) {
logger.error("Failed to delay an additional attempt!");
interruptException.printStackTrace();
} catch (InterruptedException interruptedException) {
logger.error("Failed to delay an additional attempt!", interruptedException);
}
}
}
} catch (IOException e) {
logger.error("An I/O error occurred while attempting to replace the current Geyser jar with the new one!");
e.printStackTrace();
} catch (Exception e) {
logger.error("An error occurred while attempting to replace the current Geyser jar with the new one! Giving up.", e);
}
}

Expand Down Expand Up @@ -157,9 +154,8 @@ public void scheduleAutoUpdate() {
logger.info("A newer build of Geyser is available! Attempting to download the latest build now...");
GeyserBungeeDownloader.updateGeyser();
}
} catch (IOException e) {
logger.error("Failed to check for updates to Geyser! We were unable to reach the Geyser build server, or your local branch does not exist on it.");
e.printStackTrace();
} catch (Exception e) {
logger.error("Failed to check for updates to Geyser! We were unable to reach the Geyser build server, or your local branch does not exist on it.", e);
}
}, 1, getConfig().getLong("Auto-Update-Interval", 24L) * 60, TimeUnit.MINUTES);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.projectg.geyserupdater.bungee.command;

import com.projectg.geyserupdater.bungee.util.GeyserBungeeDownloader;
import com.projectg.geyserupdater.common.Messages;
import com.projectg.geyserupdater.common.logger.UpdaterLogger;
import com.projectg.geyserupdater.common.util.Constants;
import com.projectg.geyserupdater.common.util.GeyserProperties;

import net.md_5.bungee.api.ChatColor;
Expand All @@ -11,9 +11,6 @@
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;

import java.io.IOException;


public class GeyserUpdateCommand extends Command {

public GeyserUpdateCommand() {
Expand All @@ -25,33 +22,31 @@ public void execute(CommandSender commandSender, String[] args) {

if (commandSender instanceof ProxiedPlayer player) {
try {
player.sendMessage(new TextComponent(ChatColor.GOLD + "[GeyserUpdater] " + Messages.Command.CHECK_START));
player.sendMessage(new TextComponent(ChatColor.GOLD + "[GeyserUpdater] " + Constants.CHECK_START));
boolean isLatest = GeyserProperties.isLatestBuild();
if (isLatest) {
player.sendMessage(new TextComponent(ChatColor.GOLD + "[GeyserUpdater] " + Messages.Command.LATEST));
player.sendMessage(new TextComponent(ChatColor.GOLD + "[GeyserUpdater] " + Constants.LATEST));
} else {
player.sendMessage(new TextComponent(ChatColor.GOLD + "[GeyserUpdater] " + Messages.Command.OUTDATED));
player.sendMessage(new TextComponent(ChatColor.GOLD + "[GeyserUpdater] " + Constants.OUTDATED));
GeyserBungeeDownloader.updateGeyser();
}
} catch (IOException e) {
player.sendMessage(new TextComponent(ChatColor.RED + "[GeyserUpdater] " + Messages.Command.FAIL_CHECK));
logger.error(Messages.Command.FAIL_CHECK);
e.printStackTrace();
} catch (Exception e) {
player.sendMessage(new TextComponent(ChatColor.RED + "[GeyserUpdater] " + Constants.FAIL_CHECK));
logger.error(Constants.FAIL_CHECK, e);
}
} else {
// TODO: filter this against command blocks
try {
logger.info(Messages.Command.CHECK_START);
logger.info(Constants.CHECK_START);
boolean isLatest = GeyserProperties.isLatestBuild();
if (isLatest) {
logger.info(Messages.Command.LATEST);
logger.info(Constants.LATEST);
} else {
logger.info(Messages.Command.OUTDATED);
logger.info(Constants.OUTDATED);
GeyserBungeeDownloader.updateGeyser();
}
} catch (IOException e) {
logger.error(Messages.Command.FAIL_CHECK);
e.printStackTrace();
} catch (Exception e) {
logger.error(Constants.FAIL_CHECK, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import com.projectg.geyserupdater.bungee.BungeeUpdater;
import com.projectg.geyserupdater.common.logger.UpdaterLogger;
import com.projectg.geyserupdater.common.util.Constants;
import com.projectg.geyserupdater.common.util.FileUtils;
import com.projectg.geyserupdater.common.util.GeyserProperties;

import com.projectg.geyserupdater.common.util.GeyserDownloadApi;
import com.projectg.geyserupdater.common.util.ServerPlatform;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class GeyserBungeeDownloader {
Expand Down Expand Up @@ -58,20 +59,14 @@ public static void updateGeyser() {
* @return true if the download was successful, false if not.
*/
private static boolean downloadGeyser() {
String fileUrl;
try {
fileUrl = "https://ci.opencollab.dev/job/GeyserMC/job/Geyser/job/" + GeyserProperties.getGeyserGitPropertiesValue("git.branch") + "/lastSuccessfulBuild/artifact/bootstrap/bungeecord/build/libs/Geyser-BungeeCord.jar";
} catch (IOException e) {
logger.error("Failed to get the current Geyser branch when attempting to download a new build of Geyser!");
e.printStackTrace();
return false;
}
String fileUrl = Constants.GEYSER_BASE_URL + Constants.GEYSER_DOWNLOAD_LINK + ServerPlatform.BUNGEECORD.getUrlComponent();
String outputPath = "plugins/GeyserUpdater/BuildUpdate/Geyser-BungeeCord.jar";
try {
FileUtils.downloadFile(fileUrl, outputPath);
} catch (IOException e) {
logger.error("Failed to download the newest build of Geyser");
e.printStackTrace();
String expectedHash = new GeyserDownloadApi().data().downloads().bungeecord().sha256();
FileUtils.downloadFile(fileUrl, outputPath, expectedHash);
} catch (Exception e) {
logger.error("Failed to download the newest build of Geyser" + e.getMessage());
logger.debug("Stack trace: " + e);
return false;
}

Expand Down
15 changes: 0 additions & 15 deletions src/main/java/com/projectg/geyserupdater/common/Messages.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.projectg.geyserupdater.common.json_schema;

import lombok.Getter;
import lombok.experimental.Accessors;

import java.util.Date;
import java.util.List;

@SuppressWarnings({"UnusedDeclaration"})
@Getter
@Accessors(fluent = true)
public class EndpointResponse {
private String project_id;
private String project_name;
private String version;
private int build;
private Date time;
private String channel;
private boolean promoted;
private List<Change> changes;
private Downloads downloads;

@Getter
public static class Bungeecord {
private String name;
private String sha256;
}

@Getter
public static class Change {
private String commit;
private String summary;
private String message;
}

@Getter
public static class Downloads {
private Bungeecord bungeecord;
private Fabric fabric;
private Spigot spigot;
private Sponge sponge;
private Standalone standalone;
private Velocity velocity;
}

@Getter
public static class Fabric {
private String name;
private String sha256;
}

@Getter
public static class Spigot {
private String name;
private String sha256;
}

@Getter
public static class Sponge {
private String name;
private String sha256;
}

@Getter
public static class Standalone {
private String name;
private String sha256;
}

@Getter
public static class Velocity {
private String name;
private String sha256;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ static UpdaterLogger getLogger() {
*/
void error(String message);

/**
* Logs an error message to the console.
*
* @param message the message to log to the console
*/
default void error(String message, Throwable throwable) {
error(message);
throwable.printStackTrace();
}

/**
* Logs a warning message to the console.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.projectg.geyserupdater.common.util;

public class Constants {
public static final String GEYSER_BASE_URL = "https://download.geysermc.org";
public static final String GEYSER_LATEST_MASTER_ENDPOINT = "/v2/projects/geyser/versions/latest/builds/latest";
public static final String GEYSER_DOWNLOAD_LINK = "/v2/projects/geyser/versions/latest/builds/latest/downloads/";
public static final String CHECK_START = "Checking for updates to Geyser...";
public static final String LATEST = "You are using the latest build of Geyser!";
public static final String OUTDATED = "A newer build of Geyser is available! Attempting to download the latest build now...";
public static final String FAIL_CHECK = "Failed to check for updates to Geyser! We were unable to reach the Geyser build server, or your local branch does not exist on it.";
}
Loading
Loading