Skip to content
This repository has been archived by the owner on May 22, 2022. It is now read-only.

Commit

Permalink
Update 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
efekurbann committed Apr 17, 2021
1 parent 39565bb commit 4b46ab7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
27 changes: 7 additions & 20 deletions src/main/java/xyz/efekurbann/topbalance/TopBalancePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import xyz.efekurbann.topbalance.utils.VaultManager;

import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

public final class TopBalancePlugin extends JavaPlugin {

Expand All @@ -28,7 +26,7 @@ public final class TopBalancePlugin extends JavaPlugin {
@Override
public void onEnable() {
instance = this;
if (!VaultManager.setupEconomy()){
if (!VaultManager.setupEconomy()) {
getLogger().severe("Vault-Eco not found! Plugin is disabled..");
getServer().getPluginManager().disablePlugin(this);
return;
Expand All @@ -44,28 +42,17 @@ public void onEnable() {
getCommand("baltop").setExecutor(new MainCommand(this));
new Metrics(this, 11047);
UpdateChecker updateChecker = new UpdateChecker(this);
updateChecker.isUpToDate((isUpToDate)->{
if (!isUpToDate) {
getLogger().info("An update was found for TopBalance!");
getLogger().info("https://www.spigotmc.org/resources/91372/");
} else {
getLogger().info("Plugin is up to date, no update found.");
getLogger().info("Plugin enabled. Thank you for using.");
}
});
updateChecker.checkUpdates();

this.getServer().getPluginManager().registerEvents(new Listener() {
@EventHandler
public void onJoin(PlayerJoinEvent event){
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (!player.hasPermission("topbalance.admin")) return;

new UpdateChecker(TopBalancePlugin.getInstance()).isUpToDate((isUpToDate)->{
if (!isUpToDate) {
player.sendMessage(ChatColor.GREEN + "An update was found for TopBalance!");
player.sendMessage(ChatColor.GREEN + "Download it here: "+ ChatColor.DARK_GREEN +"https://www.spigotmc.org/resources/91372/");
}
});
if (!updateChecker.isUpToDate()) {
player.sendMessage(ChatColor.GREEN + "An update was found for TopBalance!");
player.sendMessage(ChatColor.GREEN + "Download it here: " + ChatColor.DARK_GREEN + "https://www.spigotmc.org/resources/91372/");
}
}
}, this);

Expand Down
18 changes: 15 additions & 3 deletions src/main/java/xyz/efekurbann/topbalance/UpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,36 @@ public class UpdateChecker {

private final TopBalancePlugin plugin;
private String latestVersion;
private boolean isUpToDate;

public UpdateChecker(TopBalancePlugin plugin) {
this.plugin = plugin;
}

public void isUpToDate(final Consumer<Boolean> consumer) {
public void checkUpdates() {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
try {
HttpsURLConnection con = (HttpsURLConnection) (new URL("https://api.spigotmc.org/legacy/update.php?resource=91372")).openConnection();
con.setRequestMethod("GET");
InputStreamReader reader = new InputStreamReader(con.getInputStream());
this.latestVersion = (new BufferedReader(reader)).readLine();
String version = plugin.getDescription().getVersion();
this.isUpToDate = this.latestVersion.equals(plugin.getDescription().getVersion());

consumer.accept(latestVersion.equals(version));
if (!isUpToDate) {
plugin.getLogger().info("An update was found for TopBalance!");
plugin.getLogger().info("https://www.spigotmc.org/resources/91372/");
} else {
plugin.getLogger().info("Plugin is up to date, no update found.");
plugin.getLogger().info("Plugin enabled. Thank you for using.");
}
} catch (IOException exception) {
this.plugin.getLogger().info("Cannot look for updates: " + exception.getMessage());
}
});
}

public boolean isUpToDate() {
return isUpToDate;
}

}

0 comments on commit 4b46ab7

Please sign in to comment.