Update from Git Manager GUI

This commit is contained in:
2026-03-27 10:05:01 +01:00
parent a27c174daa
commit d92d0d5328
3 changed files with 10 additions and 59 deletions

View File

@@ -323,7 +323,7 @@ public class NexusLobby extends JavaPlugin implements Listener {
player.sendMessage(de.nexuslobby.utils.LangManager.get("update_available"));
player.sendMessage(de.nexuslobby.utils.LangManager.get("update_version").replace("{old}", getDescription().getVersion()).replace("{new}", latestVersion));
TextComponent link = new TextComponent(de.nexuslobby.utils.LangManager.get("update_download_link"));
link.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://git.viper.ipv64.net/M_Viper/NexusLobby/releases"));
link.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/132388/"));
link.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder(de.nexuslobby.utils.LangManager.get("update_download_hover")).create()));
player.spigot().sendMessage(link);

View File

@@ -1,24 +1,18 @@
package de.nexuslobby.utils;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import de.nexuslobby.NexusLobby;
import org.bukkit.Bukkit;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.function.Consumer;
public class UpdateChecker {
private final NexusLobby plugin;
private static final String API_URL = "https://git.viper.ipv64.net/api/v1/repos/M_Viper/NexusLobby/releases/latest";
private static final int TIMEOUT_MS = 5000;
private static final int RESOURCE_ID = 132388;
public UpdateChecker(NexusLobby plugin) {
this.plugin = plugin;
@@ -26,60 +20,17 @@ public class UpdateChecker {
public void getVersion(final Consumer<String> consumer) {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
HttpURLConnection connection = null;
try {
URL url = new URL(API_URL);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(TIMEOUT_MS);
connection.setReadTimeout(TIMEOUT_MS);
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("User-Agent", "NexusLobby-UpdateChecker");
try (InputStream is = new URL(
"https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID + "/~").openStream();
Scanner scanner = new Scanner(is)) {
int responseCode = connection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
plugin.getLogger().warning("Update-Check fehlgeschlagen: HTTP " + responseCode);
return;
}
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
parseAndNotify(response.toString(), consumer);
if (scanner.hasNext()) {
consumer.accept(scanner.next());
}
} catch (IOException e) {
plugin.getLogger().warning("Update-Check fehlgeschlagen: " + e.getMessage());
} finally {
if (connection != null) {
connection.disconnect();
}
}
});
}
private void parseAndNotify(String jsonResponse, Consumer<String> consumer) {
try {
JsonObject json = JsonParser.parseString(jsonResponse).getAsJsonObject();
if (json.has("tag_name")) {
String version = json.get("tag_name").getAsString();
// Entferne 'v' Präfix falls vorhanden (z.B. v1.0.0 -> 1.0.0)
if (version.startsWith("v")) {
version = version.substring(1);
}
consumer.accept(version);
} else {
plugin.getLogger().warning("Update-Check: 'tag_name' nicht in API-Response gefunden");
}
} catch (JsonSyntaxException e) {
plugin.getLogger().warning("Update-Check: Ungültiges JSON-Format - " + e.getMessage());
}
}
}

View File

@@ -1,6 +1,6 @@
name: NexusLobby
main: de.nexuslobby.NexusLobby
version: "1.1.4"
version: "1.1.5"
api-version: "1.21"
author: M_Viper
description: Modular Lobby Plugin with an invisible Particle-Parkour system.