mirror of
https://github.com/nkomarn/harbor.git
synced 2024-12-19 14:57:38 +01:00
⚡ Async update check
This commit is contained in:
parent
d018365dfc
commit
bb7dfde0f0
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>xyz.nkomarn</groupId>
|
||||
<artifactId>Harbor</artifactId>
|
||||
<version>1.6</version>
|
||||
<version>1.6.1</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -12,7 +12,7 @@ import xyz.nkomarn.Harbor.util.Metrics;
|
||||
public class Harbor extends JavaPlugin {
|
||||
|
||||
public static Harbor instance;
|
||||
public static String version = "1.6";
|
||||
public static String version = "1.6.1";
|
||||
public static Essentials essentials;
|
||||
|
||||
public void onEnable() {
|
||||
|
@ -5,9 +5,11 @@ import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import xyz.nkomarn.Harbor.Harbor;
|
||||
import xyz.nkomarn.Harbor.util.Config;
|
||||
import xyz.nkomarn.Harbor.util.Updater;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@ -19,23 +21,25 @@ public class PlayerListener implements Listener {
|
||||
if (!e.getPlayer().hasPermission("harbor.admin") || !Config.getBoolean("features.notifier")) return;
|
||||
|
||||
// Check for updates
|
||||
boolean updateAvailable = false;
|
||||
try {
|
||||
updateAvailable = Updater.check().get();
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Harbor.instance, () -> {
|
||||
boolean updateAvailable = false;
|
||||
try {
|
||||
updateAvailable = Updater.check().get();
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (updateAvailable) {
|
||||
TextComponent updateMessage = new TextComponent(ChatColor.translateAlternateColorCodes('&',
|
||||
Config.getString("messages.miscellaneous.prefix")
|
||||
+ "&7Hey there, Harbor " + Updater.latest + " is now out!"
|
||||
+ " Click this message to upgrade automatically."));
|
||||
updateMessage.setColor(ChatColor.GRAY);
|
||||
updateMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new ComponentBuilder("§a§l↑ §7Click to update Harbor now!").create()));
|
||||
updateMessage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/harbor update"));
|
||||
e.getPlayer().spigot().sendMessage(updateMessage);
|
||||
}
|
||||
if (updateAvailable) {
|
||||
TextComponent updateMessage = new TextComponent(ChatColor.translateAlternateColorCodes('&',
|
||||
Config.getString("messages.miscellaneous.prefix")
|
||||
+ "&7Hey there, Harbor " + Updater.latest + " is now out!"
|
||||
+ " Click this message to upgrade automatically."));
|
||||
updateMessage.setColor(ChatColor.GRAY);
|
||||
updateMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new ComponentBuilder("§a§l↑ §7Click to update Harbor now!").create()));
|
||||
updateMessage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/harbor update"));
|
||||
e.getPlayer().spigot().sendMessage(updateMessage);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -20,7 +20,7 @@ public class Updater {
|
||||
public static Future<Boolean> check() {
|
||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
|
||||
Executors.newCachedThreadPool().submit(() -> {
|
||||
ForkJoinPool.commonPool().submit(() -> {
|
||||
try {
|
||||
URL latestVersion = new URL("https://api.spigotmc.org/legacy/update.php?resource=60088");
|
||||
URLConnection request = latestVersion.openConnection();
|
||||
@ -43,7 +43,7 @@ public class Updater {
|
||||
public static Future<String> upgrade() {
|
||||
CompletableFuture<String> future = new CompletableFuture<>();
|
||||
|
||||
Executors.newCachedThreadPool().submit(() -> {
|
||||
ForkJoinPool.commonPool().submit(() -> {
|
||||
String jarName = new File(Updater.class.getProtectionDomain().getCodeSource().getLocation()
|
||||
.getPath()).getName();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user