From 4646b8789300158eb7bab75ce010c56fcfa305c4 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Sat, 26 Mar 2022 16:36:29 -0500 Subject: [PATCH] Add build number --- build.gradle | 12 ++++----- src/main/java/dev/plex/Plex.java | 27 +++++++++++++++++++ .../java/dev/plex/command/impl/PlexCMD.java | 4 +++ src/main/resources/build.properties | 3 +++ 4 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 src/main/resources/build.properties diff --git a/build.gradle b/build.gradle index fe3d68f..c9de329 100644 --- a/build.gradle +++ b/build.gradle @@ -45,12 +45,6 @@ ext { buildNumber = System.getenv("BUILD_NUMBER") ?: "unknown" } -tasks.register('printProperties') { - doLast { - println buildNumber - } -} - shadowJar { archiveClassifier.set("") relocate "org.bstats", "dev.plex" @@ -66,6 +60,12 @@ bukkit { apiVersion = "1.18" } +task buildProperties { + ant.propertyfile(file: "$project.rootDir/src/main/resources/build.properties") { + entry(key: "buildNumber", value: buildNumber) + } +} + java { toolchain.languageVersion.set(JavaLanguageVersion.of(17)) } diff --git a/src/main/java/dev/plex/Plex.java b/src/main/java/dev/plex/Plex.java index 9361d44..91b76f5 100644 --- a/src/main/java/dev/plex/Plex.java +++ b/src/main/java/dev/plex/Plex.java @@ -24,6 +24,8 @@ import dev.plex.util.PlexUtils; import dev.plex.util.UpdateChecker; import dev.plex.world.CustomWorld; import java.io.File; +import java.io.InputStream; +import java.util.Properties; import java.util.UUID; import lombok.Getter; import lombok.Setter; @@ -219,4 +221,29 @@ public class Plex extends JavaPlugin } }); } + + public static class BuildProperties + { + public String number; + + public void load(Plex plugin) + { + try + { + final Properties props; + + try (InputStream in = plugin.getResource("build.properties")) + { + props = new Properties(); + props.load(in); + } + + number = props.getProperty("buildNumber", "unknown"); + } + catch (Exception ex) + { + PlexLog.error("Could not load build properties! Did you compile with NetBeans/Maven?"); + } + } + } } \ No newline at end of file diff --git a/src/main/java/dev/plex/command/impl/PlexCMD.java b/src/main/java/dev/plex/command/impl/PlexCMD.java index 5e3b0aa..c300f84 100644 --- a/src/main/java/dev/plex/command/impl/PlexCMD.java +++ b/src/main/java/dev/plex/command/impl/PlexCMD.java @@ -1,5 +1,6 @@ package dev.plex.command.impl; +import dev.plex.Plex; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; @@ -24,6 +25,8 @@ import org.jetbrains.annotations.Nullable; public class PlexCMD extends PlexCommand { // Don't modify this command + Plex.BuildProperties build = new Plex.BuildProperties(); + @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) { @@ -32,6 +35,7 @@ public class PlexCMD extends PlexCommand send(sender, mmString("Plex - A new freedom plugin.")); send(sender, mmString("Plugin version: " + plugin.getDescription().getVersion())); send(sender, mmString("Authors: Telesphoreo, Taahh")); + send(sender, mmString("Build: " + build.number)); send(sender, mmString("Run /plex modules to see a list of modules.")); return null; } diff --git a/src/main/resources/build.properties b/src/main/resources/build.properties new file mode 100644 index 0000000..e374625 --- /dev/null +++ b/src/main/resources/build.properties @@ -0,0 +1,3 @@ +#Sat, 26 Mar 2022 16:36:02 -0500 + +buildNumber=unknown