From dcd11fa9c831849e52f2e44b7b10ec681050a970 Mon Sep 17 00:00:00 2001 From: Nathan Thor Date: Fri, 20 Aug 2021 13:24:42 -0700 Subject: [PATCH] Update BStats and Generalized Updater for Add-on usage --- pom.xml | 2 +- .../java/org/shanerx/tradeshop/TradeShop.java | 4 +-- .../org/shanerx/tradeshop/utils/Updater.java | 30 ++++++++++--------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index e72804c0..7f0a7bf6 100644 --- a/pom.xml +++ b/pom.xml @@ -154,7 +154,7 @@ org.bstats bstats-bukkit - 1.7 + 2.2.1 compile diff --git a/src/main/java/org/shanerx/tradeshop/TradeShop.java b/src/main/java/org/shanerx/tradeshop/TradeShop.java index c9ac8ddb..bd830b98 100644 --- a/src/main/java/org/shanerx/tradeshop/TradeShop.java +++ b/src/main/java/org/shanerx/tradeshop/TradeShop.java @@ -105,7 +105,7 @@ public void onEnable() { getCommand("tradeshop").setTabCompleter(new CommandTabCaller(this)); if (Setting.CHECK_UPDATES.getBoolean()) { - new Thread(() -> new Updater(getDescription()).checkCurrentVersion()).start(); + new Thread(() -> getUpdater().checkCurrentVersion()).start(); } if (Setting.ALLOW_METRICS.getBoolean()) { @@ -157,7 +157,7 @@ public ShopStorage getStorages() { } public Updater getUpdater() { - return new Updater(getDescription()); + return new Updater(getDescription(), "https://api.spigotmc.org/legacy/update.php?resource=32762", "https://www.spigotmc.org/resources/tradeshop.32762/"); } public Debug getDebugger() { diff --git a/src/main/java/org/shanerx/tradeshop/utils/Updater.java b/src/main/java/org/shanerx/tradeshop/utils/Updater.java index 28992bc9..f8a1d64c 100644 --- a/src/main/java/org/shanerx/tradeshop/utils/Updater.java +++ b/src/main/java/org/shanerx/tradeshop/utils/Updater.java @@ -38,17 +38,19 @@ public class Updater { private static Logger log; - private PluginDescriptionFile pdf; + private final PluginDescriptionFile pdf; private BuildType build; private URL url = null; + private final String updateURL; - public Updater(PluginDescriptionFile pdf) { + public Updater(PluginDescriptionFile pdf, String versionURL, String updateURL) { this.pdf = pdf; + this.updateURL = updateURL; - log = Bukkit.getPluginManager().getPlugin("TradeShop").getLogger(); + log = Bukkit.getPluginManager().getPlugin(pdf.getName()).getLogger(); try { - url = new URL("https://api.spigotmc.org/legacy/update.php?resource=32762"); // Edit API URL. + url = new URL(versionURL); } catch (MalformedURLException ex) { log.log(Level.WARNING, "Error: Bad URL while checking {0} !", pdf.getName()); } @@ -96,19 +98,19 @@ public RelationalStatus checkCurrentVersion() { RelationalStatus rs = compareVersions(ver[0], ver[1], ver[2].split("-")[0]); if (rs == RelationalStatus.BEHIND) { log.log(Level.WARNING, "[Updater] +------------------------------------------------+"); - log.log(Level.WARNING, "[Updater] You are running an outdated version of the plugin!"); + log.log(Level.WARNING, "[Updater] You are running an outdated version of " + pdf.getName() + "!"); log.log(Level.WARNING, "[Updater] Most recent stable version: " + inputLine); - log.log(Level.WARNING, "[Updater] Current version: " + getVersion()); - log.log(Level.WARNING, "[Updater] Please update from: "); - log.log(Level.WARNING, "[Updater] https://www.spigotmc.org/resources/tradeshop.32762/"); + log.log(Level.WARNING, "[Updater] Current version: " + getVersion()); + log.log(Level.WARNING, "[Updater] Please update from: "); + log.log(Level.WARNING, "[Updater] " + updateURL); log.log(Level.WARNING, "[Updater] +------------------------------------------------+"); in.close(); return RelationalStatus.BEHIND; } else if (rs == RelationalStatus.AHEAD) { log.log(Level.WARNING, "[Updater] +-----------------------------------------------------+"); - log.log(Level.WARNING, "[Updater] You are running a developmental version of the plugin!"); + log.log(Level.WARNING, "[Updater] You are running a developmental version of " + pdf.getName() + "!"); log.log(Level.WARNING, "[Updater] Most recent stable version: " + inputLine); - log.log(Level.WARNING, "[Updater] Current version: " + getVersion()); + log.log(Level.WARNING, "[Updater] Current version: " + getVersion()); log.log(Level.WARNING, "[Updater] Please notice that the build may contain critical bugs!"); log.log(Level.WARNING, "[Updater] +-----------------------------------------------------+"); in.close(); @@ -122,10 +124,10 @@ public RelationalStatus checkCurrentVersion() { } catch (Exception e) { e.printStackTrace(); log.log(Level.WARNING, "[Updater] +----------------------------------------------------+"); - log.log(Level.WARNING, "[Updater] Could not establish a connection to check for updates!"); - log.log(Level.WARNING, "[Updater] Current version: " + getVersion()); - log.log(Level.WARNING, "[Updater] Please check for new updates from: "); - log.log(Level.WARNING, "[Updater] https://www.spigotmc.org/resources/tradeshop.32762/"); + log.log(Level.WARNING, "[Updater] Could not establish a connection to check " + pdf.getName() + " for updates!"); + log.log(Level.WARNING, "[Updater] Current version: " + getVersion()); + log.log(Level.WARNING, "[Updater] Please check for new updates from: "); + log.log(Level.WARNING, "[Updater] " + updateURL); log.log(Level.WARNING, "[Updater] +----------------------------------------------------+"); } return RelationalStatus.UNKNOWN;