Update 1.2.1
Added UpdateChecker
This commit is contained in:
parent
f4fa0d86b0
commit
9fcbee447d
3 changed files with 53 additions and 1 deletions
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>pl.sloudpl</groupId>
|
<groupId>pl.sloudpl</groupId>
|
||||||
<artifactId>SloudVanish</artifactId>
|
<artifactId>SloudVanish</artifactId>
|
||||||
<version>1.2</version>
|
<version>1.2.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>SloudVanish</name>
|
<name>SloudVanish</name>
|
||||||
|
|
|
@ -7,6 +7,7 @@ import pl.sloudpl.simplevanish.cmds.VanishCommand;
|
||||||
import pl.sloudpl.simplevanish.events.onJoinEvent;
|
import pl.sloudpl.simplevanish.events.onJoinEvent;
|
||||||
import pl.sloudpl.simplevanish.events.onLeaveEvent;
|
import pl.sloudpl.simplevanish.events.onLeaveEvent;
|
||||||
import pl.sloudpl.simplevanish.events.onPlayerDamage;
|
import pl.sloudpl.simplevanish.events.onPlayerDamage;
|
||||||
|
import pl.sloudpl.simplevanish.utils.UpdateChecker;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -31,6 +32,17 @@ public final class SimpleVanish extends JavaPlugin {
|
||||||
new onPlayerDamage(this);
|
new onPlayerDamage(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new UpdateChecker(this, 108713).getLatestVersion(version -> {
|
||||||
|
String current = this.getDescription().getVersion();
|
||||||
|
if (!current.equalsIgnoreCase(version)) {
|
||||||
|
getLogger().warning("§cA new version of §eSloudVanish §cis available!");
|
||||||
|
getLogger().warning("§7Current: §e" + current + " §7| Latest: §a" + version);
|
||||||
|
getLogger().warning("§bDownload: https://www.spigotmc.org/resources/sloudvanish.108713/");
|
||||||
|
} else {
|
||||||
|
getLogger().info("§aSloudVanish is up to date (v" + current + ").");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package pl.sloudpl.simplevanish.utils;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import pl.sloudpl.simplevanish.SimpleVanish;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class UpdateChecker {
|
||||||
|
private final SimpleVanish plugin;
|
||||||
|
private final int resourceId;
|
||||||
|
|
||||||
|
public UpdateChecker(SimpleVanish plugin, int resourceId) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.resourceId = resourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getLatestVersion(Consumer<String> callback) {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
try {
|
||||||
|
URL url = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + resourceId);
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestMethod("GET");
|
||||||
|
conn.setConnectTimeout(5000);
|
||||||
|
conn.setReadTimeout(5000);
|
||||||
|
|
||||||
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
|
||||||
|
String version = reader.readLine();
|
||||||
|
callback.accept(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().warning("Failed to check for updates: " + e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue