From 1ca4f6cba91b2d9c8997674ba04cf601958cbc8e Mon Sep 17 00:00:00 2001 From: powercas_gamer Date: Wed, 29 May 2024 19:09:11 +0000 Subject: [PATCH 1/8] feat: build info --- api/build.gradle.kts | 5 + .../api/util/ServerBuildInfo.java | 134 ++++++++++++++++++ build-logic/build.gradle.kts | 1 + .../kotlin/velocity-init-manifest.gradle.kts | 34 +++-- gradle/libs.versions.toml | 3 +- proxy/build.gradle.kts | 15 +- .../velocitypowered/proxy/VelocityServer.java | 4 +- .../command/builtin/VelocityCommand.java | 5 +- .../proxy/util/JarManifests.java | 64 +++++++++ .../proxy/util/ServerBuildInfoImpl.java | 126 ++++++++++++++++ 10 files changed, 369 insertions(+), 22 deletions(-) create mode 100644 api/src/main/java/com/velocitypowered/api/util/ServerBuildInfo.java create mode 100644 proxy/src/main/java/com/velocitypowered/proxy/util/JarManifests.java create mode 100644 proxy/src/main/java/com/velocitypowered/proxy/util/ServerBuildInfoImpl.java diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 2e524db9fa..24a88f6095 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -54,6 +54,11 @@ tasks { attributes["Automatic-Module-Name"] = "com.velocitypowered.api" } } + // TEMP + withType { + exclude("**/com/velocitypowered/api/util/ServerBuildInfo.java") + } + withType { exclude("com/velocitypowered/api/plugin/ap/**") diff --git a/api/src/main/java/com/velocitypowered/api/util/ServerBuildInfo.java b/api/src/main/java/com/velocitypowered/api/util/ServerBuildInfo.java new file mode 100644 index 0000000000..8c06be0b75 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/util/ServerBuildInfo.java @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2024 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.util; + +import java.time.Instant; +import java.util.Optional; +import java.util.OptionalInt; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.util.Services; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +/** + * Information about the current server build. + */ +@SuppressWarnings({"checkstyle", "CheckStyle"}) // Temporarily +@ApiStatus.NonExtendable +public interface ServerBuildInfo { + /** + * The brand id for Velocity. + */ + Key BRAND_VELOCITY_ID = Key.key("papermc", "velocity"); + + /** + * Gets the {@code ServerBuildInfo}. + * + * @return the {@code ServerBuildInfo} + */ + static @NotNull ServerBuildInfo buildInfo() { + // + /** + * This is a holder, it holds the serverbuildinfo :). + */ + final class Holder { + static final Optional INSTANCE = Services.service(ServerBuildInfo.class); + } + // + + return Holder.INSTANCE.orElseThrow(); + } + + /** + * Gets the brand id of the server. + * + * @return the brand id of the server (e.g. "papermc:velocity") + */ + @NotNull Key brandId(); + + /** + * Checks if the current server supports the specified brand. + * + * @param brandId the brand to check (e.g. "papermc:folia") + * @return {@code true} if the server supports the specified brand + */ + @ApiStatus.Experimental + boolean isBrandCompatible(final @NotNull Key brandId); + + /** + * Gets the brand name of the server. + * + * @return the brand name of the server (e.g. "Velocity") + */ + @NotNull String brandName(); + + +// /** +// * Gets the Velocity version id. +// * +// * @return the Velocity version id (e.g. "3.3.0-SNAPSHOT", "3.3.0", "3.0.0") +// */ +// @NotNull String velocityVersionId(); + + /** + * Gets the Velocity version name. + * + * @return the Velocity version name (e.g. "3.3.0 Snapshot", "3.3.0", "3.0.0") + */ + @NotNull String velocityVersionName(); + + /** + * Gets the build number. + * + * @return the build number + */ + @NotNull OptionalInt buildNumber(); + + /** + * Gets the build time. + * + * @return the build time + */ + @NotNull Instant buildTime(); + + /** + * Gets the git commit branch. + * + * @return the git commit branch + */ + @NotNull Optional gitBranch(); + + /** + * Gets the git commit hash. + * + * @return the git commit hash + */ + @NotNull Optional gitCommit(); + + /** + * Creates a string representation of the server build information. + * + * @param representation the type of representation + * @return a string + */ + @NotNull String asString(final @NotNull StringRepresentation representation); + + /** + * String representation types. + */ + enum StringRepresentation { + /** + * A simple version string, in format {@code --}. + */ + VERSION_SIMPLE, + /** + * A simple version string, in format {@code --@ ()}. + */ + VERSION_FULL, + } +} diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 26af276248..ce881ea954 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -8,6 +8,7 @@ dependencies { // see https://github.com/gradle/gradle/issues/15383#issuecomment-779893192 implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) implementation("com.diffplug.spotless:spotless-plugin-gradle:${libs.plugins.spotless.get().version}") + implementation("net.kyori:indra-git:${libs.versions.indra.get()}") } spotless { diff --git a/build-logic/src/main/kotlin/velocity-init-manifest.gradle.kts b/build-logic/src/main/kotlin/velocity-init-manifest.gradle.kts index 1901430f57..c64eed3d9f 100644 --- a/build-logic/src/main/kotlin/velocity-init-manifest.gradle.kts +++ b/build-logic/src/main/kotlin/velocity-init-manifest.gradle.kts @@ -1,29 +1,41 @@ +import net.kyori.indra.git.IndraGitExtension import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.withType -import java.io.ByteArrayOutputStream +import java.time.Instant -val currentShortRevision = ByteArrayOutputStream().use { - exec { - executable = "git" - args = listOf("rev-parse", "HEAD") - standardOutput = it - } - it.toString().trim().substring(0, 8) +plugins { + id("net.kyori.indra.git") } tasks.withType { manifest { + val indraGit = project.extensions.getByType(IndraGitExtension::class.java) val buildNumber = System.getenv("BUILD_NUMBER") + val gitHash = indraGit.commit()?.name?.substring(0, 8) ?: "unknown" + val gitBranch = indraGit.branchName() ?: "unknown" + val velocityVersion = project.version.toString() + val implementationVersion = "$velocityVersion-${buildNumber ?: "DEV"}-$gitHash" val velocityHumanVersion: String = if (project.version.toString().endsWith("-SNAPSHOT")) { if (buildNumber == null) { - "${project.version} (git-$currentShortRevision)" + "${project.version} (git-$gitHash)" } else { - "${project.version} (git-$currentShortRevision-b$buildNumber)" + "${project.version} (git-$gitHash-b$buildNumber)" } } else { archiveVersion.get() } - attributes["Implementation-Version"] = velocityHumanVersion + attributes["Implementation-Title"] = "Velocity" + attributes["Implementation-Vendor"] = "Velocity Contributors" + attributes["Multi-Release"] = "true" + attributes["Specification-Version"] = velocityHumanVersion + attributes["Implementation-Version"] = velocityVersion + attributes["Brand-Id"] = "papermc:velocity" + attributes["Brand-Name"] = "Velocity" + attributes["Build-Number"] = (buildNumber ?: "") + attributes["Build-Time"] = Instant.now().toString() + attributes["Git-Branch"] = gitBranch + attributes["Git-Commit"] = gitHash + attributes["Full-Version"] = implementationVersion } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 510c4d62a8..db4150c741 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,11 +4,12 @@ configurate4 = "4.1.2" flare = "2.0.1" log4j = "2.22.1" netty = "4.1.106.Final" +indra = "3.1.3" [plugins] -indra-publishing = "net.kyori.indra.publishing:2.0.6" shadow = "io.github.goooler.shadow:8.1.5" spotless = "com.diffplug.spotless:6.25.0" +indra-git = { id = "net.kyori.indra.git", version.ref = "indra" } [libraries] adventure-bom = "net.kyori:adventure-bom:4.17.0" diff --git a/proxy/build.gradle.kts b/proxy/build.gradle.kts index 5e1387b06c..06c45d23ad 100644 --- a/proxy/build.gradle.kts +++ b/proxy/build.gradle.kts @@ -1,4 +1,6 @@ import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer +import net.kyori.indra.git.IndraGitExtension +import java.time.Instant plugins { application @@ -12,18 +14,15 @@ application { } tasks { + runShadow { + systemProperty("terminal.jline", false) + systemProperty("terminal.ansi", true) + workingDir = project.file("run").also(File::mkdirs) + } withType { exclude("**/com/velocitypowered/proxy/protocol/packet/**") } - jar { - manifest { - attributes["Implementation-Title"] = "Velocity" - attributes["Implementation-Vendor"] = "Velocity Contributors" - attributes["Multi-Release"] = "true" - } - } - shadowJar { transform(Log4j2PluginsCacheFileTransformer::class.java) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 0042436169..6fd8bb0052 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -36,6 +36,7 @@ import com.velocitypowered.api.util.Favicon; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.ProxyVersion; +import com.velocitypowered.api.util.ServerBuildInfo; import com.velocitypowered.proxy.command.VelocityCommandManager; import com.velocitypowered.proxy.command.builtin.CallbackCommand; import com.velocitypowered.proxy.command.builtin.GlistCommand; @@ -211,7 +212,8 @@ void awaitProxyShutdown() { @EnsuresNonNull({"serverKeyPair", "servers", "pluginManager", "eventManager", "scheduler", "console", "cm", "configuration"}) void start() { - logger.info("Booting up {} {}...", getVersion().getName(), getVersion().getVersion()); + final ServerBuildInfo buildInfo = ServerBuildInfo.buildInfo(); + logger.info("Booting up {} {}...", getVersion().getName(), buildInfo.asString(ServerBuildInfo.StringRepresentation.VERSION_FULL)); console.setupStreams(); registerTranslations(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java index 79ac41e74e..6ee7ad6ef1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java @@ -33,6 +33,7 @@ import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.util.ProxyVersion; +import com.velocitypowered.api.util.ServerBuildInfo; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.util.InformationUtils; import java.io.BufferedWriter; @@ -154,13 +155,15 @@ private record Info(ProxyServer server) implements Command { public int run(final CommandContext context) { final CommandSource source = context.getSource(); final ProxyVersion version = server.getVersion(); + final ServerBuildInfo build = ServerBuildInfo.buildInfo(); + final Component velocity = Component.text() .content(version.getName() + " ") .decoration(TextDecoration.BOLD, true) .color(VELOCITY_COLOR) .append(Component.text() - .content(version.getVersion()) + .content(build.asString(ServerBuildInfo.StringRepresentation.VERSION_FULL)) .decoration(TextDecoration.BOLD, false)) .build(); final Component copyright = Component diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/JarManifests.java b/proxy/src/main/java/com/velocitypowered/proxy/util/JarManifests.java new file mode 100644 index 0000000000..b9e3dccdf1 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/JarManifests.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2024 Velocity Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.velocitypowered.proxy.util; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Collections; +import java.util.Map; +import java.util.WeakHashMap; +import java.util.jar.Manifest; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * This is the jar manifest class. + * It does manifest stuff. + */ +@ApiStatus.Internal +public final class JarManifests { + private JarManifests() { + } + + private static final Map MANIFESTS = Collections.synchronizedMap(new WeakHashMap<>()); + + /** + * Manifest. It gets a manifest from a jar. + * + * @param clazz the CLASS. + * @return the manifest or null. + */ + public static @Nullable Manifest manifest(final @NotNull Class clazz) { + return MANIFESTS.computeIfAbsent(clazz.getClassLoader(), classLoader -> { + final String classLocation = "/" + clazz.getName().replace(".", "/") + ".class"; + final URL resource = clazz.getResource(classLocation); + if (resource == null) { + return null; + } + final String classFilePath = resource.toString().replace("\\", "/"); + final String archivePath = classFilePath.substring(0, classFilePath.length() - classLocation.length()); + try (final InputStream stream = new URL(archivePath + "/META-INF/MANIFEST.MF").openStream()) { + return new Manifest(stream); + } catch (final IOException ex) { + return null; + } + }); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/ServerBuildInfoImpl.java b/proxy/src/main/java/com/velocitypowered/proxy/util/ServerBuildInfoImpl.java new file mode 100644 index 0000000000..c96c9926e5 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/ServerBuildInfoImpl.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2024 Velocity Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.velocitypowered.proxy.util; + +import com.google.auto.service.AutoService; +import com.google.common.base.Strings; +import com.velocitypowered.api.util.ServerBuildInfo; +import com.velocitypowered.proxy.VelocityServer; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.Optional; +import java.util.OptionalInt; +import java.util.jar.Manifest; +import net.kyori.adventure.key.Key; +import org.jetbrains.annotations.NotNull; + +/** + * This is internal it does not need a javadoc CHECKSTYLE. + */ +@AutoService(ServerBuildInfo.class) +public record ServerBuildInfoImpl( + Key brandId, + String brandName, + /*String velocityVersionId,*/ + String velocityVersionName, + OptionalInt buildNumber, + Instant buildTime, + Optional gitBranch, + Optional gitCommit +) implements ServerBuildInfo { + private static final String ATTRIBUTE_BRAND_ID = "Brand-Id"; + private static final String ATTRIBUTE_BRAND_NAME = "Brand-Name"; + private static final String ATTRIBUTE_BUILD_TIME = "Build-Time"; + private static final String ATTRIBUTE_BUILD_NUMBER = "Build-Number"; + private static final String ATTRIBUTE_GIT_BRANCH = "Git-Branch"; + private static final String ATTRIBUTE_GIT_COMMIT = "Git-Commit"; + private static final String ATTRIBUTE_VERSION = "Implementation-Version"; + + private static final String BRAND_PAPER_NAME = "Velocity"; + + private static final String BUILD_DEV = "DEV"; + + public ServerBuildInfoImpl() { + this(JarManifests.manifest(VelocityServer.class)); + } + + private ServerBuildInfoImpl(final Manifest manifest) { + this( + getManifestAttribute(manifest, ATTRIBUTE_BRAND_ID) + .map(Key::key) + .orElse(BRAND_VELOCITY_ID), + getManifestAttribute(manifest, ATTRIBUTE_BRAND_NAME) + .orElse(BRAND_PAPER_NAME), + getManifestAttribute(manifest, ATTRIBUTE_VERSION) + .orElse("Unknown"), + getManifestAttribute(manifest, ATTRIBUTE_BUILD_NUMBER) + .map(Integer::parseInt) + .map(OptionalInt::of) + .orElse(OptionalInt.empty()), + getManifestAttribute(manifest, ATTRIBUTE_BUILD_TIME) + .map(Instant::parse) + .orElse(Instant.now()), + getManifestAttribute(manifest, ATTRIBUTE_GIT_BRANCH), + getManifestAttribute(manifest, ATTRIBUTE_GIT_COMMIT) + ); + } + + @Override + public boolean isBrandCompatible(final @NotNull Key brandId) { + return brandId.equals(this.brandId); + } + + @Override + public @NotNull String asString(final @NotNull StringRepresentation representation) { + final StringBuilder sb = new StringBuilder(); + sb.append(this.velocityVersionName); + if (this.buildNumber.isPresent()) { + sb.append('-'); // eh + sb.append(this.buildNumber.getAsInt()); + } else if (!this.velocityVersionName.contains("-SNAPSHOT")) { + sb.append('-'); // eh + sb.append(BUILD_DEV); + } + final boolean hasGitBranch = this.gitBranch.isPresent(); + final boolean hasGitCommit = this.gitCommit.isPresent(); + if (hasGitBranch || hasGitCommit) { + sb.append('-'); + } + if (hasGitBranch && representation == StringRepresentation.VERSION_FULL) { + sb.append(this.gitBranch.get()); + if (hasGitCommit) { + sb.append('@'); + } + } + if (hasGitCommit) { + sb.append(this.gitCommit.get()); + } + if (representation == StringRepresentation.VERSION_FULL) { + sb.append(' '); + sb.append('('); + sb.append(this.buildTime.truncatedTo(ChronoUnit.SECONDS)); + sb.append(')'); + } + return sb.toString(); + } + + private static Optional getManifestAttribute(final Manifest manifest, final String name) { + final String value = manifest != null ? manifest.getMainAttributes().getValue(name) : null; + return Optional.ofNullable(Strings.emptyToNull(value)); + } +} From fefd62e7385e08f4c551c25e03501edba650b599 Mon Sep 17 00:00:00 2001 From: powercas_gamer Date: Wed, 29 May 2024 22:54:45 +0000 Subject: [PATCH 2/8] paper -> velocity --- proxy/build.gradle.kts | 5 +---- .../com/velocitypowered/proxy/util/ServerBuildInfoImpl.java | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/proxy/build.gradle.kts b/proxy/build.gradle.kts index 06c45d23ad..c3b58630cc 100644 --- a/proxy/build.gradle.kts +++ b/proxy/build.gradle.kts @@ -1,6 +1,4 @@ import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer -import net.kyori.indra.git.IndraGitExtension -import java.time.Instant plugins { application @@ -15,10 +13,9 @@ application { tasks { runShadow { - systemProperty("terminal.jline", false) - systemProperty("terminal.ansi", true) workingDir = project.file("run").also(File::mkdirs) } + withType { exclude("**/com/velocitypowered/proxy/protocol/packet/**") } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/ServerBuildInfoImpl.java b/proxy/src/main/java/com/velocitypowered/proxy/util/ServerBuildInfoImpl.java index c96c9926e5..0f769cbb9f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/ServerBuildInfoImpl.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/ServerBuildInfoImpl.java @@ -51,7 +51,7 @@ public record ServerBuildInfoImpl( private static final String ATTRIBUTE_GIT_COMMIT = "Git-Commit"; private static final String ATTRIBUTE_VERSION = "Implementation-Version"; - private static final String BRAND_PAPER_NAME = "Velocity"; + private static final String BRAND_VELOCITY_NAME = "Velocity"; private static final String BUILD_DEV = "DEV"; @@ -65,7 +65,7 @@ private ServerBuildInfoImpl(final Manifest manifest) { .map(Key::key) .orElse(BRAND_VELOCITY_ID), getManifestAttribute(manifest, ATTRIBUTE_BRAND_NAME) - .orElse(BRAND_PAPER_NAME), + .orElse(BRAND_VELOCITY_NAME), getManifestAttribute(manifest, ATTRIBUTE_VERSION) .orElse("Unknown"), getManifestAttribute(manifest, ATTRIBUTE_BUILD_NUMBER) From 713f3df14d9ecf16a437f1978d0d8220bacff71c Mon Sep 17 00:00:00 2001 From: powercas_gamer Date: Thu, 30 May 2024 18:20:09 +0000 Subject: [PATCH 3/8] Separate concept --- api/build.gradle.kts | 2 +- .../util/buildinfo/PaperServerBuildInfo.java | 35 +++++++++++++++ .../util/{ => buildinfo}/ServerBuildInfo.java | 27 +++--------- .../buildinfo/VelocityServerBuildInfo.java | 43 +++++++++++++++++++ .../velocitypowered/proxy/VelocityServer.java | 2 +- .../command/builtin/VelocityCommand.java | 2 +- .../{ => buildinfo}/ServerBuildInfoImpl.java | 14 +++--- 7 files changed, 95 insertions(+), 30 deletions(-) create mode 100644 api/src/main/java/com/velocitypowered/api/util/buildinfo/PaperServerBuildInfo.java rename api/src/main/java/com/velocitypowered/api/util/{ => buildinfo}/ServerBuildInfo.java (77%) create mode 100644 api/src/main/java/com/velocitypowered/api/util/buildinfo/VelocityServerBuildInfo.java rename proxy/src/main/java/com/velocitypowered/proxy/util/{ => buildinfo}/ServerBuildInfoImpl.java (90%) diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 24a88f6095..1cf1e13a38 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -56,7 +56,7 @@ tasks { } // TEMP withType { - exclude("**/com/velocitypowered/api/util/ServerBuildInfo.java") + exclude("**/com/velocitypowered/api/util/buildinfo/*ServerBuildInfo.java") } withType { diff --git a/api/src/main/java/com/velocitypowered/api/util/buildinfo/PaperServerBuildInfo.java b/api/src/main/java/com/velocitypowered/api/util/buildinfo/PaperServerBuildInfo.java new file mode 100644 index 0000000000..813aee3a1d --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/util/buildinfo/PaperServerBuildInfo.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.util.buildinfo; + +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +/** + * Information about the current server build. + * + * @apiNote to be seperated later + */ +@SuppressWarnings({"checkstyle", "CheckStyle"}) // Temporarily +@ApiStatus.NonExtendable +public interface PaperServerBuildInfo extends ServerBuildInfo { + + /** + * Gets the Minecraft version id. + * + * @return the Minecraft version id (e.g. "1.20.4", "1.20.2-pre2", "23w31a") + */ + @NotNull String minecraftVersionId(); + + /** + * Gets the Minecraft version name. + * + * @return the Minecraft version name (e.g. "1.20.4", "1.20.2 Pre-release 2", "23w31a") + */ + @NotNull String minecraftVersionName(); +} diff --git a/api/src/main/java/com/velocitypowered/api/util/ServerBuildInfo.java b/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java similarity index 77% rename from api/src/main/java/com/velocitypowered/api/util/ServerBuildInfo.java rename to api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java index 8c06be0b75..17628e3449 100644 --- a/api/src/main/java/com/velocitypowered/api/util/ServerBuildInfo.java +++ b/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java @@ -5,7 +5,7 @@ * reference the LICENSE file in the api top-level directory. */ -package com.velocitypowered.api.util; +package com.velocitypowered.api.util.buildinfo; import java.time.Instant; import java.util.Optional; @@ -17,14 +17,12 @@ /** * Information about the current server build. + * + * @apiNote to be seperated later */ @SuppressWarnings({"checkstyle", "CheckStyle"}) // Temporarily @ApiStatus.NonExtendable public interface ServerBuildInfo { - /** - * The brand id for Velocity. - */ - Key BRAND_VELOCITY_ID = Key.key("papermc", "velocity"); /** * Gets the {@code ServerBuildInfo}. @@ -67,21 +65,6 @@ final class Holder { */ @NotNull String brandName(); - -// /** -// * Gets the Velocity version id. -// * -// * @return the Velocity version id (e.g. "3.3.0-SNAPSHOT", "3.3.0", "3.0.0") -// */ -// @NotNull String velocityVersionId(); - - /** - * Gets the Velocity version name. - * - * @return the Velocity version name (e.g. "3.3.0 Snapshot", "3.3.0", "3.0.0") - */ - @NotNull String velocityVersionName(); - /** * Gets the build number. * @@ -123,11 +106,11 @@ final class Holder { */ enum StringRepresentation { /** - * A simple version string, in format {@code --}. + * A simple version string, in format {@code --}. */ VERSION_SIMPLE, /** - * A simple version string, in format {@code --@ ()}. + * A simple version string, in format {@code --@ ()}. */ VERSION_FULL, } diff --git a/api/src/main/java/com/velocitypowered/api/util/buildinfo/VelocityServerBuildInfo.java b/api/src/main/java/com/velocitypowered/api/util/buildinfo/VelocityServerBuildInfo.java new file mode 100644 index 0000000000..66050e00c6 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/util/buildinfo/VelocityServerBuildInfo.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2024 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.util.buildinfo; + +import net.kyori.adventure.key.Key; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +/** + * Information about the current server build. + * + * @apiNote to be seperated later + */ +@SuppressWarnings({"checkstyle", "CheckStyle"}) // Temporarily +@ApiStatus.NonExtendable +public interface VelocityServerBuildInfo extends ServerBuildInfo { + + /** + * The brand id for Velocity. + */ + Key BRAND_VELOCITY_ID = Key.key("papermc", "velocity"); + + /** + * Gets the Velocity version id. + * + * @return the Velocity version id (e.g. "3.3.0-SNAPSHOT", "3.3.0", "3.0.0") + */ + @NotNull + String velocityVersionId(); + // one of these can probably go + /** + * Gets the Velocity version name. + * + * @return the Velocity version name (e.g. "3.3.0 Snapshot", "3.3.0", "3.0.0") + */ + @NotNull + String velocityVersionName(); +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 6fd8bb0052..3e70da6577 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -36,7 +36,7 @@ import com.velocitypowered.api.util.Favicon; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.ProxyVersion; -import com.velocitypowered.api.util.ServerBuildInfo; +import com.velocitypowered.api.util.buildinfo.ServerBuildInfo; import com.velocitypowered.proxy.command.VelocityCommandManager; import com.velocitypowered.proxy.command.builtin.CallbackCommand; import com.velocitypowered.proxy.command.builtin.GlistCommand; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java index 6ee7ad6ef1..e75eb757db 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java @@ -33,7 +33,7 @@ import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.util.ProxyVersion; -import com.velocitypowered.api.util.ServerBuildInfo; +import com.velocitypowered.api.util.buildinfo.ServerBuildInfo; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.util.InformationUtils; import java.io.BufferedWriter; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/ServerBuildInfoImpl.java b/proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java similarity index 90% rename from proxy/src/main/java/com/velocitypowered/proxy/util/ServerBuildInfoImpl.java rename to proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java index 0f769cbb9f..9f642f6113 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/ServerBuildInfoImpl.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java @@ -15,12 +15,14 @@ * along with this program. If not, see . */ -package com.velocitypowered.proxy.util; +package com.velocitypowered.proxy.util.buildinfo; import com.google.auto.service.AutoService; import com.google.common.base.Strings; -import com.velocitypowered.api.util.ServerBuildInfo; +import com.velocitypowered.api.util.buildinfo.ServerBuildInfo; +import com.velocitypowered.api.util.buildinfo.VelocityServerBuildInfo; import com.velocitypowered.proxy.VelocityServer; +import com.velocitypowered.proxy.util.JarManifests; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.Optional; @@ -36,13 +38,13 @@ public record ServerBuildInfoImpl( Key brandId, String brandName, - /*String velocityVersionId,*/ + String velocityVersionId, String velocityVersionName, OptionalInt buildNumber, Instant buildTime, Optional gitBranch, Optional gitCommit -) implements ServerBuildInfo { +) implements VelocityServerBuildInfo { private static final String ATTRIBUTE_BRAND_ID = "Brand-Id"; private static final String ATTRIBUTE_BRAND_NAME = "Brand-Name"; private static final String ATTRIBUTE_BUILD_TIME = "Build-Time"; @@ -67,7 +69,9 @@ private ServerBuildInfoImpl(final Manifest manifest) { getManifestAttribute(manifest, ATTRIBUTE_BRAND_NAME) .orElse(BRAND_VELOCITY_NAME), getManifestAttribute(manifest, ATTRIBUTE_VERSION) - .orElse("Unknown"), + .orElse("VersionId"), + getManifestAttribute(manifest, ATTRIBUTE_VERSION) + .orElse("VersionName"), getManifestAttribute(manifest, ATTRIBUTE_BUILD_NUMBER) .map(Integer::parseInt) .map(OptionalInt::of) From b59a5b4027c619075c52f247171fdeed0eee9307 Mon Sep 17 00:00:00 2001 From: powercas_gamer Date: Thu, 30 May 2024 19:18:47 +0000 Subject: [PATCH 4/8] 'fix' return type --- .../api/util/buildinfo/PaperServerBuildInfo.java | 8 +++++++- .../api/util/buildinfo/ServerBuildInfo.java | 6 +++--- .../api/util/buildinfo/VelocityServerBuildInfo.java | 2 +- .../java/com/velocitypowered/proxy/VelocityServer.java | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/util/buildinfo/PaperServerBuildInfo.java b/api/src/main/java/com/velocitypowered/api/util/buildinfo/PaperServerBuildInfo.java index 813aee3a1d..2c3cf26a76 100644 --- a/api/src/main/java/com/velocitypowered/api/util/buildinfo/PaperServerBuildInfo.java +++ b/api/src/main/java/com/velocitypowered/api/util/buildinfo/PaperServerBuildInfo.java @@ -7,18 +7,24 @@ package com.velocitypowered.api.util.buildinfo; +import net.kyori.adventure.key.Key; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; /** * Information about the current server build. * - * @apiNote to be seperated later + * @apiNote to be separated later */ @SuppressWarnings({"checkstyle", "CheckStyle"}) // Temporarily @ApiStatus.NonExtendable public interface PaperServerBuildInfo extends ServerBuildInfo { + /** + * The brand id for Paper. + */ + Key BRAND_PAPER_ID = Key.key("papermc", "paper"); + /** * Gets the Minecraft version id. * diff --git a/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java b/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java index 17628e3449..4a87b249d2 100644 --- a/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java +++ b/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java @@ -18,7 +18,7 @@ /** * Information about the current server build. * - * @apiNote to be seperated later + * @apiNote to be separated later */ @SuppressWarnings({"checkstyle", "CheckStyle"}) // Temporarily @ApiStatus.NonExtendable @@ -29,7 +29,7 @@ public interface ServerBuildInfo { * * @return the {@code ServerBuildInfo} */ - static @NotNull ServerBuildInfo buildInfo() { + static @NotNull T buildInfo() { // /** * This is a holder, it holds the serverbuildinfo :). @@ -39,7 +39,7 @@ final class Holder { } // - return Holder.INSTANCE.orElseThrow(); + return (T) Holder.INSTANCE.orElseThrow(); } /** diff --git a/api/src/main/java/com/velocitypowered/api/util/buildinfo/VelocityServerBuildInfo.java b/api/src/main/java/com/velocitypowered/api/util/buildinfo/VelocityServerBuildInfo.java index 66050e00c6..936eff4404 100644 --- a/api/src/main/java/com/velocitypowered/api/util/buildinfo/VelocityServerBuildInfo.java +++ b/api/src/main/java/com/velocitypowered/api/util/buildinfo/VelocityServerBuildInfo.java @@ -14,7 +14,7 @@ /** * Information about the current server build. * - * @apiNote to be seperated later + * @apiNote to be separated later */ @SuppressWarnings({"checkstyle", "CheckStyle"}) // Temporarily @ApiStatus.NonExtendable diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 3e70da6577..6be347a195 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -37,6 +37,7 @@ import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.ProxyVersion; import com.velocitypowered.api.util.buildinfo.ServerBuildInfo; +import com.velocitypowered.api.util.buildinfo.VelocityServerBuildInfo; import com.velocitypowered.proxy.command.VelocityCommandManager; import com.velocitypowered.proxy.command.builtin.CallbackCommand; import com.velocitypowered.proxy.command.builtin.GlistCommand; From 6a60e9a1cfece016424c2de35606766abf7ace79 Mon Sep 17 00:00:00 2001 From: powercas_gamer Date: Thu, 30 May 2024 21:18:25 +0000 Subject: [PATCH 5/8] more testing --- .../api/util/buildinfo/ServerBuildInfo.java | 1 + .../src/main/kotlin/velocity-init-manifest.gradle.kts | 4 ++-- .../java/com/velocitypowered/proxy/VelocityServer.java | 1 - .../proxy/util/buildinfo/ServerBuildInfoImpl.java | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java b/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java index 4a87b249d2..df60a8c6eb 100644 --- a/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java +++ b/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java @@ -29,6 +29,7 @@ public interface ServerBuildInfo { * * @return the {@code ServerBuildInfo} */ + // TODO: This works but, I have no clue if this is correct codewise static @NotNull T buildInfo() { // /** diff --git a/build-logic/src/main/kotlin/velocity-init-manifest.gradle.kts b/build-logic/src/main/kotlin/velocity-init-manifest.gradle.kts index c64eed3d9f..024272df8e 100644 --- a/build-logic/src/main/kotlin/velocity-init-manifest.gradle.kts +++ b/build-logic/src/main/kotlin/velocity-init-manifest.gradle.kts @@ -14,6 +14,7 @@ tasks.withType { val gitHash = indraGit.commit()?.name?.substring(0, 8) ?: "unknown" val gitBranch = indraGit.branchName() ?: "unknown" val velocityVersion = project.version.toString() + val velocityVersionButWithoutTheDashSnapshot = velocityVersion.replace("-SNAPSHOT", "") val implementationVersion = "$velocityVersion-${buildNumber ?: "DEV"}-$gitHash" val velocityHumanVersion: String = if (project.version.toString().endsWith("-SNAPSHOT")) { @@ -29,13 +30,12 @@ tasks.withType { attributes["Implementation-Vendor"] = "Velocity Contributors" attributes["Multi-Release"] = "true" attributes["Specification-Version"] = velocityHumanVersion - attributes["Implementation-Version"] = velocityVersion + attributes["Implementation-Version"] = velocityVersionButWithoutTheDashSnapshot attributes["Brand-Id"] = "papermc:velocity" attributes["Brand-Name"] = "Velocity" attributes["Build-Number"] = (buildNumber ?: "") attributes["Build-Time"] = Instant.now().toString() attributes["Git-Branch"] = gitBranch attributes["Git-Commit"] = gitHash - attributes["Full-Version"] = implementationVersion } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 6be347a195..3e70da6577 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -37,7 +37,6 @@ import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.ProxyVersion; import com.velocitypowered.api.util.buildinfo.ServerBuildInfo; -import com.velocitypowered.api.util.buildinfo.VelocityServerBuildInfo; import com.velocitypowered.proxy.command.VelocityCommandManager; import com.velocitypowered.proxy.command.builtin.CallbackCommand; import com.velocitypowered.proxy.command.builtin.GlistCommand; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java b/proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java index 9f642f6113..3f3117e971 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java @@ -93,11 +93,11 @@ public boolean isBrandCompatible(final @NotNull Key brandId) { public @NotNull String asString(final @NotNull StringRepresentation representation) { final StringBuilder sb = new StringBuilder(); sb.append(this.velocityVersionName); - if (this.buildNumber.isPresent()) { - sb.append('-'); // eh - sb.append(this.buildNumber.getAsInt()); - } else if (!this.velocityVersionName.contains("-SNAPSHOT")) { - sb.append('-'); // eh + sb.append('-'); + final OptionalInt buildNumber = this.buildNumber; + if (buildNumber.isPresent()) { + sb.append(buildNumber.getAsInt()); + } else { sb.append(BUILD_DEV); } final boolean hasGitBranch = this.gitBranch.isPresent(); From a0abd7faaf6084ebadcc5bed2ef8c0c6be8abc9b Mon Sep 17 00:00:00 2001 From: powercas_gamer Date: Thu, 30 May 2024 21:43:00 +0000 Subject: [PATCH 6/8] adventure --- .../api/util/buildinfo/ServerBuildInfo.java | 5 ++ .../command/builtin/VelocityCommand.java | 2 +- .../util/buildinfo/ServerBuildInfoImpl.java | 55 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java b/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java index df60a8c6eb..4e485a168c 100644 --- a/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java +++ b/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java @@ -11,6 +11,7 @@ import java.util.Optional; import java.util.OptionalInt; import net.kyori.adventure.key.Key; +import net.kyori.adventure.text.Component; import net.kyori.adventure.util.Services; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -100,8 +101,12 @@ final class Holder { * @param representation the type of representation * @return a string */ + // This *could* be a PlainTextSerializer string of asComponent()? @NotNull String asString(final @NotNull StringRepresentation representation); + @NotNull + default Component asComponent(final @NotNull StringRepresentation representation) { return Component.empty(); } + /** * String representation types. */ diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java index e75eb757db..6ca7d5e420 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java @@ -163,7 +163,7 @@ public int run(final CommandContext context) { .decoration(TextDecoration.BOLD, true) .color(VELOCITY_COLOR) .append(Component.text() - .content(build.asString(ServerBuildInfo.StringRepresentation.VERSION_FULL)) + .append(build.asComponent(ServerBuildInfo.StringRepresentation.VERSION_FULL)) .decoration(TextDecoration.BOLD, false)) .build(); final Component copyright = Component diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java b/proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java index 3f3117e971..b99493738d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java @@ -17,6 +17,8 @@ package com.velocitypowered.proxy.util.buildinfo; +import static net.kyori.adventure.text.Component.text; + import com.google.auto.service.AutoService; import com.google.common.base.Strings; import com.velocitypowered.api.util.buildinfo.ServerBuildInfo; @@ -29,6 +31,9 @@ import java.util.OptionalInt; import java.util.jar.Manifest; import net.kyori.adventure.key.Key; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.event.ClickEvent; import org.jetbrains.annotations.NotNull; /** @@ -123,6 +128,56 @@ public boolean isBrandCompatible(final @NotNull Key brandId) { return sb.toString(); } + @Override + public @NotNull Component asComponent(final @NotNull StringRepresentation representation) { + final TextComponent.Builder sb = text(); + sb.append(text(this.velocityVersionName)); + sb.append(text('-')); + final OptionalInt buildNumber = this.buildNumber; + if (buildNumber.isPresent()) { + sb.append(text(buildNumber.getAsInt())); + } else { + sb.append(text(BUILD_DEV)); + } + final boolean hasGitBranch = this.gitBranch.isPresent(); + final boolean hasGitCommit = this.gitCommit.isPresent(); + if (hasGitBranch || hasGitCommit) { + sb.append(text('-')); + } + if (hasGitBranch && representation == StringRepresentation.VERSION_FULL) { + // In theory, you could add a link to the branch, but that wouldn't work for local branches but would that really matter though? + // Could also just not do that if the buildNumber is not present (or if DEV) is in the string + if (buildNumber.isPresent()) { + sb.append(text() + .content(this.gitBranch.get()) + .clickEvent(ClickEvent.openUrl( + "https://github.com/" + this.brandId.namespace() + "/" + this.brandId.value() + "/tree/" + this.gitBranch.get() + )) + ); + } else { + sb.append(text(this.gitBranch.get())); + } + if (hasGitCommit) { + sb.append(text('@')); + } + } + if (hasGitCommit) { + sb.append(text() + .content(this.gitCommit.get()) + .clickEvent(ClickEvent.openUrl( + "https://github.com/" + this.brandId.namespace() + "/" + this.brandId.value() + "/commit/" + this.gitCommit.get() + )) + ); + } + if (representation == StringRepresentation.VERSION_FULL) { + sb.append(text(' ')); + sb.append(text('(')); + sb.append(text(this.buildTime.truncatedTo(ChronoUnit.SECONDS).toString())); + sb.append(text(')')); + } + return sb.build(); + } + private static Optional getManifestAttribute(final Manifest manifest, final String name) { final String value = manifest != null ? manifest.getMainAttributes().getValue(name) : null; return Optional.ofNullable(Strings.emptyToNull(value)); From 880d837d237d255e762eaf41746d0357f39b6e75 Mon Sep 17 00:00:00 2001 From: powercas_gamer Date: Fri, 31 May 2024 13:28:21 +0000 Subject: [PATCH 7/8] ProxyVersion --- .../main/java/com/velocitypowered/proxy/VelocityServer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 3e70da6577..aecb3cfcfa 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -183,7 +183,9 @@ public VelocityConfiguration getConfiguration() { @Override public ProxyVersion getVersion() { + // TODO: this can likely also be changed to ServerBuildInfo Package pkg = VelocityServer.class.getPackage(); + final ServerBuildInfo buildInfo = ServerBuildInfo.buildInfo(); String implName; String implVersion; String implVendor; @@ -197,7 +199,7 @@ public ProxyVersion getVersion() { implVendor = "Velocity Contributors"; } - return new ProxyVersion(implName, implVendor, implVersion); + return new ProxyVersion(buildInfo.brandName(), implVendor, implVersion); } @Override From 591af5537b3500e99536c284efe8092738ae7645 Mon Sep 17 00:00:00 2001 From: powercas_gamer Date: Fri, 31 May 2024 23:38:12 +0000 Subject: [PATCH 8/8] slightly different javadoc --- .../api/util/buildinfo/ServerBuildInfo.java | 8 +++-- .../proxy/util/JarManifests.java | 7 ++-- .../util/buildinfo/ServerBuildInfoImpl.java | 36 +------------------ 3 files changed, 9 insertions(+), 42 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java b/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java index 4e485a168c..f4505aee2a 100644 --- a/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java +++ b/api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java @@ -12,6 +12,7 @@ import java.util.OptionalInt; import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.kyori.adventure.util.Services; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -102,10 +103,11 @@ final class Holder { * @return a string */ // This *could* be a PlainTextSerializer string of asComponent()? - @NotNull String asString(final @NotNull StringRepresentation representation); + @NotNull default String asString(final @NotNull StringRepresentation representation) { + return PlainTextComponentSerializer.plainText().serialize(asComponent(representation)); + } - @NotNull - default Component asComponent(final @NotNull StringRepresentation representation) { return Component.empty(); } + @NotNull Component asComponent(final @NotNull StringRepresentation representation); /** * String representation types. diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/JarManifests.java b/proxy/src/main/java/com/velocitypowered/proxy/util/JarManifests.java index b9e3dccdf1..8c8e61e630 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/JarManifests.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/JarManifests.java @@ -29,8 +29,7 @@ import org.jetbrains.annotations.Nullable; /** - * This is the jar manifest class. - * It does manifest stuff. + * Internal class that is able to do {@link Manifest} stuff. */ @ApiStatus.Internal public final class JarManifests { @@ -40,9 +39,9 @@ private JarManifests() { private static final Map MANIFESTS = Collections.synchronizedMap(new WeakHashMap<>()); /** - * Manifest. It gets a manifest from a jar. + * Gets the {@link Manifest} from a class. * - * @param clazz the CLASS. + * @param clazz the class to get the {@link Manifest} from. * @return the manifest or null. */ public static @Nullable Manifest manifest(final @NotNull Class clazz) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java b/proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java index b99493738d..d81314450f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java @@ -37,7 +37,7 @@ import org.jetbrains.annotations.NotNull; /** - * This is internal it does not need a javadoc CHECKSTYLE. + * Information about the current proxy build. */ @AutoService(ServerBuildInfo.class) public record ServerBuildInfoImpl( @@ -94,40 +94,6 @@ public boolean isBrandCompatible(final @NotNull Key brandId) { return brandId.equals(this.brandId); } - @Override - public @NotNull String asString(final @NotNull StringRepresentation representation) { - final StringBuilder sb = new StringBuilder(); - sb.append(this.velocityVersionName); - sb.append('-'); - final OptionalInt buildNumber = this.buildNumber; - if (buildNumber.isPresent()) { - sb.append(buildNumber.getAsInt()); - } else { - sb.append(BUILD_DEV); - } - final boolean hasGitBranch = this.gitBranch.isPresent(); - final boolean hasGitCommit = this.gitCommit.isPresent(); - if (hasGitBranch || hasGitCommit) { - sb.append('-'); - } - if (hasGitBranch && representation == StringRepresentation.VERSION_FULL) { - sb.append(this.gitBranch.get()); - if (hasGitCommit) { - sb.append('@'); - } - } - if (hasGitCommit) { - sb.append(this.gitCommit.get()); - } - if (representation == StringRepresentation.VERSION_FULL) { - sb.append(' '); - sb.append('('); - sb.append(this.buildTime.truncatedTo(ChronoUnit.SECONDS)); - sb.append(')'); - } - return sb.toString(); - } - @Override public @NotNull Component asComponent(final @NotNull StringRepresentation representation) { final TextComponent.Builder sb = text();