From edfeac2705d363525761ac2bc7134dfded939b0f Mon Sep 17 00:00:00 2001 From: William278 Date: Fri, 12 Jan 2024 22:08:39 +0000 Subject: [PATCH] feat: add bStats, update spigot ID, bump to 1.0.1 --- .../huskclaims/BukkitHuskClaims.java | 27 +++++++++++++++++++ .../net/william278/huskclaims/HuskClaims.java | 8 ++++++ .../huskclaims/util/MetaProvider.java | 3 ++- gradle.properties | 2 +- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/net/william278/huskclaims/BukkitHuskClaims.java b/bukkit/src/main/java/net/william278/huskclaims/BukkitHuskClaims.java index d6f17a12..6f96a67d 100644 --- a/bukkit/src/main/java/net/william278/huskclaims/BukkitHuskClaims.java +++ b/bukkit/src/main/java/net/william278/huskclaims/BukkitHuskClaims.java @@ -38,6 +38,7 @@ import net.william278.huskclaims.config.TrustLevels; import net.william278.huskclaims.database.Database; import net.william278.huskclaims.event.BukkitEventDispatcher; +import net.william278.huskclaims.highlighter.BlockUpdateHighlighter; import net.william278.huskclaims.highlighter.Highlighter; import net.william278.huskclaims.hook.BukkitHookProvider; import net.william278.huskclaims.hook.Hook; @@ -54,6 +55,8 @@ import net.william278.huskclaims.util.BlockProvider; import net.william278.huskclaims.util.BukkitBlockProvider; import net.william278.huskclaims.util.BukkitTask; +import org.bstats.bukkit.Metrics; +import org.bstats.charts.SimplePie; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -125,6 +128,30 @@ public void loadAPI() { BukkitHuskClaimsAPI.register(this); } + @Override + public void loadMetrics() { + try { + final Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID); + metrics.addCustomChart(new SimplePie("is_cross_server", + () -> settings.getCrossServer().isEnabled() ? "true" : "false") + ); + metrics.addCustomChart(new SimplePie("language", + () -> settings.getLanguage().toLowerCase()) + ); + metrics.addCustomChart(new SimplePie("database_type", + () -> settings.getDatabase().getType().getDisplayName()) + ); + metrics.addCustomChart(new SimplePie("highlighter_type", + () -> getHighlighter() instanceof BlockUpdateHighlighter ? "Block Updates" : "Display Entities") + ); + getBroker().ifPresent(broker -> metrics.addCustomChart(new SimplePie("broker_type", + () -> settings.getCrossServer().getBrokerType().getDisplayName() + ))); + } catch (Exception e) { + log(Level.WARNING, "Failed to initialize plugin metrics", e); + } + } + @Override public void disablePlugin() { log(Level.INFO, "Disabling HuskClaims..."); diff --git a/common/src/main/java/net/william278/huskclaims/HuskClaims.java b/common/src/main/java/net/william278/huskclaims/HuskClaims.java index 245e7a37..344989bf 100644 --- a/common/src/main/java/net/william278/huskclaims/HuskClaims.java +++ b/common/src/main/java/net/william278/huskclaims/HuskClaims.java @@ -72,6 +72,7 @@ default void initialize() { loadClaimBlockScheduler(); loadHooks(); loadAPI(); + loadMetrics(); } catch (Throwable e) { log(Level.SEVERE, "An error occurred whilst initializing HuskClaims", e); disablePlugin(); @@ -116,6 +117,13 @@ default void unloadAPI() { HuskClaimsAPI.unregister(); } + /** + * Load plugin metrics + * + * @since 1.0 + */ + void loadMetrics(); + /** * Disable the plugin * diff --git a/common/src/main/java/net/william278/huskclaims/util/MetaProvider.java b/common/src/main/java/net/william278/huskclaims/util/MetaProvider.java index bcd34083..aabf83d9 100644 --- a/common/src/main/java/net/william278/huskclaims/util/MetaProvider.java +++ b/common/src/main/java/net/william278/huskclaims/util/MetaProvider.java @@ -34,7 +34,8 @@ */ public interface MetaProvider { - int SPIGOT_RESOURCE_ID = 100000; //todo set this + int SPIGOT_RESOURCE_ID = 114467; + int BSTATS_PLUGIN_ID = 20728; /** * Get a list of all {@link ClaimWorld}s diff --git a/gradle.properties b/gradle.properties index 5fed4652..cfc6f78d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ javaVersion=17 org.gradle.jvmargs='-Dfile.encoding=UTF-8' org.gradle.daemon=true -plugin_version=1.0 +plugin_version=1.0.1 plugin_archive=huskclaims plugin_description=A clean, cross-server compatible grief prevention plugin