Skip to content

Commit

Permalink
Add release update notification (#541)
Browse files Browse the repository at this point in the history
Also add that config option to our metrics
  • Loading branch information
Phoenix616 committed Feb 7, 2024
1 parent 2388da6 commit d3f8abb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/main/java/com/Acrobot/ChestShop/ChestShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ private void startStatistics() {
bStats.addCustomChart(new SimplePie("allow-partial-transactions", () -> Properties.ALLOW_PARTIAL_TRANSACTIONS ? "enabled" : "disabled"));
bStats.addCustomChart(new SimplePie("log-to-console", () -> Properties.LOG_TO_CONSOLE ? "enabled" : "disabled"));
bStats.addCustomChart(new SimplePie("log-to-file", () -> Properties.LOG_TO_FILE ? "enabled" : "disabled"));
bStats.addCustomChart(new SimplePie("auto-update", () -> !Properties.TURN_OFF_UPDATES ? "enabled" : "disabled"));
bStats.addCustomChart(new SimplePie("release-notifications", () -> !Properties.TURN_OFF_UPDATE_NOTIFIER ? "enabled" : "disabled"));
bStats.addCustomChart(new SimplePie("dev-build-notifications", () -> !Properties.TURN_OFF_DEV_UPDATE_NOTIFIER ? "enabled" : "disabled"));

bStats.addCustomChart(new AdvancedBarChart("pluginProperties", () -> {
Map<String, int[]> map = new LinkedHashMap<>();
Expand All @@ -518,6 +521,9 @@ private void startStatistics() {
map.put("bungeecord-messages", getChartArray(Properties.BUNGEECORD_MESSAGES));
map.put("log-to-console", getChartArray(Properties.LOG_TO_CONSOLE));
map.put("log-to-file", getChartArray(Properties.LOG_TO_FILE));
map.put("auto-update", getChartArray(!Properties.TURN_OFF_UPDATES));
map.put("release-notifications", getChartArray(!Properties.TURN_OFF_UPDATE_NOTIFIER));
map.put("dev-build-notifications", getChartArray(!Properties.TURN_OFF_DEV_UPDATE_NOTIFIER));
return map;
}));
bStats.addCustomChart(new SimpleBarChart("shopContainers",
Expand All @@ -538,6 +544,14 @@ private int[] getChartArray(boolean value) {
private void startUpdater() {
if (Properties.TURN_OFF_UPDATES) {
getLogger().info("Auto-updater is disabled. If you want the plugin to automatically download new releases then set 'TURN_OFF_UPDATES' to 'false' in your config.yml!");
if (!Properties.TURN_OFF_UPDATE_NOTIFIER) {
final Updater updater = new Updater(this, PROJECT_BUKKITDEV_ID, this.getFile(), Updater.UpdateType.NO_DOWNLOAD, true);
getServer().getScheduler().runTaskAsynchronously(this, () -> {
if (updater.getResult() == Updater.UpdateResult.UPDATE_AVAILABLE) {
getLogger().info("There is a new version available: " + updater.getLatestName() + ". You can download it from https://dev.bukkit.org/projects/" + PROJECT_BUKKITDEV_ID);
}
});
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public <T> Object parseToJava(Class<T> type, Object object) {
@ConfigurationComment("Do you want to turn off the automatic updates of ChestShop?")
public static boolean TURN_OFF_UPDATES = true;

@ConfigurationComment("Do you want to turn off the automatic notifications for releases?")
public static boolean TURN_OFF_UPDATE_NOTIFIER = false;

@ConfigurationComment("Do you want to turn off the automatic notifications for new development builds?")
public static boolean TURN_OFF_DEV_UPDATE_NOTIFIER = false;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/Acrobot/ChestShop/Updater/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ private boolean versionCheck(String title) {
* @return true if Updater should consider the remote version an update, false if not.
*/
public boolean shouldUpdate(String localVersion, String remoteVersion) {
if (localVersion.contains("DEV") || getLatestType() != ReleaseType.RELEASE) {
if (this.type != Updater.UpdateType.NO_DOWNLOAD && localVersion.contains("DEV") || getLatestType() != ReleaseType.RELEASE) {
return false; //Do not download alphas or betas
}

Expand Down

0 comments on commit d3f8abb

Please sign in to comment.