From b0e291edc4c62e303cba7002ea47ffde8550d4a1 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Mon, 6 Jul 2020 12:18:14 +0100 Subject: [PATCH] Fix version checking and add failed language string --- .../connector/command/defaults/VersionCommand.java | 14 +++++++++----- connector/src/main/resources/languages | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/VersionCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/VersionCommand.java index e29e164b3..7dd59712a 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/VersionCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/VersionCommand.java @@ -33,6 +33,9 @@ import org.geysermc.connector.utils.FileUtils; import org.geysermc.connector.utils.LanguageUtils; import org.geysermc.connector.utils.WebUtils; +import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.Properties; public class VersionCommand extends GeyserCommand { @@ -56,9 +59,9 @@ public class VersionCommand extends GeyserCommand { Properties gitProp = new Properties(); gitProp.load(FileUtils.getResource("git.properties")); - String buildXML = WebUtils.getBody("https://ci.nukkitx.com/job/GeyserMC/job/Geyser/job/" + gitProp.getProperty("git.branch") + "/lastSuccessfulBuild/api/xml?xpath=//master/buildNumber"); + String buildXML = WebUtils.getBody("https://ci.nukkitx.com/job/GeyserMC/job/Geyser/job/" + URLEncoder.encode(gitProp.getProperty("git.branch"), StandardCharsets.UTF_8.toString()) + "/lastSuccessfulBuild/api/xml?xpath=//buildNumber"); if (buildXML.startsWith("")) { - int latestBuildNum = Integer.parseInt(buildXML.replaceAll("<(\\\\)?buildNumber>", "")); + int latestBuildNum = Integer.parseInt(buildXML.replaceAll("<(\\\\)?(/)?buildNumber>", "").trim()); int buildNum = Integer.parseInt(gitProp.getProperty("git.build.number")); if (latestBuildNum != buildNum) { sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.commands.version.no_updates")); @@ -66,10 +69,11 @@ public class VersionCommand extends GeyserCommand { sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.commands.version.outdated", (latestBuildNum - buildNum), "http://ci.geysermc.org/")); } } else { - throw new AssertionError(); + throw new AssertionError("buildNumber missing"); } - } catch (Exception e) { - sender.sendMessage("Failed to check for updates"); + } catch (IOException | AssertionError | NumberFormatException e) { + GeyserConnector.getInstance().getLogger().error(LanguageUtils.getLocaleStringLog("geyser.commands.version.failed"), e); + sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.commands.version.failed")); } } } diff --git a/connector/src/main/resources/languages b/connector/src/main/resources/languages index c199011b6..fc8f930a2 160000 --- a/connector/src/main/resources/languages +++ b/connector/src/main/resources/languages @@ -1 +1 @@ -Subproject commit c199011b6c131b195e94d4785abbc3dd73ca19cd +Subproject commit fc8f930a238a375c7e3be6e5c7ea1720b61d0cca