package de.nexuslobby.utils; import de.nexuslobby.NexusLobby; import org.bukkit.Bukkit; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Scanner; import java.util.function.Consumer; public class UpdateChecker { private final NexusLobby plugin; // URL zur Gitea API für das neueste Release private final String url = "https://git.viper.ipv64.net/api/v1/repos/M_Viper/NexusLobby/releases/latest"; public UpdateChecker(NexusLobby plugin) { this.plugin = plugin; } public void getVersion(final Consumer consumer) { Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> { try (InputStream inputStream = new URL(url).openStream(); Scanner scanner = new Scanner(inputStream)) { StringBuilder response = new StringBuilder(); while (scanner.hasNextLine()) { response.append(scanner.nextLine()); } String content = response.toString(); // Einfaches Parsing des JSON "tag_name" Feldes if (content.contains("\"tag_name\":")) { String version = content.split("\"tag_name\":\"")[1].split("\"")[0]; // Entferne ein eventuelles 'v' Präfix (z.B. v1.0.0 -> 1.0.0) version = version.replace("v", ""); consumer.accept(version); } } catch (IOException exception) { this.plugin.getLogger().warning("Update-Check fehlgeschlagen: " + exception.getMessage()); } }); } }