Skip to content

Commit 3d73c71

Browse files
committed
feat(metrics): Basic FastStats setup
1 parent e77c143 commit 3d73c71

13 files changed

Lines changed: 201 additions & 81 deletions

File tree

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ repositories {
5959
maven("https://repo.oraxen.com/releases") // Oraxen
6060
maven("https://storehouse.okaeri.eu/repository/maven-public/") // Okaeri Config
6161
maven("https://repo.papermc.io/repository/maven-public/") // PaperLib
62+
maven("https://repo.faststats.dev/releases") // FastStats
6263
maven { githubPackage("apdevteam/movecraft")(this) } // Movecraft
6364
}
6465

@@ -99,6 +100,7 @@ dependencies {
99100
}
100101
}
101102
}
103+
implementation("dev.faststats.metrics:bukkit:0.22.0")
102104

103105
// Plugin Compatability
104106
compileOnly("com.sk89q:worldguard:6.1") // https://dev.bukkit.org/projects/worldedit/files
@@ -165,6 +167,7 @@ tasks {
165167
relocate("org.bson", "$pack.bson")
166168
relocate("io.papermc.lib", "$pack.paperlib")
167169
relocate("com.zaxxer.hikari", "$pack.hikari")
170+
relocate("dev.faststats", "$pack.faststats")
168171

169172
archiveClassifier.set("")
170173
}

src/main/java/com/dre/brewery/BIngredients.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public ItemStack cook(int state, Player brewer) {
239239
}
240240
brew.save(potionMeta);
241241
potion.setItemMeta(potionMeta);
242-
plugin.getBreweryStats().metricsForCreate(false);
242+
plugin.getMetrics().getBstatsBrewery().metricsForCreate(false);
243243

244244
return potion;
245245
}

src/main/java/com/dre/brewery/BPlayer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.dre.brewery.configuration.ConfigManager;
2828
import com.dre.brewery.configuration.files.Config;
2929
import com.dre.brewery.configuration.files.Lang;
30+
import com.dre.brewery.integration.metrics.faststats.FastStats;
3031
import com.dre.brewery.lore.BrewLore;
3132
import com.dre.brewery.recipe.BEffect;
3233
import com.dre.brewery.utility.BUtil;
@@ -55,7 +56,6 @@
5556
import org.bukkit.inventory.meta.ItemMeta;
5657
import org.bukkit.metadata.FixedMetadataValue;
5758
import org.bukkit.potion.PotionEffect;
58-
import org.bukkit.potion.PotionEffectType;
5959
import org.bukkit.util.Vector;
6060
import org.jetbrains.annotations.Nullable;
6161

@@ -212,7 +212,7 @@ public static boolean drink(Brew brew, Player player, @Nullable ItemMeta meta, @
212212
if (brew.hasRecipe()) {
213213
brew.getCurrentRecipe().applyDrinkFeatures(player, brew.getQuality());
214214
}
215-
BreweryPlugin.getInstance().getBreweryStats().forDrink(brew);
215+
BreweryPlugin.getInstance().getMetrics().getBstatsBrewery().forDrink(brew);
216216

217217
int brewAlc = drinkEvent.getAddedAlcohol();
218218
int quality = drinkEvent.getQuality();

src/main/java/com/dre/brewery/Brew.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import org.bukkit.inventory.meta.ItemMeta;
5454
import org.bukkit.inventory.meta.PotionMeta;
5555
import org.bukkit.potion.PotionEffect;
56-
import org.bukkit.potion.PotionEffectType;
5756
import org.bukkit.potion.PotionType;
5857
import org.jetbrains.annotations.Contract;
5958
import org.jetbrains.annotations.Nullable;
@@ -890,7 +889,7 @@ public ItemStack createItem(@Nullable BRecipe recipe, boolean event, @Nullable P
890889
}
891890
save(potionMeta);
892891
potion.setItemMeta(potionMeta);
893-
BreweryPlugin.getInstance().getBreweryStats().metricsForCreate(true);
892+
BreweryPlugin.getInstance().getMetrics().getBstatsBrewery().metricsForCreate(true);
894893
return potion;
895894
}
896895

