Skip to content

Commit ebb43aa

Browse files
committed
adventure lol
1 parent 226f964 commit ebb43aa

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

api/src/main/java/com/velocitypowered/api/util/buildinfo/ServerBuildInfo.java

Lines changed: 4 additions & 0 deletions
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;
@@ -102,6 +103,9 @@ final class Holder {
102103
*/
103104
@NotNull String asString(final @NotNull StringRepresentation representation);
104105

106+
@NotNull
107+
default Component asComponent(final @NotNull StringRepresentation representation) { return Component.empty(); }
108+
105109
/**
106110
* String representation types.
107111
*/

proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java

Lines changed: 1 addition & 1 deletion
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

proxy/src/main/java/com/velocitypowered/proxy/util/buildinfo/ServerBuildInfoImpl.java

Lines changed: 44 additions & 0 deletions
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,45 @@ 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+
sb.append(text(this.gitBranch.get()));
149+
if (hasGitCommit) {
150+
sb.append(text('@'));
151+
}
152+
}
153+
if (hasGitCommit) {
154+
sb.append(text()
155+
.content(this.gitCommit.get())
156+
.clickEvent(ClickEvent.openUrl(
157+
"https://github.com/" + this.brandId.namespace() + "/" + this.brandId.value() + "/commit/" + this.gitCommit.get()
158+
))
159+
);
160+
}
161+
if (representation == StringRepresentation.VERSION_FULL) {
162+
sb.append(text(' '));
163+
sb.append(text('('));
164+
sb.append(text(this.buildTime.truncatedTo(ChronoUnit.SECONDS).toString()));
165+
sb.append(text(')'));
166+
}
167+
return sb.build();
168+
}
169+
126170
private static Optional<String> getManifestAttribute(final Manifest manifest, final String name) {
127171
final String value = manifest != null ? manifest.getMainAttributes().getValue(name) : null;
128172
return Optional.ofNullable(Strings.emptyToNull(value));

0 commit comments

Comments
 (0)