Skip to content

Commit

Permalink
Change Magma updater to use GitHub releases
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Nov 22, 2023
1 parent 43e0b1f commit 7a7c954
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ext {

GIT_INFO = gradleutils.gitInfo
FORGE_VERSION = '40.2.10'
MAGMA_VERSION = "1.18.2-$FORGE_VERSION-" + versioning.info.commit.substring(0, 8) // Use 8 characters for the commit hash
MAGMA_VERSION = "1.18.2-$FORGE_VERSION-" + versioning.info.commit.substring(0, 7) // Use 8 characters for the commit hash
VERSION = "1.18.2-$FORGE_VERSION"

SPECIAL_SOURCE = 'net.md-5:SpecialSource:1.10.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ public class MagmaUpdater {
private String newSha;
private String currentSha;

private String versionURL = "http://64.58.124.27:25565/1.18.2";
private String versionURL = "https://api.github.com/repos/magmamaintained/Magma-1.18.2/releases/latest";
private String assetURL;

public boolean versionChecker() {
try {
URL url = new URL(versionURL + "/latest");
URL url = new URL(versionURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.addRequestProperty("User-Agent", "Magma");

BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
JsonObject root = gson.fromJson(reader, JsonObject.class);

newSha = root.get("version").getAsString();
newSha = root.get("tag_name").getAsString();
assetURL = root.get("assets").getAsJsonObject().get("browser_download_url").getAsString();
currentSha = MagmaConstants.VERSION.split("-")[1];

if(currentSha.equals(newSha)) {
Expand All @@ -62,12 +64,11 @@ public boolean versionChecker() {
}

public void downloadJar() {
String url = versionURL + "/download";
try {
Path path = Paths.get(MagmaUpdater.class.getProtectionDomain().getCodeSource().getLocation().toURI());
System.out.println("[Magma] Updating Magma Jar ...");
System.out.println("[Magma] Downloading " + url + " ...");
URL website = new URL(url);
System.out.println("[Magma] Downloading " + assetURL + " ...");
URL website = new URL(assetURL);
HttpURLConnection connection = (HttpURLConnection) website.openConnection();
connection.setRequestMethod("GET");
connection.addRequestProperty("User-Agent", "Magma");
Expand Down

0 comments on commit 7a7c954

Please sign in to comment.