feat: added version command
This commit is contained in:
parent
97fd7bfd76
commit
ba75abcebc
3 changed files with 83 additions and 0 deletions
|
@ -30,10 +30,28 @@ dependencies {
|
|||
implementation project(":api")
|
||||
}
|
||||
|
||||
ext {
|
||||
gitBranch = System.getenv('GIT_BRANCH') ?: ''
|
||||
gitCommitHash = System.getenv('GIT_COMMIT') ?: ''
|
||||
buildId = System.getenv('BUILD_ID') ?: ''
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archivesBaseName = "ZNPCsPlus"
|
||||
archiveClassifier.set ""
|
||||
|
||||
manifest {
|
||||
if (gitBranch?.trim()) {
|
||||
attributes('Git-Branch': gitBranch)
|
||||
}
|
||||
if (gitCommitHash?.trim()) {
|
||||
attributes('Git-Commit': gitCommitHash)
|
||||
}
|
||||
if (buildId?.trim()) {
|
||||
attributes('Build-Id': buildId)
|
||||
}
|
||||
}
|
||||
|
||||
relocate "org.objectweb.asm", "lol.pyr.znpcsplus.libraries.asm"
|
||||
relocate "me.lucko.jarrelocator", "lol.pyr.znpcsplus.libraries.jarrelocator"
|
||||
|
||||
|
|
|
@ -342,6 +342,7 @@ public class ZNpcsPlus {
|
|||
.addSubcommand("delete", new ActionDeleteCommand(npcRegistry))
|
||||
.addSubcommand("edit", new ActionEditCommand(npcRegistry, actionRegistry))
|
||||
.addSubcommand("list", new ActionListCommand(npcRegistry)))
|
||||
.addSubcommand("version", new VersionCommand(this))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
package lol.pyr.znpcsplus.commands;
|
||||
|
||||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.znpcsplus.ZNpcsPlus;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
public class VersionCommand implements CommandHandler {
|
||||
|
||||
private final String pluginVersion;
|
||||
private final String gitBranch;
|
||||
private final String gitCommitHash;
|
||||
private final String buildId;
|
||||
|
||||
public VersionCommand(ZNpcsPlus plugin) {
|
||||
pluginVersion = plugin.getDescription().getVersion();
|
||||
String gitBranch = "";
|
||||
String gitCommitHash = "";
|
||||
String buildId = "";
|
||||
try {
|
||||
URL jarUrl = getClass().getProtectionDomain().getCodeSource().getLocation();
|
||||
JarFile jarFile = new JarFile(jarUrl.toURI().getPath());
|
||||
Attributes attributes = jarFile.getManifest().getMainAttributes();
|
||||
gitBranch = attributes.getValue("Git-Branch");
|
||||
gitCommitHash = attributes.getValue("Git-Commit-Hash");
|
||||
buildId = attributes.getValue("Build-Id");
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.gitBranch = gitBranch;
|
||||
this.gitCommitHash = gitCommitHash;
|
||||
this.buildId = buildId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
|
||||
StringBuilder versionBuilder = new StringBuilder("This server is running ZNPCsPlus version ").append(pluginVersion);
|
||||
if (gitBranch != null && !gitBranch.isEmpty()) {
|
||||
versionBuilder.append("-").append(gitBranch);
|
||||
}
|
||||
if (gitCommitHash != null && !gitCommitHash.isEmpty()) {
|
||||
versionBuilder.append("@").append(gitCommitHash);
|
||||
}
|
||||
if (buildId != null && !buildId.isEmpty()) {
|
||||
versionBuilder.append(" (Build #").append(buildId).append(")");
|
||||
}
|
||||
|
||||
String version = versionBuilder.toString();
|
||||
|
||||
context.send(Component.text(version, NamedTextColor.GREEN)
|
||||
.hoverEvent(Component.text("Click to copy version to clipboard"))
|
||||
.clickEvent(ClickEvent.copyToClipboard(version)));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue