Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class InitializeLogger {

public static void start() {
start = Instant.now();
info("--------------GeyserExtras--------------");
info("--------------GeyserPlus--------------");
info("Version: " + PluginVersion.GE_VERSION);
info("Server Type: " + ServerType.get());
info("Platform Type: " + ServerType.platform().platformName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static InputStream request(URL url) {
try {
URLConnection cn = url.openConnection();
cn.setConnectTimeout(5000);
cn.setRequestProperty("User-Agent", "GeyserExtras/GeyserExtras/" + GE_VERSION);
cn.setRequestProperty("User-Agent", "RealmsNetwork/GeyserPlus/" + GE_VERSION);
cn.connect();
return cn.getInputStream();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void build(BedrockForm menu, GeyserSession session, ExtrasPlayer player)
menu.add(new Label("Ping Sample: " + player.getPingSample()));
menu.add(new Label("Ping Sample Size: " + player.getPingSampleSize()));

menu.add(new SubSectionLabel("GeyserExtras Info"));
menu.add(new SubSectionLabel("GeyserPlus Info"));
menu.add(new Label("Version: " + PluginVersion.GE_VERSION));
menu.add(new Label("Server Type: " + ServerType.get()));
menu.add(new Label("Floodgate installed: " + (IsAvailable.floodgate() ? "Yes" : "No")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,48 @@
import static dev.letsgoaway.geyserextras.core.GeyserExtras.SERVER;

public class PluginVersion {
public static final String GE_VERSION = "2.1.0";
public static final String GE_VERSION = "2.2.0";

public static String latestVersion = "";
public static String latestVersionModrinthID = "";

static boolean isNewerVersion(String candidate, String current) {
List<Integer> candidateParts = numericVersion(candidate);
List<Integer> currentParts = numericVersion(current);
if (candidateParts == null || currentParts == null) {
return false;
}

int parts = Math.max(candidateParts.size(), currentParts.size());
for (int i = 0; i < parts; i++) {
int candidatePart = i < candidateParts.size() ? candidateParts.get(i) : 0;
int currentPart = i < currentParts.size() ? currentParts.get(i) : 0;
if (candidatePart != currentPart) {
return candidatePart > currentPart;
}
}
return false;
}

private static List<Integer> numericVersion(String version) {
if (version == null || version.isBlank()) {
return null;
}
String numeric = version.trim().split("[-+]", 2)[0];
if (!numeric.matches("\\d+(?:\\.\\d+)*")) {
return null;
}

List<Integer> parts = new ArrayList<>();
try {
for (String part : numeric.split("\\.")) {
parts.add(Integer.parseInt(part));
}
} catch (NumberFormatException exception) {
return null;
}
return parts;
}

public static boolean checkForUpdate() {
if (!GE.getConfig().isCheckForUpdates()) {
Expand All @@ -32,7 +69,7 @@ public static boolean checkForUpdate() {
URL url = new URL("https://api.modrinth.com/v2/project/geyserplus/version");
URLConnection request = url.openConnection();
request.setConnectTimeout(5000);
request.setRequestProperty("User-Agent", "leemwood/GeyserPlus/" + GE_VERSION);
request.setRequestProperty("User-Agent", "RealmsNetwork/GeyserPlus/" + GE_VERSION);
request.connect();
JsonElement root = JsonParser.parseReader(new InputStreamReader((InputStream) request.getContent()));

Expand All @@ -45,7 +82,7 @@ public static boolean checkForUpdate() {
if (loadersArray.contains(ServerType.type.name().toLowerCase()) || (ServerType.isExtension() && loadersArray.contains("geyser"))) {
latestVersion = version.getAsJsonObject().get("version_number").getAsString();
latestVersionModrinthID = version.getAsJsonObject().get("id").getAsString();
return !latestVersion.equals(GE_VERSION);
return isNewerVersion(latestVersion, GE_VERSION);
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package dev.letsgoaway.geyserextras.core.version;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class PluginVersionTest {
@Test
void runtimeVersionMatchesTheCurrentBuild() {
assertEquals("2.2.0", PluginVersion.GE_VERSION);
}

@Test
void identifiesOnlyNumericallyNewerReleases() {
assertTrue(PluginVersion.isNewerVersion("2.3.0", "2.2.0"));
assertTrue(PluginVersion.isNewerVersion("2.10.0", "2.9.9"));
assertTrue(PluginVersion.isNewerVersion("2.2.1", "2.2.0"));
assertFalse(PluginVersion.isNewerVersion("2.1.0", "2.2.0"));
assertFalse(PluginVersion.isNewerVersion("2.2.0", "2.2.0"));
assertFalse(PluginVersion.isNewerVersion("2.2", "2.2.0"));
}

@Test
void treatsTrailingZeroComponentsAsEquivalent() {
assertFalse(PluginVersion.isNewerVersion("2.2", "2.2.0"));
assertFalse(PluginVersion.isNewerVersion("2.2.0.0", "2.2"));
}

@Test
void safelyRejectsMalformedVersions() {
assertFalse(PluginVersion.isNewerVersion(null, "2.2.0"));
assertFalse(PluginVersion.isNewerVersion("latest", "2.2.0"));
assertFalse(PluginVersion.isNewerVersion("2.x.0", "2.2.0"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import static dev.letsgoaway.geyserextras.core.GeyserExtras.GE;

@Plugin(
authors = "LetsGoAway",
name = "GeyserExtras",
authors = "RealmsNetwork",
name = "GeyserPlus",
version = PluginVersion.GE_VERSION,
id = "geyserextras",
dependencies = {
Expand Down
Loading