Skip to content

Commit

Permalink
Add amount_npc_actions metric
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Sep 15, 2024
1 parent 725fa28 commit cb358ea
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/main/java/de/oliver/fancynpcs/FancyNpcs.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
public class FancyNpcs extends JavaPlugin implements FancyNpcsPlugin {

public static final FeatureFlag PLAYER_NPCS_FEATURE_FLAG = new FeatureFlag("player-npcs", "Every player can only manage the npcs they have created", false);
public static final FeatureFlag USE_FANCYANALYTICS_FEATURE_FLAG = new FeatureFlag("use-fancyanalytics", "Use FancyAnalytics to report plugin usage and errors", false);

private static FancyNpcs instance;
private final ExtendedFancyLogger fancyLogger = new ExtendedFancyLogger("FancyNpcs");
Expand Down Expand Up @@ -109,7 +108,6 @@ public static FancyNpcs getInstance() {
public void onLoad() {
// Load feature flags
featureFlagConfig.addFeatureFlag(PLAYER_NPCS_FEATURE_FLAG);
featureFlagConfig.addFeatureFlag(USE_FANCYANALYTICS_FEATURE_FLAG);
featureFlagConfig.load();

String mcVersion = Bukkit.getMinecraftVersion();
Expand Down Expand Up @@ -214,7 +212,7 @@ Please update to the newest version (%s).
metrics.addCustomChart(new Metrics.SimplePie("using_development_build", () -> isDevelopmentBuild ? "Yes" : "No"));

int randomRes = new Random(System.currentTimeMillis()).nextInt(100);
if (USE_FANCYANALYTICS_FEATURE_FLAG.isEnabled() && (isDevelopmentBuild || randomRes < 30)) {
if (isDevelopmentBuild || randomRes < 30) {
fancyAnalytics.registerDefaultPluginMetrics(instance);
fancyAnalytics.registerLogger(getLogger());
fancyAnalytics.registerLogger(Bukkit.getLogger());
Expand Down Expand Up @@ -276,6 +274,16 @@ Please update to the newest version (%s).
return (double) count;
}));

fancyAnalytics.registerNumberMetric(new MetricSupplier<>("amount_npc_actions", () -> {
long count = 0;

for (Npc npc : npcManager.getAllNpcs()) {
count += npc.getData().getActions().values().size();
}

return (double) count;
}));


fancyAnalytics.initialize();
}
Expand Down

0 comments on commit cb358ea

Please sign in to comment.