Skip to content

Commit 3b9f323

Browse files
committed
adventure
1 parent 226f964 commit 3b9f323

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

Diff for: api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.Optional;
1212
import java.util.OptionalInt;
1313
import net.kyori.adventure.key.Key;
14+
import net.kyori.adventure.text.Component;
1415
import net.kyori.adventure.util.Services;
1516
import org.jetbrains.annotations.ApiStatus;
1617
import org.jetbrains.annotations.NotNull;
@@ -100,8 +101,12 @@ final class Holder {
100101
* @param representation the type of representation
101102
* @return a string
102103
*/
104+
// This *could* be a PlainTextSerializer string of asComponent()?
103105
@NotNull String asString(final @NotNull StringRepresentation representation);
104106

107+
@NotNull
108+
default Component asComponent(final @NotNull StringRepresentation representation) { return Component.empty(); }
109+
105110
/**
106111
* String representation types.
107112
*/

Diff for: proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public int run(final CommandContext<CommandSource> context) {
163163
.decoration(TextDecoration.BOLD, true)
164164
.color(VELOCITY_COLOR)
165165
.append(Component.text()
166-
.content(build.asString(ServerBuildInfo.StringRepresentation.VERSION_FULL))
166+
.append(build.asComponent(ServerBuildInfo.StringRepresentation.VERSION_FULL))
167167
.decoration(TextDecoration.BOLD, false))
168168
.build();
169169
final Component copyright = Component

Diff for: proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java

+55
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package com.velocitypowered.proxy.util.buildinfo;
1919

20+
import static net.kyori.adventure.text.Component.text;
21+
2022
import com.google.auto.service.AutoService;
2123
import com.google.common.base.Strings;
2224
import com.velocitypowered.api.util.buildinfo.ServerBuildInfo;
@@ -29,6 +31,9 @@
2931
import java.util.OptionalInt;
3032
import java.util.jar.Manifest;
3133
import net.kyori.adventure.key.Key;
34+
import net.kyori.adventure.text.Component;
35+
import net.kyori.adventure.text.TextComponent;
36+
import net.kyori.adventure.text.event.ClickEvent;
3237
import org.jetbrains.annotations.NotNull;
3338

3439
/**
@@ -123,6 +128,56 @@ public boolean isBrandCompatible(final @NotNull Key brandId) {
123128
return sb.toString();
124129
}
125130

131+
@Override
132+
public @NotNull Component asComponent(final @NotNull StringRepresentation representation) {
133+
final TextComponent.Builder sb = text();
134+
sb.append(text(this.velocityVersionName));
135+
sb.append(text('-'));
136+
final OptionalInt buildNumber = this.buildNumber;
137+
if (buildNumber.isPresent()) {
138+
sb.append(text(buildNumber.getAsInt()));
139+
} else {
140+
sb.append(text(BUILD_DEV));
141+
}
142+
final boolean hasGitBranch = this.gitBranch.isPresent();
143+
final boolean hasGitCommit = this.gitCommit.isPresent();
144+
if (hasGitBranch || hasGitCommit) {
145+
sb.append(text('-'));
146+
}
147+
if (hasGitBranch && representation == StringRepresentation.VERSION_FULL) {
148+
// In theory, you could add a link to the branch, but that wouldn't work for local branches but would that really matter though?
149+
// Could also just not do that if the buildNumber is not present (or if DEV) is in the string
150+
if (buildNumber.isPresent()) {
151+
sb.append(text()
152+
.content(this.gitBranch.get())
153+
.clickEvent(ClickEvent.openUrl(
154+
"https://github.com/" + this.brandId.namespace() + "/" + this.brandId.value() + "/tree/" + this.gitBranch.get()
155+
))
156+
);
157+
} else {
158+
sb.append(text(this.gitBranch.get()));
159+
}
160+
if (hasGitCommit) {
161+
sb.append(text('@'));
162+
}
163+
}
164+
if (hasGitCommit) {
165+
sb.append(text()
166+
.content(this.gitCommit.get())
167+
.clickEvent(ClickEvent.openUrl(
168+
"https://github.com/" + this.brandId.namespace() + "/" + this.brandId.value() + "/commit/" + this.gitCommit.get()
169+
))
170+
);
171+
}
172+
if (representation == StringRepresentation.VERSION_FULL) {
173+
sb.append(text(' '));
174+
sb.append(text('('));
175+
sb.append(text(this.buildTime.truncatedTo(ChronoUnit.SECONDS).toString()));
176+
sb.append(text(')'));
177+
}
178+
return sb.build();
179+
}
180+
126181
private static Optional<String> getManifestAttribute(final Manifest manifest, final String name) {
127182
final String value = manifest != null ? manifest.getMainAttributes().getValue(name) : null;
128183
return Optional.ofNullable(Strings.emptyToNull(value));

0 commit comments

Comments
 (0)