geforkt von Mirrors/FastAsyncWorldEdit
chore: Lazily prepare update checker for future job
Future versions of Fawe use a version agnostic job. This commit will remain unmerged to any other branch but warrant a working update checker.
Dieser Commit ist enthalten in:
Ursprung
96ca83704a
Commit
42035bdb87
@ -1,59 +1,23 @@
|
|||||||
package com.fastasyncworldedit.core.util;
|
package com.fastasyncworldedit.core.util;
|
||||||
|
|
||||||
import com.fastasyncworldedit.core.Fawe;
|
|
||||||
import com.fastasyncworldedit.core.FaweVersion;
|
|
||||||
import com.fastasyncworldedit.core.configuration.Caption;
|
|
||||||
import com.fastasyncworldedit.core.configuration.Settings;
|
import com.fastasyncworldedit.core.configuration.Settings;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.internal.util.LogManagerCompat;
|
import com.sk89q.worldedit.internal.util.LogManagerCompat;
|
||||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||||
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
|
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.w3c.dom.Document;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class UpdateNotification {
|
public class UpdateNotification {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
||||||
|
|
||||||
private static boolean hasUpdate;
|
|
||||||
private static String faweVersion = "";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a new build with a higher build number than the current build is available.
|
* Check whether a new build with a higher build number than the current build is available.
|
||||||
*/
|
*/
|
||||||
public static void doUpdateCheck() {
|
public static void doUpdateCheck() {
|
||||||
if (Settings.IMP.ENABLED_COMPONENTS.UPDATE_NOTIFICATIONS) {
|
if (Settings.IMP.ENABLED_COMPONENTS.UPDATE_NOTIFICATIONS) {
|
||||||
try {
|
LOGGER.warn("An update for FastAsyncWorldEdit is available. Update at https://ci.athion.net/job/FastAsyncWorldEdit/");
|
||||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
|
||||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
|
||||||
Document doc = db.parse(new URL("https://ci.athion.net/job/FastAsyncWorldEdit-1.17/api/xml/").openStream());
|
|
||||||
faweVersion = doc.getElementsByTagName("lastSuccessfulBuild").item(0).getFirstChild().getTextContent();
|
|
||||||
FaweVersion faweVersion = Fawe.get().getVersion();
|
|
||||||
if (faweVersion.build == 0) {
|
|
||||||
LOGGER.warn("You are using a snapshot or a custom version of FAWE. This is not an official build distributed " +
|
|
||||||
"via https://www.spigotmc.org/resources/13932/");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (faweVersion.build < Integer.parseInt(UpdateNotification.faweVersion)) {
|
|
||||||
hasUpdate = true;
|
|
||||||
int versionDifference = Integer.parseInt(UpdateNotification.faweVersion) - faweVersion.build;
|
|
||||||
LOGGER.warn(
|
|
||||||
"An update for FastAsyncWorldEdit is available. You are {} build(s) out of date.\nYou are running " +
|
|
||||||
"version {}, the latest version is {}-{}.\nUpdate at https://www.spigotmc.org/resources/13932/",
|
|
||||||
versionDifference,
|
|
||||||
faweVersion.toString(),
|
|
||||||
faweVersion.getSimpleVersionName(),
|
|
||||||
UpdateNotification.faweVersion
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOGGER.error("Unable to check for updates. Skipping.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,15 +28,11 @@ public class UpdateNotification {
|
|||||||
*/
|
*/
|
||||||
public static void doUpdateNotification(Actor actor) {
|
public static void doUpdateNotification(Actor actor) {
|
||||||
if (Settings.IMP.ENABLED_COMPONENTS.UPDATE_NOTIFICATIONS) {
|
if (Settings.IMP.ENABLED_COMPONENTS.UPDATE_NOTIFICATIONS) {
|
||||||
if (actor.hasPermission("fawe.admin") && UpdateNotification.hasUpdate) {
|
if (actor.hasPermission("fawe.admin")) {
|
||||||
FaweVersion faweVersion = Fawe.get().getVersion();
|
actor.printInfo(TextComponent.of("An update for FastAsyncWorldEdit is available. Update at " +
|
||||||
int versionDifference = Integer.parseInt(UpdateNotification.faweVersion) - faweVersion.build;
|
"https://ci.athion.net/job/FastAsyncWorldEdit/").clickEvent(ClickEvent.openUrl("https://ci.athion.net/job/FastAsyncWorldEdit/"))
|
||||||
actor.print(Caption.of("fawe.info.update-available", versionDifference, faweVersion.toString(),
|
|
||||||
faweVersion.getSimpleVersionName() + "-" + UpdateNotification.faweVersion,
|
);
|
||||||
TextComponent
|
|
||||||
.of("https://www.spigotmc.org/resources/13932/")
|
|
||||||
.clickEvent(ClickEvent.openUrl("https://www.spigotmc.org/resources/13932/"))
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren