From f9fd7cb831fc909ed4291a7ab9b652987952481f Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 2 Jul 2022 12:42:31 -0500 Subject: [PATCH] Fix Geyser not working in IDE --- .../java/org/geysermc/api/GeyserApiBase.java | 2 +- .../java/org/geysermc/geyser/GeyserImpl.java | 12 ++++++++-- .../command/defaults/VersionCommand.java | 2 +- .../extension/GeyserExtensionLoader.java | 22 ++++++++----------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/api/base/src/main/java/org/geysermc/api/GeyserApiBase.java b/api/base/src/main/java/org/geysermc/api/GeyserApiBase.java index bf38f58b9..e5105b1be 100644 --- a/api/base/src/main/java/org/geysermc/api/GeyserApiBase.java +++ b/api/base/src/main/java/org/geysermc/api/GeyserApiBase.java @@ -78,7 +78,7 @@ public interface GeyserApiBase { * @return the major API version. Bumped whenever a significant breaking change or feature addition is added. */ default int majorApiVersion() { - return 0; + return 1; } /** diff --git a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java index 8f3156abe..4c3cf6fca 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java @@ -116,7 +116,7 @@ public class GeyserImpl implements GeyserApi { public static final String GIT_VERSION = "${gitVersion}"; // A fallback for running in IDEs public static final String VERSION = "${version}"; // A fallback for running in IDEs - public static final int BUILD_NUMBER = Integer.parseInt("${buildNumber}"); + public static final String BUILD_NUMBER = "${buildNumber}"; public static final String BRANCH = "${branch}"; /** @@ -318,7 +318,7 @@ public class GeyserImpl implements GeyserApi { pendingMicrosoftAuthentication = new PendingMicrosoftAuthentication(config.getPendingAuthenticationTimeout()); - this.newsHandler = new NewsHandler(BRANCH, BUILD_NUMBER); + this.newsHandler = new NewsHandler(BRANCH, this.buildNumber()); CooldownUtils.setDefaultShowCooldown(config.getShowCooldown()); DimensionUtils.changeBedrockNetherId(config.isAboveBedrockNetherBuilding()); // Apply End dimension ID workaround to Nether @@ -632,6 +632,14 @@ public class GeyserImpl implements GeyserApi { return this.getConfig().getMaxPlayers(); } + public int buildNumber() { + if (!this.isProductionEnvironment()) { + return 0; + } + + return Integer.parseInt(BUILD_NUMBER); + } + public static GeyserImpl start(PlatformType platformType, GeyserBootstrap bootstrap) { if (instance == null) { return new GeyserImpl(platformType, bootstrap); diff --git a/core/src/main/java/org/geysermc/geyser/command/defaults/VersionCommand.java b/core/src/main/java/org/geysermc/geyser/command/defaults/VersionCommand.java index 9006ca959..fbe4fb4f6 100644 --- a/core/src/main/java/org/geysermc/geyser/command/defaults/VersionCommand.java +++ b/core/src/main/java/org/geysermc/geyser/command/defaults/VersionCommand.java @@ -79,7 +79,7 @@ public class VersionCommand extends GeyserCommand { URLEncoder.encode(GeyserImpl.BRANCH, StandardCharsets.UTF_8.toString()) + "/lastSuccessfulBuild/api/xml?xpath=//buildNumber"); if (buildXML.startsWith("")) { int latestBuildNum = Integer.parseInt(buildXML.replaceAll("<(\\\\)?(/)?buildNumber>", "").trim()); - int buildNum = GeyserImpl.BUILD_NUMBER; + int buildNum = this.geyser.buildNumber(); if (latestBuildNum == buildNum) { sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.no_updates", sender.locale())); } else { diff --git a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java index 137a2005e..55f018ddb 100644 --- a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java +++ b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java @@ -29,6 +29,7 @@ import it.unimi.dsi.fastutil.objects.Object2ReferenceMap; import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap; import lombok.RequiredArgsConstructor; import org.checkerframework.checker.nullness.qual.NonNull; +import org.geysermc.api.Geyser; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.event.ExtensionEventBus; import org.geysermc.geyser.api.extension.*; @@ -125,14 +126,6 @@ public class GeyserExtensionLoader extends ExtensionLoader { @Override protected void loadAllExtensions(@NonNull ExtensionManager extensionManager) { - // noinspection ConstantConditions - if (!GeyserImpl.VERSION.contains(".")) { - GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_version_number")); - return; - } - - String[] apiVersion = GeyserImpl.VERSION.split("\\."); - try { if (Files.notExists(EXTENSION_DIRECTORY)) { Files.createDirectory(EXTENSION_DIRECTORY); @@ -166,27 +159,30 @@ public class GeyserExtensionLoader extends ExtensionLoader { return; } + int majorVersion = Geyser.api().majorApiVersion(); + int minorVersion = Geyser.api().minorApiVersion(); + try { // Check the format: majorVersion.minorVersion.patch if (!API_VERSION_PATTERN.matcher(description.apiVersion()).matches()) { throw new IllegalArgumentException(); } } catch (NullPointerException | IllegalArgumentException e) { - GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_format", name, apiVersion[0] + "." + apiVersion[1])); + GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_format", name, majorVersion + "." + minorVersion)); return; } String[] versionArray = description.apiVersion().split("\\."); // Completely different API version - if (!Objects.equals(Integer.valueOf(versionArray[0]), Integer.valueOf(apiVersion[0]))) { - GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, apiVersion[0] + "." + apiVersion[1])); + if (Integer.parseInt(versionArray[0]) != majorVersion) { + GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, majorVersion + "." + minorVersion)); return; } // If the extension requires new API features, being backwards compatible - if (Integer.parseInt(versionArray[1]) > Integer.parseInt(apiVersion[1])) { - GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, apiVersion[0] + "." + apiVersion[1])); + if (Integer.parseInt(versionArray[1]) > minorVersion) { + GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, majorVersion + "." + minorVersion)); return; }