common, fancynpcs, fancyholograms-v2, fancyholograms-v3, ci: Add channel and platform to version config

This commit is contained in:
Oliver
2025-06-27 15:59:29 +02:00
parent a0ef8c264e
commit f4527487ff
11 changed files with 49 additions and 34 deletions

View File

@@ -28,6 +28,9 @@ jobs:
run: chmod +x ./gradlew run: chmod +x ./gradlew
- name: Build FancyNpcs - name: Build FancyNpcs
env:
RELEASE_CHANNEL: 'snapshot'
RELEASE_PLATFORM: 'modrinth'
run: ./gradlew :plugins:fancynpcs:shadowJar run: ./gradlew :plugins:fancynpcs:shadowJar
- name: Build deployment tool - name: Build deployment tool

View File

@@ -12,8 +12,9 @@ public class VersionConfig {
private final Plugin plugin; private final Plugin plugin;
private final VersionFetcher fetcher; private final VersionFetcher fetcher;
private String version; private String version;
private String build; private String commitHash;
private String hash; private String channel;
private String platform;
public VersionConfig(Plugin plugin, VersionFetcher fetcher) { public VersionConfig(Plugin plugin, VersionFetcher fetcher) {
this.plugin = plugin; this.plugin = plugin;
@@ -29,8 +30,13 @@ public class VersionConfig {
} }
version = config.getString("version", "undefined"); version = config.getString("version", "undefined");
build = config.getString("build", "undefined"); commitHash = config.getString("commit_hash", "undefined");
hash = config.getString("hash", "undefined"); channel = config.getString("channel", "undefined");
platform = config.getString("platform", "undefined");
}
public boolean isDevelopmentBuild() {
return !channel.equalsIgnoreCase("release");
} }
public void checkVersionAndDisplay(CommandSender sender, boolean displayOnlyIfOutdated) { public void checkVersionAndDisplay(CommandSender sender, boolean displayOnlyIfOutdated) {
@@ -70,13 +76,11 @@ public class VersionConfig {
private String latestVersion() { private String latestVersion() {
String result = "This server is using the latest version of {plugin}!\n" + String result = "This server is using the latest version of {plugin}!\n" +
"Version: {version} (Git: {hash})" + "Version: {version} (Git: {hash})";
"{build}";
result = result.replace("{plugin}", plugin.getName()) result = result.replace("{plugin}", plugin.getName())
.replace("{version}", version) .replace("{version}", version)
.replace("{hash}", hash.substring(0, 7)) .replace("{hash}", commitHash.substring(0, 7));
.replace("{build}", build.equalsIgnoreCase("undefined") ? "" : "\nBuild: " + build);
return result; return result;
} }
@@ -99,11 +103,15 @@ public class VersionConfig {
return version; return version;
} }
public String getBuild() { public String getCommitHash() {
return build; return commitHash;
} }
public String getHash() { public String getChannel() {
return hash; return channel;
}
public String getPlatform() {
return platform;
} }
} }

View File

