|
56 | 56 | import fr.traqueur.structura.exceptions.StructuraException; |
57 | 57 | import fr.traqueur.structura.registries.CustomReaderRegistry; |
58 | 58 | import fr.traqueur.structura.registries.PolymorphicRegistry; |
| 59 | +import org.bstats.bukkit.Metrics; |
| 60 | +import org.bstats.charts.AdvancedPie; |
| 61 | +import org.bstats.charts.SimplePie; |
59 | 62 | import org.jetbrains.annotations.NotNull; |
60 | 63 | import org.slf4j.LoggerFactory; |
61 | 64 |
|
62 | 65 | import java.io.File; |
| 66 | +import java.util.HashMap; |
63 | 67 | import java.util.List; |
| 68 | +import java.util.Map; |
64 | 69 |
|
65 | 70 | public class zCrates extends CratesPlugin { |
66 | 71 |
|
@@ -89,6 +94,10 @@ public void onEnable() { |
89 | 94 | Logger.info("<yellow>=== ENABLE START ==="); |
90 | 95 | Logger.info("<gray>Plugin Version V<red>{}", this.getDescription().getVersion()); |
91 | 96 |
|
| 97 | + int pluginId = 28262; |
| 98 | + Metrics metrics = new Metrics(this, pluginId); |
| 99 | + this.addCustomCharts(metrics); |
| 100 | + |
92 | 101 | ZPlacedCrateDataType.initialize(); |
93 | 102 | Keys.initialize(this); |
94 | 103 | MessagesService.initialize(this); |
@@ -278,7 +287,7 @@ public InventoryManager getInventoryManager() { |
278 | 287 | } |
279 | 288 |
|
280 | 289 | private void registerCommands(PluginSettings settings) { |
281 | | - CommandManager<@NotNull CratesPlugin> commandManager = new CommandManager<>(this); |
| 290 | + CommandManager<CratesPlugin> commandManager = new CommandManager<>(this); |
282 | 291 | commandManager.setLogger(new fr.traqueur.commands.api.logging.Logger() { |
283 | 292 | @Override |
284 | 293 | public void error(String s) { |
@@ -319,4 +328,112 @@ private <T extends Settings> T createSettings(String path, Class<T> clazz) { |
319 | 328 | Settings.register(clazz, instance); |
320 | 329 | return instance; |
321 | 330 | } |
| 331 | + |
| 332 | + private void addCustomCharts(@NotNull Metrics metrics) { |
| 333 | + |
| 334 | + // Number of crates configured |
| 335 | + metrics.addCustomChart(new SimplePie("crates_count", () -> { |
| 336 | + CratesRegistry registry = Registry.get(CratesRegistry.class); |
| 337 | + if (registry == null) return "0"; |
| 338 | + int count = registry.getAll().size(); |
| 339 | + if (count == 0) return "0"; |
| 340 | + if (count <= 5) return "1-5"; |
| 341 | + if (count <= 10) return "6-10"; |
| 342 | + if (count <= 20) return "11-20"; |
| 343 | + if (count <= 50) return "21-50"; |
| 344 | + return "50+"; |
| 345 | + })); |
| 346 | + |
| 347 | + // Reward types distribution |
| 348 | + metrics.addCustomChart(new AdvancedPie("reward_types", () -> { |
| 349 | + CratesRegistry cratesRegistry = Registry.get(CratesRegistry.class); |
| 350 | + if (cratesRegistry == null) return new HashMap<>(); |
| 351 | + |
| 352 | + Map<String, Integer> rewardCounts = new HashMap<>(); |
| 353 | + rewardCounts.put("ITEM", 0); |
| 354 | + rewardCounts.put("ITEMS", 0); |
| 355 | + rewardCounts.put("COMMAND", 0); |
| 356 | + rewardCounts.put("COMMANDS", 0); |
| 357 | + |
| 358 | + for (Crate crate : cratesRegistry.getAll()) { |
| 359 | + for (Reward reward : crate.rewards()) { |
| 360 | + String type = reward.getClass().getSimpleName() |
| 361 | + .replace("Reward", "") |
| 362 | + .replace("ListReward", "S") |
| 363 | + .toUpperCase(); |
| 364 | + rewardCounts.put(type, rewardCounts.getOrDefault(type, 0) + 1); |
| 365 | + } |
| 366 | + } |
| 367 | + |
| 368 | + return rewardCounts; |
| 369 | + })); |
| 370 | + |
| 371 | + // Key types distribution |
| 372 | + metrics.addCustomChart(new AdvancedPie("key_types", () -> { |
| 373 | + CratesRegistry cratesRegistry = Registry.get(CratesRegistry.class); |
| 374 | + if (cratesRegistry == null) return new HashMap<>(); |
| 375 | + |
| 376 | + Map<String, Integer> keyCounts = new HashMap<>(); |
| 377 | + keyCounts.put("VIRTUAL", 0); |
| 378 | + keyCounts.put("PHYSIC", 0); |
| 379 | + |
| 380 | + for (Crate crate : cratesRegistry.getAll()) { |
| 381 | + String type = crate.key().getClass().getSimpleName() |
| 382 | + .replace("Key", "") |
| 383 | + .toUpperCase(); |
| 384 | + keyCounts.put(type, keyCounts.getOrDefault(type, 0) + 1); |
| 385 | + } |
| 386 | + |
| 387 | + return keyCounts; |
| 388 | + })); |
| 389 | + |
| 390 | + // Most used animations |
| 391 | + metrics.addCustomChart(new AdvancedPie("animations_used", () -> { |
| 392 | + CratesRegistry cratesRegistry = Registry.get(CratesRegistry.class); |
| 393 | + if (cratesRegistry == null) return new HashMap<>(); |
| 394 | + |
| 395 | + Map<String, Integer> animationCounts = new HashMap<>(); |
| 396 | + for (Crate crate : cratesRegistry.getAll()) { |
| 397 | + String animationId = crate.animation().id(); |
| 398 | + animationCounts.put(animationId, animationCounts.getOrDefault(animationId, 0) + 1); |
| 399 | + } |
| 400 | + |
| 401 | + return animationCounts; |
| 402 | + })); |
| 403 | + |
| 404 | + // Most used algorithms |
| 405 | + metrics.addCustomChart(new AdvancedPie("algorithms_used", () -> { |
| 406 | + CratesRegistry cratesRegistry = Registry.get(CratesRegistry.class); |
| 407 | + if (cratesRegistry == null) return new HashMap<>(); |
| 408 | + |
| 409 | + Map<String, Integer> algorithmCounts = new HashMap<>(); |
| 410 | + for (Crate crate : cratesRegistry.getAll()) { |
| 411 | + String algorithmId = crate.algorithm().id(); |
| 412 | + algorithmCounts.put(algorithmId, algorithmCounts.getOrDefault(algorithmId, 0) + 1); |
| 413 | + } |
| 414 | + |
| 415 | + return algorithmCounts; |
| 416 | + })); |
| 417 | + |
| 418 | + // Crates with rerolls enabled |
| 419 | + metrics.addCustomChart(new SimplePie("rerolls_enabled", () -> { |
| 420 | + CratesRegistry cratesRegistry = Registry.get(CratesRegistry.class); |
| 421 | + if (cratesRegistry == null) return "None"; |
| 422 | + |
| 423 | + long cratesWithRerolls = cratesRegistry.getAll().stream() |
| 424 | + .filter(crate -> crate.maxRerolls() > 0) |
| 425 | + .count(); |
| 426 | + long totalCrates = cratesRegistry.getAll().size(); |
| 427 | + |
| 428 | + if (totalCrates == 0) return "None"; |
| 429 | + if (cratesWithRerolls == 0) return "None"; |
| 430 | + if (cratesWithRerolls == totalCrates) return "All"; |
| 431 | + |
| 432 | + double percentage = (cratesWithRerolls * 100.0) / totalCrates; |
| 433 | + if (percentage < 25) return "< 25%"; |
| 434 | + if (percentage < 50) return "25-50%"; |
| 435 | + if (percentage < 75) return "50-75%"; |
| 436 | + return "75-100%"; |
| 437 | + })); |
| 438 | + } |
322 | 439 | } |
0 commit comments