Skip to content

Commit

Permalink
Separate concept
Browse files Browse the repository at this point in the history
  • Loading branch information
powercasgamer committed May 30, 2024
1 parent 15d5a5e commit 0baed1d
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 30 deletions.
2 changes: 1 addition & 1 deletion api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ tasks {
}
// TEMP
withType<Checkstyle> {
exclude("**/com/velocitypowered/api/util/ServerBuildInfo.java")
exclude("**/com/velocitypowered/api/util/buildinfo/*ServerBuildInfo.java")
}

withType<Javadoc> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}.
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -123,11 +106,11 @@ final class Holder {
*/
enum StringRepresentation {
/**
* A simple version string, in format {@code <velocityVersionName>-<buildNumber>-<gitCommit>}.
* A simple version string, in format {@code <versionName>-<buildNumber>-<gitCommit>}.
*/
VERSION_SIMPLE,
/**
* A simple version string, in format {@code <velocityVersionName>-<buildNumber>-<gitBranch>@<gitCommit> (<buildTime>)}.
* A simple version string, in format {@code <versionName>-<buildNumber>-<gitBranch>@<gitCommit> (<buildTime>)}.
*/
VERSION_FULL,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

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;
Expand All @@ -36,13 +38,13 @@
public record ServerBuildInfoImpl(
Key brandId,
String brandName,
/*String velocityVersionId,*/
String velocityVersionId,
String velocityVersionName,
OptionalInt buildNumber,
Instant buildTime,
Optional<String> gitBranch,
Optional<String> 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";
Expand All @@ -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)
Expand Down

0 comments on commit 0baed1d

Please sign in to comment.