|
17 | 17 |
|
18 | 18 | package com.velocitypowered.proxy.util.buildinfo; |
19 | 19 |
|
| 20 | +import static net.kyori.adventure.text.Component.text; |
| 21 | + |
20 | 22 | import com.google.auto.service.AutoService; |
21 | 23 | import com.google.common.base.Strings; |
22 | 24 | import com.velocitypowered.api.util.buildinfo.ServerBuildInfo; |
|
29 | 31 | import java.util.OptionalInt; |
30 | 32 | import java.util.jar.Manifest; |
31 | 33 | 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; |
32 | 37 | import org.jetbrains.annotations.NotNull; |
33 | 38 |
|
34 | 39 | /** |
@@ -123,6 +128,45 @@ public boolean isBrandCompatible(final @NotNull Key brandId) { |
123 | 128 | return sb.toString(); |
124 | 129 | } |
125 | 130 |
|
| 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 | + |
126 | 170 | private static Optional<String> getManifestAttribute(final Manifest manifest, final String name) { |
127 | 171 | final String value = manifest != null ? manifest.getMainAttributes().getValue(name) : null; |
128 | 172 | return Optional.ofNullable(Strings.emptyToNull(value)); |
|
0 commit comments