src/main/java/com/dre/brewery/BreweryPlugin.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
import com.dre.brewery.integration.LandsHook;
3232
import com.dre.brewery.integration.PlaceholderAPIHook;
3333
import com.dre.brewery.integration.barrel.BlockLockerBarrel;
34-
import com.dre.brewery.integration.bstats.BreweryStats;
35-
import com.dre.brewery.integration.bstats.BreweryXStats;
34+
import com.dre.brewery.integration.metrics.Metrics;
35+
import com.dre.brewery.integration.metrics.bstats.BStatsBrewery;
36+
import com.dre.brewery.integration.metrics.bstats.BStatsBreweryX;
3637
import com.dre.brewery.integration.listeners.ChestShopListener;
3738
import com.dre.brewery.integration.listeners.IntegrationListener;
3839
import com.dre.brewery.integration.listeners.ShopKeepersListener;
@@ -91,7 +92,7 @@ public final class BreweryPlugin extends JavaPlugin {
9192

9293

9394
private final Map<String, Function<ItemLoader, Ingredient>> ingredientLoaders = new HashMap<>(); // Registrations
94-
private BreweryStats breweryStats; // Metrics
95+
private Metrics metrics;
9596

9697
{
9798
// Basically just racing to be the first code to execute.
@@ -152,7 +153,7 @@ public void onEnable() {
152153
ConfigManager.loadRecipes();
153154
ConfigManager.loadDistortWords();
154155
ConfigManager.loadSeed();
155-
this.breweryStats = new BreweryStats(); // Load metrics
156+
this.metrics = new Metrics();
156157

157158

158159
Logging.log("Minecraft version&7:&a " + MCVersion.getVersion());
@@ -196,8 +197,7 @@ public void onEnable() {
196197

197198
addonManager.enableAddons();
198199
// Setup Metrics
199-
this.breweryStats.setupBStats();
200-
new BreweryXStats().setupBStats();
200+
this.metrics.enable();
201201

202202
// Register command and aliases
203203
PluginCommand defaultCommand = getCommand("breweryx");
@@ -274,6 +274,8 @@ public void onDisable() {
274274
// Stop schedulers
275275
BreweryPlugin.getScheduler().cancelTasks(this);
276276

277+
this.metrics.disable();
278+
277279
// save Data to Disk
278280
if (dataManager != null) dataManager.exit(true, false);
279281

src/main/java/com/dre/brewery/commands/subcommands/ShowStatsCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void execute(BreweryPlugin breweryPlugin, Lang lang, CommandSender sender
3939
//if (sender instanceof ConsoleCommandSender && !sender.isOp()) return;
4040

4141
Logging.msg(sender, "Drunk Players: " + BPlayer.numDrunkPlayers());
42-
Logging.msg(sender, "Brews created: " + BreweryPlugin.getInstance().getBreweryStats().brewsCreated);
42+
Logging.msg(sender, "Brews created: " + BreweryPlugin.getInstance().getMetrics().getBstatsBrewery().brewsCreated);
4343
Logging.msg(sender, "Barrels built: " + Barrel.getAllBarrels().size());
4444
Logging.msg(sender, "Cauldrons boiling: " + BCauldron.bcauldrons.size());
4545
Logging.msg(sender, "Number of Recipes: " + BRecipe.getAllRecipes().size());
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* BreweryX Bukkit-Plugin for an alternate brewing process
3+
* Copyright (C) 2024-2026 The Brewery Team
4+
*
5+
* This file is part of BreweryX.
6+
*
7+
* BreweryX is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* BreweryX is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with BreweryX. If not, see <http://www.gnu.org/licenses/gpl-3.0.html>.
19+
*/
20+
21+
package com.dre.brewery.integration.metrics;
22+
23+
import com.dre.brewery.integration.metrics.bstats.BStatsBrewery;
24+
import com.dre.brewery.integration.metrics.bstats.BStatsBreweryX;
25+
import com.dre.brewery.integration.metrics.faststats.FastStats;
26+
import lombok.Getter;
27+
28+
@Getter
29+
public class Metrics {
30+
31+
private final FastStats fastStats;
32+
private final BStatsBrewery bstatsBrewery;
33+
private final BStatsBreweryX bStatsBreweryX;
34+
35+
public Metrics() {
36+
this.fastStats = new FastStats();
37+
this.bstatsBrewery = new BStatsBrewery();
38+
this.bStatsBreweryX = new BStatsBreweryX();
39+
}
40+
41+
public void enable() {
42+
fastStats.enable();
43+
bstatsBrewery.setupBStats();
44+
bStatsBreweryX.setupBStats();
45+
}
46+
47+
public void disable() {
48+
fastStats.disable();
49+
}
50+
}

src/main/java/com/dre/brewery/integration/bstats/Metrics.java renamed to src/main/java/com/dre/brewery/integration/metrics/bstats/BStats.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Violations will result in a ban of your plugin and account from bStats.
1515
*/
1616

17-
package com.dre.brewery.integration.bstats;
17+
package com.dre.brewery.integration.metrics.bstats;
1818

1919
import org.bukkit.Bukkit;
2020
import org.bukkit.configuration.file.YamlConfiguration;
@@ -51,7 +51,7 @@
5151
import java.util.zip.GZIPOutputStream;
5252

5353
// Copied from bStats because Gradle wasn't returning the right class
54-
public class Metrics {
54+
public class BStats {
5555

5656
private final Plugin plugin;
5757

@@ -64,7 +64,7 @@ public class Metrics {
6464
* @param serviceId The id of the service. It can be found at <a
6565
* href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
6666
*/
67-
public Metrics(JavaPlugin plugin, int serviceId) {
67+
public BStats(JavaPlugin plugin, int serviceId) {
6868
this.plugin = plugin;
6969
// Get the config file
7070
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");

src/main/java/com/dre/brewery/integration/bstats/BreweryStats.java renamed to src/main/java/com/dre/brewery/integration/metrics/bstats/BStatsBrewery.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* along with BreweryX. If not, see <http://www.gnu.org/licenses/gpl-3.0.html>.
1919
*/
2020

21-
package com.dre.brewery.integration.bstats;
21+
package com.dre.brewery.integration.metrics.bstats;
2222

2323
import com.dre.brewery.BCauldron;
2424
import com.dre.brewery.BPlayer;
@@ -28,10 +28,10 @@
2828
import com.dre.brewery.Wakeup;
2929
import com.dre.brewery.configuration.ConfigManager;
3030
import com.dre.brewery.configuration.files.Config;
31-
import com.dre.brewery.integration.bstats.Metrics.AdvancedPie;
32-
import com.dre.brewery.integration.bstats.Metrics.DrilldownPie;
33-
import com.dre.brewery.integration.bstats.Metrics.SimplePie;
34-
import com.dre.brewery.integration.bstats.Metrics.SingleLineChart;
31+
import com.dre.brewery.integration.metrics.bstats.BStats.AdvancedPie;
32+
import com.dre.brewery.integration.metrics.bstats.BStats.DrilldownPie;
33+
import com.dre.brewery.integration.metrics.bstats.BStats.SimplePie;
34+
import com.dre.brewery.integration.metrics.bstats.BStats.SingleLineChart;
3535
import com.dre.brewery.recipe.BRecipe;
3636
import com.dre.brewery.utility.Logging;
3737
import org.bukkit.Bukkit;
@@ -42,7 +42,7 @@
4242
/**
4343
* General stats written by the original author of Brewery.
4444
*/
45-
public class BreweryStats {
45+
public class BStatsBrewery {
4646

4747
private static final int BSTATS_ID = 3494;
4848

@@ -76,12 +76,12 @@ public void forDrink(Brew brew) {
7676

7777
public void setupBStats() {
7878
try {
79-
Metrics metrics = new Metrics(BreweryPlugin.getInstance(), BSTATS_ID);
80-
metrics.addCustomChart(new SingleLineChart("drunk_players", BPlayer::numDrunkPlayers));
81-
metrics.addCustomChart(new SingleLineChart("brews_in_existence", () -> brewsCreated));
82-
metrics.addCustomChart(new SingleLineChart("barrels_built", Barrel.getAllBarrels()::size));
83-
metrics.addCustomChart(new SingleLineChart("cauldrons_boiling", BCauldron.bcauldrons::size));
84-
metrics.addCustomChart(new AdvancedPie("brew_quality", () -> {
79+
BStats bstats = new BStats(BreweryPlugin.getInstance(), BSTATS_ID);
80+
bstats.addCustomChart(new SingleLineChart("drunk_players", BPlayer::numDrunkPlayers));
81+
bstats.addCustomChart(new SingleLineChart("brews_in_existence", () -> brewsCreated));
82+
bstats.addCustomChart(new SingleLineChart("barrels_built", Barrel.getAllBarrels()::size));
83+
bstats.addCustomChart(new SingleLineChart("cauldrons_boiling", BCauldron.bcauldrons::size));
84+
bstats.addCustomChart(new AdvancedPie("brew_quality", () -> {
8585
Map<String, Integer> map = new HashMap<>(8);
8686
map.put("excellent", exc);
8787
map.put("good", good);
@@ -90,14 +90,14 @@ public void setupBStats() {
9090
map.put("terrible", terr);
9191
return map;
9292
}));
93-
metrics.addCustomChart(new AdvancedPie("brews_created", () -> {
93+
bstats.addCustomChart(new AdvancedPie("brews_created", () -> {
9494
Map<String, Integer> map = new HashMap<>(4);
9595
map.put("by command", brewsCreatedCmd);
9696
map.put("brewing", brewsCreated - brewsCreatedCmd);
9797
return map;
9898
}));
9999

100-
metrics.addCustomChart(new SimplePie("number_of_recipes", () -> {
100+
bstats.addCustomChart(new SimplePie("number_of_recipes", () -> {
101101
int recipes = BRecipe.getAllRecipes().size();
102102
if (recipes < 7) {
103103
return "Less than 7";
@@ -128,7 +128,7 @@ public void setupBStats() {
128128
}
129129

130130
}));
131-
metrics.addCustomChart(new SimplePie("cauldron_particles", () -> {
131+
bstats.addCustomChart(new SimplePie("cauldron_particles", () -> {
132132
if (!config.isEnableCauldronParticles()) {
133133
return "disabled";
134134
}
@@ -137,7 +137,7 @@ public void setupBStats() {
137137
}
138138
return "enabled";
139139
}));
140-
metrics.addCustomChart(new SimplePie("wakeups", () -> {
140+
bstats.addCustomChart(new SimplePie("wakeups", () -> {
141141
if (!config.isEnableWake()) {
142142
return "disabled";
143143
}
@@ -154,7 +154,7 @@ public void setupBStats() {
154154
return "More than 20";
155155
}
156156
}));
157-
metrics.addCustomChart(new SimplePie("v2_mc_version", () -> {
157+
bstats.addCustomChart(new SimplePie("v2_mc_version", () -> {
158158
String mcv = Bukkit.getBukkitVersion();
159159
mcv = mcv.substring(0, mcv.indexOf('.', 2));
160160
int index = mcv.indexOf('-');
@@ -168,7 +168,7 @@ public void setupBStats() {
168168
return "undef";
169169
}
170170
}));
171-
metrics.addCustomChart(new DrilldownPie("plugin_mc_version", () -> {
171+
bstats.addCustomChart(new DrilldownPie("plugin_mc_version", () -> {
172172
Map<String, Map<String, Integer>> map = new HashMap<>(3);
173173
String mcv = Bukkit.getBukkitVersion();
174174
mcv = mcv.substring(0, mcv.indexOf('.', 2));
@@ -187,9 +187,9 @@ public void setupBStats() {
187187
map.put(BreweryPlugin.getInstance().getDescription().getVersion(), innerMap);
188188
return map;
189189
}));
190-
metrics.addCustomChart(new SimplePie("language", config::getLanguage));
191-
metrics.addCustomChart(new SimplePie("config_scramble", () -> config.isEnableEncode() ? "enabled" : "disabled"));
192-
metrics.addCustomChart(new SimplePie("config_lore_color", () -> {
190+
bstats.addCustomChart(new SimplePie("language", config::getLanguage));
191+
bstats.addCustomChart(new SimplePie("config_scramble", () -> config.isEnableEncode() ? "enabled" : "disabled"));
192+
bstats.addCustomChart(new SimplePie("config_lore_color", () -> {
193193
if (config.isColorInBarrels()) {
194194
if (config.isColorInBrewer()) {
195195
return "both";
@@ -204,7 +204,7 @@ public void setupBStats() {
204204
}
205205
}
206206
}));
207-
metrics.addCustomChart(new SimplePie("config_always_show", () -> {
207+
bstats.addCustomChart(new SimplePie("config_always_show", () -> {
208208
if (config.isAlwaysShowQuality()) {
209209
if (config.isAlwaysShowAlc()) {
210210
return "both";

0 commit comments

Comments
 (0)