3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-07-09 12:08:02 +02:00

Update version (checking) for semver

Dieser Commit ist enthalten in:
dordsor21 2021-12-20 21:18:26 +00:00
Ursprung d6e3c331d4
Commit e9d97fc7b1
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
3 geänderte Dateien mit 53 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -1,5 +1,9 @@
package com.fastasyncworldedit.core;
import com.fastasyncworldedit.core.util.StringMan;
import java.util.Locale;
/**
* An internal FAWE class not meant for public use.
**/
@ -11,28 +15,34 @@ public class FaweVersion {
public final int day;
public final int hash;
public final int build;
public final int[] semver;
public final boolean snapshot;
public FaweVersion(int year, int month, int day, int hash, int build) {
public FaweVersion(int year, int month, int day, int[] semver, boolean snapshot, int hash, int build) {
this.year = year;
this.month = month;
this.day = day;
this.hash = hash;
this.build = build;
this.semver = semver;
this.snapshot = snapshot;
}
public FaweVersion(String version, String commit, String date) {
String[] split = version.substring(version.indexOf('=') + 1).split("-");
int build = 0;
try {
build = Integer.parseInt(split[1]);
} catch (NumberFormatException ignored) {
String[] split1 = split[0].split("\\.");
int[] ver = new int[3];
for (int i = 0; i < 3; i++) {
ver[i] = Integer.parseInt(split1[i]);
}
this.build = build;
this.semver = ver;
this.snapshot = split.length > 1 && split[1].toLowerCase(Locale.ROOT).contains("snapshot");
this.build = version.contains("+") ? Integer.parseInt(version.substring(version.indexOf('+') + 1)) : 0;
this.hash = Integer.parseInt(commit.substring(commit.indexOf('=') + 1), 16);
String[] split1 = date.substring(date.indexOf('=') + 1).split("\\.");
this.year = Integer.parseInt(split1[0]);
this.month = Integer.parseInt(split1[1]);
this.day = Integer.parseInt(split1[2]);
String[] split2 = date.substring(date.indexOf('=') + 1).split("\\.");
this.year = Integer.parseInt(split2[0]);
this.month = Integer.parseInt(split2[1]);
this.day = Integer.parseInt(split2[2]);
}
public static FaweVersion tryParse(String version, String commit, String date) {
@ -40,28 +50,42 @@ public class FaweVersion {
return new FaweVersion(version, commit, date);
} catch (Exception exception) {
exception.printStackTrace();
return new FaweVersion(0, 0, 0, 0, 0);
return new FaweVersion(0, 0, 0, null, true, 0, 0);
}
}
@Override
public String toString() {
if (hash == 0 && build == 0) {
return getSimpleVersionName() + "-NoVer-SNAPSHOT";
if (semver == null) {
return "FastAsyncWorldEdit-NoVer-SNAPSHOT";
} else {
return getSimpleVersionName() + "-" + build;
String snapshot = this.snapshot ? "-SNAPSHOT" : "";
String build = this.build > 0 ? "+" + this.build : "";
return "FastAsyncWorldEdit-" + StringMan.join(semver, ".") + snapshot + build;
}
}
/**
* @return The qualified version name
* Returns if another FaweVersion is newer than this one
*/
public String getSimpleVersionName() {
return "FastAsyncWorldEdit-1.17";
}
public boolean isNewer(FaweVersion other) {
return other.build < this.build;
if (other.semver == null) {
return other.build > this.build;
}
if (this.semver == null) {
return true;
}
if (other.semver[0] != this.semver[0]) {
return other.semver[0] > this.semver[0];
} else if (other.semver[1] != this.semver[1]) {
return other.semver[1] > this.semver[1];
} else if (other.semver[2] != this.semver[2]) {
return other.semver[2] > this.semver[2];
}
if (other.snapshot == this.snapshot) {
return other.build > this.build;
}
return !other.snapshot;
}
}

Datei anzeigen

@ -30,8 +30,7 @@ public class UpdateNotification {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
//TODO 1.18 revisit and update to semver parsing after updating FaweVersion.java
Document doc = db.parse(new URL("https://ci.athion.net/job/FastAsyncWorldEdit-1.17/api/xml/").openStream());
Document doc = db.parse(new URL("https://ci.athion.net/job/FastAsyncWorldEdit/api/xml/").openStream());
faweVersion = doc.getElementsByTagName("lastSuccessfulBuild").item(0).getFirstChild().getTextContent();
FaweVersion faweVersion = Fawe.get().getVersion();
if (faweVersion.build == 0) {
@ -45,11 +44,10 @@ public class UpdateNotification {
LOGGER.warn(
"""
An update for FastAsyncWorldEdit is available. You are {} build(s) out of date.
You are running version {}, the latest version is {}-{}.
You are running build {}, the latest version is build {}.
Update at https://www.spigotmc.org/resources/13932/""",
versionDifference,
faweVersion.toString(),
faweVersion.getSimpleVersionName(),
faweVersion.build,
UpdateNotification.faweVersion
);
}
@ -70,8 +68,11 @@ public class UpdateNotification {
if (actor.hasPermission("fawe.admin") && UpdateNotification.hasUpdate) {
FaweVersion faweVersion = Fawe.get().getVersion();
int versionDifference = Integer.parseInt(UpdateNotification.faweVersion) - faweVersion.build;
actor.print(Caption.of("fawe.info.update-available", versionDifference, faweVersion.toString(),
faweVersion.getSimpleVersionName() + "-" + UpdateNotification.faweVersion,
actor.print(Caption.of(
"fawe.info.update-available",
versionDifference,
faweVersion.build,
UpdateNotification.faweVersion,
TextComponent
.of("https://www.spigotmc.org/resources/13932/")
.clickEvent(ClickEvent.openUrl("https://www.spigotmc.org/resources/13932/"))

Datei anzeigen

@ -13,7 +13,7 @@
"fawe.info.worldedit.restricted": "Your FAWE edits are now restricted.",
"fawe.info.worldedit.oom.admin": "Possible options:\n - //fast\n - Do smaller edits\n - Allocate more memory\n - Disable `max-memory-percent`",
"fawe.info.temporarily-not-working": "Temporarily not working",
"fawe.info.update-available": "An update for FastAsyncWorldEdit is available. You are {0} build(s) out of date.\nYou are running version {1}, the latest version is {2}.\nUpdate at {3}",
"fawe.info.update-available": "An update for FastAsyncWorldEdit is available. You are {0} build(s) out of date.\nYou are running build {1}, the latest version is build {2}.\nUpdate at {3}",
"fawe.web.generating.link": "Uploading {0}, please wait...",
"fawe.web.generating.link.failed": "Failed to generate download link!",
"fawe.web.download.link": "{0}",