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_available"));
player.sendMessage(de.nexuslobby.utils.LangManager.get("update_version").replace("{old}", getDescription().getVersion()).replace("{new}", latestVersion)); 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")); 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, link.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder(de.nexuslobby.utils.LangManager.get("update_download_hover")).create())); new ComponentBuilder(de.nexuslobby.utils.LangManager.get("update_download_hover")).create()));
player.spigot().sendMessage(link); player.spigot().sendMessage(link);

View File

@@ -1,24 +1,18 @@
package de.nexuslobby.utils; package de.nexuslobby.utils;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import de.nexuslobby.NexusLobby; import de.nexuslobby.NexusLobby;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.util.Scanner;
import java.util.function.Consumer; import java.util.function.Consumer;
public class UpdateChecker { public class UpdateChecker {
private final NexusLobby plugin; 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 RESOURCE_ID = 132388;
private static final int TIMEOUT_MS = 5000;
public UpdateChecker(NexusLobby plugin) { public UpdateChecker(NexusLobby plugin) {
this.plugin = plugin; this.plugin = plugin;
@@ -26,60 +20,17 @@ public class UpdateChecker {
public void getVersion(final Consumer<String> consumer) { public void getVersion(final Consumer<String> consumer) {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> { Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
HttpURLConnection connection = null; try (InputStream is = new URL(
try { "https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID + "/~").openStream();
URL url = new URL(API_URL); Scanner scanner = new Scanner(is)) {
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");
int responseCode = connection.getResponseCode(); if (scanner.hasNext()) {
if (responseCode != HttpURLConnection.HTTP_OK) { consumer.accept(scanner.next());
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);
} }
} catch (IOException e) { } catch (IOException e) {
plugin.getLogger().warning("Update-Check fehlgeschlagen: " + e.getMessage()); 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 name: NexusLobby
main: de.nexuslobby.NexusLobby main: de.nexuslobby.NexusLobby
version: "1.1.4" version: "1.1.5"
api-version: "1.21" api-version: "1.21"
author: M_Viper author: M_Viper
description: Modular Lobby Plugin with an invisible Particle-Parkour system. description: Modular Lobby Plugin with an invisible Particle-Parkour system.