@@ -146,8 +146,9 @@ tasks {
val props = mapOf( val props = mapOf(
"description" to project.description, "description" to project.description,
"version" to getFHVersion(), "version" to getFHVersion(),
"hash" to gitCommitHash.get(), "commit_hash" to gitCommitHash.get(),
"build" to (System.getenv("BUILD_ID") ?: "").ifEmpty { "undefined" } "channel" to (System.getenv("RELEASE_CHANNEL") ?: "").ifEmpty { "undefined" },
"platform" to (System.getenv("RELEASE_PLATFORM") ?: "").ifEmpty { "undefined" }
) )
inputs.properties(props) inputs.properties(props)

View File

@@ -319,17 +319,15 @@ public final class FancyHolograms extends JavaPlugin implements FancyHologramsPl
} }
private void registerMetrics() { private void registerMetrics() {
boolean isDevelopmentBuild = !versionConfig.getBuild().equalsIgnoreCase("undefined");
Metrics metrics = new Metrics(this, 17990); Metrics metrics = new Metrics(this, 17990);
metrics.addCustomChart(new Metrics.SingleLineChart("total_holograms", () -> hologramsManager.getHolograms().size())); metrics.addCustomChart(new Metrics.SingleLineChart("total_holograms", () -> hologramsManager.getHolograms().size()));
metrics.addCustomChart(new Metrics.SimplePie("update_notifications", () -> configuration.areVersionNotificationsEnabled() ? "Yes" : "No")); metrics.addCustomChart(new Metrics.SimplePie("update_notifications", () -> configuration.areVersionNotificationsEnabled() ? "Yes" : "No"));
metrics.addCustomChart(new Metrics.SimplePie("using_development_build", () -> isDevelopmentBuild ? "Yes" : "No")); metrics.addCustomChart(new Metrics.SimplePie("using_development_build", () -> versionConfig.isDevelopmentBuild() ? "Yes" : "No"));
fancyAnalytics = new FancyAnalyticsAPI("3b77bd59-2b01-46f2-b3aa-a9584401797f", "E2gW5zc2ZTk1OGFkNGY2ZDQ0ODlM6San"); fancyAnalytics = new FancyAnalyticsAPI("3b77bd59-2b01-46f2-b3aa-a9584401797f", "E2gW5zc2ZTk1OGFkNGY2ZDQ0ODlM6San");
fancyAnalytics.getConfig().setDisableLogging(true); fancyAnalytics.getConfig().setDisableLogging(true);
if (!isDevelopmentBuild) { if (!versionConfig.isDevelopmentBuild()) {
return; return;
} }
@@ -338,7 +336,7 @@ public final class FancyHolograms extends JavaPlugin implements FancyHologramsPl
fancyAnalytics.getExceptionHandler().registerLogger(Bukkit.getLogger()); fancyAnalytics.getExceptionHandler().registerLogger(Bukkit.getLogger());
fancyAnalytics.getExceptionHandler().registerLogger(fancyLogger); fancyAnalytics.getExceptionHandler().registerLogger(fancyLogger);
fancyAnalytics.registerStringMetric(new MetricSupplier<>("commit_hash", () -> versionConfig.getHash().substring(0, 7))); fancyAnalytics.registerStringMetric(new MetricSupplier<>("commit_hash", () -> versionConfig.getCommitHash().substring(0, 7)));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("server_size", () -> { fancyAnalytics.registerStringMetric(new MetricSupplier<>("server_size", () -> {
long onlinePlayers = Bukkit.getOnlinePlayers().size(); long onlinePlayers = Bukkit.getOnlinePlayers().size();
@@ -365,7 +363,7 @@ public final class FancyHolograms extends JavaPlugin implements FancyHologramsPl
fancyAnalytics.registerNumberMetric(new MetricSupplier<>("amount_holograms", () -> (double) hologramsManager.getHolograms().size())); fancyAnalytics.registerNumberMetric(new MetricSupplier<>("amount_holograms", () -> (double) hologramsManager.getHolograms().size()));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("enabled_update_notifications", () -> configuration.areVersionNotificationsEnabled() ? "true" : "false")); fancyAnalytics.registerStringMetric(new MetricSupplier<>("enabled_update_notifications", () -> configuration.areVersionNotificationsEnabled() ? "true" : "false"));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("fflag_disable_holograms_for_bedrock_players", () -> FHFeatureFlags.DISABLE_HOLOGRAMS_FOR_BEDROCK_PLAYERS.isEnabled() ? "true" : "false")); fancyAnalytics.registerStringMetric(new MetricSupplier<>("fflag_disable_holograms_for_bedrock_players", () -> FHFeatureFlags.DISABLE_HOLOGRAMS_FOR_BEDROCK_PLAYERS.isEnabled() ? "true" : "false"));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("using_development_build", () -> isDevelopmentBuild ? "true" : "false")); fancyAnalytics.registerStringMetric(new MetricSupplier<>("using_development_build", () -> versionConfig.isDevelopmentBuild() ? "true" : "false"));
fancyAnalytics.registerStringArrayMetric(new MetricSupplier<>("hologram_type", () -> { fancyAnalytics.registerStringArrayMetric(new MetricSupplier<>("hologram_type", () -> {
if (hologramsManager == null) { if (hologramsManager == null) {

View File

@@ -1,3 +1,4 @@
version: $version version: $version
build: $build commit_hash: $commit_hash
hash: $hash platform: $platform
channel: $channel

View File

@@ -150,7 +150,9 @@ tasks {
val props = mapOf( val props = mapOf(
"description" to project.description, "description" to project.description,
"version" to getFHVersion(), "version" to getFHVersion(),
"hash" to getCurrentCommitHash(), "commit_hash" to getCurrentCommitHash(),
"channel" to (System.getenv("RELEASE_CHANNEL") ?: "").ifEmpty { "undefined" },
"platform" to (System.getenv("RELEASE_PLATFORM") ?: "").ifEmpty { "undefined" }
) )
inputs.properties(props) inputs.properties(props)

View File

@@ -32,7 +32,7 @@ public class FHMetrics {
HologramRegistry registry = FancyHologramsPlugin.get().getRegistry(); HologramRegistry registry = FancyHologramsPlugin.get().getRegistry();
fancyAnalytics.registerStringMetric(new MetricSupplier<>("commit_hash", () -> FancyHologramsPlugin.get().getVersionConfig().getHash().substring(0, 7))); fancyAnalytics.registerStringMetric(new MetricSupplier<>("commit_hash", () -> FancyHologramsPlugin.get().getVersionConfig().getCommitHash().substring(0, 7)));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("server_size", () -> { fancyAnalytics.registerStringMetric(new MetricSupplier<>("server_size", () -> {
long onlinePlayers = Bukkit.getOnlinePlayers().size(); long onlinePlayers = Bukkit.getOnlinePlayers().size();

View File

@@ -1,2 +1,4 @@
version: $version version: $version
hash: $hash commit_hash: $commit_hash
platform: $platform
channel: $channel

View File

@@ -178,8 +178,9 @@ tasks {
val props = mapOf( val props = mapOf(
"description" to project.description, "description" to project.description,
"version" to getFNVersion(), "version" to getFNVersion(),
"hash" to gitCommitHash.get(), "commit_hash" to gitCommitHash.get(),
"build" to (System.getenv("BUILD_ID") ?: "").ifEmpty { "undefined" } "channel" to (System.getenv("RELEASE_CHANNEL") ?: "").ifEmpty { "undefined" },
"platform" to (System.getenv("RELEASE_PLATFORM") ?: "").ifEmpty { "undefined" }
) )
inputs.properties(props) inputs.properties(props)

View File

@@ -353,19 +353,17 @@ public class FancyNpcs extends JavaPlugin implements FancyNpcsPlugin {
} }
private void registerMetrics() { private void registerMetrics() {
boolean isDevelopmentBuild = !versionConfig.getBuild().equalsIgnoreCase("undefined");
Metrics metrics = new Metrics(this, 17543); Metrics metrics = new Metrics(this, 17543);
metrics.addCustomChart(new Metrics.SingleLineChart("total_npcs", () -> npcManager.getAllNpcs().size())); metrics.addCustomChart(new Metrics.SingleLineChart("total_npcs", () -> npcManager.getAllNpcs().size()));
metrics.addCustomChart(new Metrics.SimplePie("update_notifications", () -> config.isMuteVersionNotification() ? "No" : "Yes")); metrics.addCustomChart(new Metrics.SimplePie("update_notifications", () -> config.isMuteVersionNotification() ? "No" : "Yes"));
metrics.addCustomChart(new Metrics.SimplePie("using_development_build", () -> isDevelopmentBuild ? "Yes" : "No")); metrics.addCustomChart(new Metrics.SimplePie("using_development_build", () -> versionConfig.isDevelopmentBuild() ? "Yes" : "No"));
fancyAnalytics.registerMinecraftPluginMetrics(instance); fancyAnalytics.registerMinecraftPluginMetrics(instance);
fancyAnalytics.getExceptionHandler().registerLogger(getLogger()); fancyAnalytics.getExceptionHandler().registerLogger(getLogger());
fancyAnalytics.getExceptionHandler().registerLogger(Bukkit.getLogger()); fancyAnalytics.getExceptionHandler().registerLogger(Bukkit.getLogger());
fancyAnalytics.getExceptionHandler().registerLogger(fancyLogger); fancyAnalytics.getExceptionHandler().registerLogger(fancyLogger);
fancyAnalytics.registerStringMetric(new MetricSupplier<>("commit_hash", () -> versionConfig.getHash().substring(0, 7))); fancyAnalytics.registerStringMetric(new MetricSupplier<>("commit_hash", () -> versionConfig.getCommitHash().substring(0, 7)));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("server_size", () -> { fancyAnalytics.registerStringMetric(new MetricSupplier<>("server_size", () -> {
@@ -393,7 +391,7 @@ public class FancyNpcs extends JavaPlugin implements FancyNpcsPlugin {
fancyAnalytics.registerNumberMetric(new MetricSupplier<>("amount_npcs", () -> (double) npcManager.getAllNpcs().size())); fancyAnalytics.registerNumberMetric(new MetricSupplier<>("amount_npcs", () -> (double) npcManager.getAllNpcs().size()));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("enabled_update_notifications", () -> config.isMuteVersionNotification() ? "false" : "true")); fancyAnalytics.registerStringMetric(new MetricSupplier<>("enabled_update_notifications", () -> config.isMuteVersionNotification() ? "false" : "true"));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("enabled_player_npcs_fflag", () -> PLAYER_NPCS_FEATURE_FLAG.isEnabled() ? "true" : "false")); fancyAnalytics.registerStringMetric(new MetricSupplier<>("enabled_player_npcs_fflag", () -> PLAYER_NPCS_FEATURE_FLAG.isEnabled() ? "true" : "false"));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("using_development_build", () -> isDevelopmentBuild ? "true" : "false")); fancyAnalytics.registerStringMetric(new MetricSupplier<>("using_development_build", () -> versionConfig.isDevelopmentBuild() ? "true" : "false"));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("language", () -> translator.getSelectedLanguage().getLanguageCode())); fancyAnalytics.registerStringMetric(new MetricSupplier<>("language", () -> translator.getSelectedLanguage().getLanguageCode()));
fancyAnalytics.registerNumberMetric(new MetricSupplier<>("avg_interaction_cooldown", () -> { fancyAnalytics.registerNumberMetric(new MetricSupplier<>("avg_interaction_cooldown", () -> {

View File

@@ -1,3 +1,4 @@
version: $version version: $version
build: $build commit_hash: $commit_hash
hash: $hash platform: $platform
channel: $channel