|
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,56 @@ 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 | + // 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 | + |
126 | 181 | private static Optional<String> getManifestAttribute(final Manifest manifest, final String name) {
|
127 | 182 | final String value = manifest != null ? manifest.getMainAttributes().getValue(name) : null;
|
128 | 183 | return Optional.ofNullable(Strings.emptyToNull(value));
|
|
0 commit comments