Skip to content

Commit fbaa954

Browse files
committed
Include update checker
1 parent ceae7a2 commit fbaa954

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>xyz.jpenilla</groupId>
88
<artifactId>DynamicShop-Graph</artifactId>
9-
<version>0.2.2-SNAPSHOT.{BUILD_NUMBER}</version>
9+
<version>0.2.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>DynamicShop Graph</name>

src/main/java/xyz/jpenilla/dsgraph/DSGraph.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public void onEnable() {
4343
Metrics metrics = new Metrics(this, pluginId);
4444
metrics.addCustomChart(new Metrics.SimplePie("amount_of_items_tracked", () -> String.valueOf(cfg.getFiles().size())));
4545

46+
new UpdateChecker(this, 80638).getVersion(version -> {
47+
if (!this.getDescription().getVersion().equalsIgnoreCase(version)) {
48+
getLogger().info("There is an update available for DynamicShop-Graph (" + version + ") at https://www.spigotmc.org/resources/dynamicshop-graph.80638/");
49+
}
50+
});
4651
}
4752

4853
@Override
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package xyz.jpenilla.dsgraph;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.plugin.Plugin;
5+
import org.bukkit.util.Consumer;
6+
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.net.URL;
10+
import java.util.Scanner;
11+
12+
public class UpdateChecker {
13+
14+
private final Plugin plugin;
15+
private final int resourceId;
16+
17+
public UpdateChecker(Plugin plugin, int resourceId) {
18+
this.plugin = plugin;
19+
this.resourceId = resourceId;
20+
}
21+
22+
public void getVersion(final Consumer<String> consumer) {
23+
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
24+
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream(); Scanner scanner = new Scanner(inputStream)) {
25+
if (scanner.hasNext()) {
26+
consumer.accept(scanner.next());
27+
}
28+
} catch (IOException exception) {
29+
this.plugin.getLogger().info("Cannot look for updates: " + exception.getMessage());
30+
}
31+
});
32+
}
33+
}

src/main/resources/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<ul>
7272
<li><a class="grey-text text-lighten-3" href="https://github.com/jmanpenilla/DynamicShop-Graph">GitHub</a>
7373
</li>
74-
<li><a class="grey-text text-lighten-3" href="#!">Spigot</a></li>
74+
<li><a class="grey-text text-lighten-3" href="https://www.spigotmc.org/resources/dynamicshop-graph.80638/">Spigot</a></li>
7575
</ul>
7676
</div>
7777
</div>

0 commit comments

Comments
 (0)