Skip to content

Commit

Permalink
adventure lol
Browse files Browse the repository at this point in the history
  • Loading branch information
powercasgamer committed May 30, 2024
1 parent 226f964 commit ebb43aa
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,6 +103,9 @@ final class Holder {
*/
@NotNull String asString(final @NotNull StringRepresentation representation);

@NotNull
default Component asComponent(final @NotNull StringRepresentation representation) { return Component.empty(); }

/**
* String representation types.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public int run(final CommandContext<CommandSource> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -123,6 +128,45 @@ 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) {
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<String> getManifestAttribute(final Manifest manifest, final String name) {
final String value = manifest != null ? manifest.getMainAttributes().getValue(name) : null;
return Optional.ofNullable(Strings.emptyToNull(value));
Expand Down

0 comments on commit ebb43aa

Please sign in to comment.