Skip to content

Commit

Permalink
Update BStats and Generalized Updater for Add-on usage
Browse files Browse the repository at this point in the history
  • Loading branch information
KillerOfPie committed Aug 20, 2021
1 parent 68f7dd4 commit dcd11fa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.7</version>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/shanerx/tradeshop/TradeShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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() {
Expand Down
30 changes: 16 additions & 14 deletions src/main/java/org/shanerx/tradeshop/utils/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit dcd11fa

Please sign in to comment.