Skip to content

Commit

Permalink
bstats metrics do not collect snapshot & commit, solely version is ca…
Browse files Browse the repository at this point in the history
…ptured.
  • Loading branch information
retrooper committed Sep 20, 2024
1 parent 28c7849 commit d4f7bce
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,26 @@ public PEVersion clone() {

/**
* Converts the {@link PEVersion} to a string representation.
* If this is a stable release, the snapshot and the commit will not be included in the representation.
*
* @return a string representation of the version.
* @return string representation of the version.
*/
@Override
public String toString() {
return major + "." + minor + "." + patch + (snapshot && snapshotCommit != null ? ("+" + snapshotCommit + "-SNAPSHOT") : "");
}

/**
* Converts the {@link PEVersion} to a string representation with guarantee that it
* will not have the commit attached to it.
* Useful for accessing the string representation for metrics
* as detailed information, such as the commit, is not required.
* @return guaranteed string representation without commit.
*/
public String toStringWithoutSnapshot() {
return major + "." + minor + "." + patch;
}

/**
* Converts the {@link PEVersion} to an array of version numbers.
* @deprecated since {@link PEVersion} instances now always use Semantic Versioning, and thus, returning an "amorphous" array,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void init() {
Metrics metrics = new Metrics(plugin, 11327);
//Just to have an idea of which versions of packetevents people use
metrics.addCustomChart(new Metrics.SimplePie("packetevents_version", () -> {
return getVersion().toString();
return getVersion().toStringWithoutSnapshot();
}));

PacketType.Play.Client.load();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ public void init() {

Metrics metrics = new Metrics((JavaPlugin) plugin, 11327);
//Just to have an idea of which versions of packetevents people use
metrics.addCustomChart(new Metrics.SimplePie("packetevents_version", () -> getVersion().toString()));

metrics.addCustomChart(new Metrics.SimplePie("packetevents_version", () -> getVersion().toStringWithoutSnapshot()));
Bukkit.getPluginManager().registerEvents(new InternalBukkitListener(plugin), plugin);

if (lateBind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,10 @@ public void init() {
Object instance = plugin.getInstance().orElse(null);
if (instance != null) {
Metrics metrics = Metrics.createInstance(plugin, server, logger, dataDirectory, 11327);

//Just to have an idea of which versions of packetevents people use
metrics.addCustomChart(new Metrics.SimplePie("packetevents_version", () -> {
return getVersion().toString();
return getVersion().toStringWithoutSnapshot();
}));
}

Expand Down

0 comments on commit d4f7bce

Please sign in to comment.