mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-01-21 21:01:20 +01:00
Make Metrics work again
This commit is contained in:
parent
fa2a4974d8
commit
a1c0116650
@ -173,6 +173,7 @@ public class BIngredients {
|
||||
}
|
||||
brew.save(potionMeta);
|
||||
potion.setItemMeta(potionMeta);
|
||||
P.p.metricsForCreate(brew);
|
||||
|
||||
return potion;
|
||||
}
|
||||
|
@ -729,6 +729,7 @@ public class Brew implements Cloneable {
|
||||
}
|
||||
save(potionMeta);
|
||||
potion.setItemMeta(potionMeta);
|
||||
P.p.metricsForCreate(this);
|
||||
return potion;
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,10 @@ public class P extends JavaPlugin {
|
||||
public String language;
|
||||
public LanguageReader languageReader;
|
||||
|
||||
// Metrics
|
||||
public int brewsCreated;
|
||||
public int exc, good, norm, bad, terr;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
p = this;
|
||||
@ -332,30 +336,11 @@ public class P extends JavaPlugin {
|
||||
/*try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("drunk_players", BPlayer::numDrunkPlayers));
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("brews_in_existence", () -> Brew.potions.size()));
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("brews_in_existence", () -> brewsCreated));
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("barrels_built", () -> Barrel.barrels.size()));
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("cauldrons_boiling", () -> BCauldron.bcauldrons.size()));
|
||||
metrics.addCustomChart(new Metrics.AdvancedPie("brew_quality", () -> {
|
||||
Map<String, Integer> map = new HashMap<>(5);
|
||||
int exc = 0;
|
||||
int good = 0;
|
||||
int norm = 0;
|
||||
int bad = 0;
|
||||
int terr = 0;
|
||||
for (Brew brew : Brew.potions.values()) {
|
||||
if (brew.getQuality() >= 9) {
|
||||
exc++;
|
||||
} else if (brew.getQuality() >= 7) {
|
||||
good++;
|
||||
} else if (brew.getQuality() >= 5) {
|
||||
norm++;
|
||||
} else if (brew.getQuality() >= 3) {
|
||||
bad++;
|
||||
} else {
|
||||
terr++;
|
||||
}
|
||||
}
|
||||
|
||||
map.put("excellent", exc);
|
||||
map.put("good", good);
|
||||
map.put("normal", norm);
|
||||
@ -364,7 +349,7 @@ public class P extends JavaPlugin {
|
||||
return map;
|
||||
}));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("number_of_recipes", () -> {
|
||||
int recipes = BIngredients.recipes.size();
|
||||
int recipes = BRecipe.getAllRecipes().size();
|
||||
if (recipes < 7) {
|
||||
return "Less than 7";
|
||||
} else if (recipes < 11) {
|
||||
@ -528,6 +513,22 @@ public class P extends JavaPlugin {
|
||||
return p;
|
||||
}
|
||||
|
||||
public void metricsForCreate(Brew brew) {
|
||||
if (brewsCreated == Integer.MAX_VALUE) return;
|
||||
brewsCreated++;
|
||||
if (brew.getQuality() >= 9) {
|
||||
exc++;
|
||||
} else if (brew.getQuality() >= 7) {
|
||||
good++;
|
||||
} else if (brew.getQuality() >= 5) {
|
||||
norm++;
|
||||
} else if (brew.getQuality() >= 3) {
|
||||
bad++;
|
||||
} else {
|
||||
terr++;
|
||||
}
|
||||
}
|
||||
|
||||
// Utility
|
||||
|
||||
public void msg(CommandSender sender, String msg) {
|
||||
|
@ -39,6 +39,20 @@ public class BData {
|
||||
|
||||
Brew.loadPrevSeeds(data);
|
||||
|
||||
List<Integer> brewsCreated = data.getIntegerList("brewsCreated");
|
||||
if (brewsCreated != null && brewsCreated.size() == 6) {
|
||||
int hash = data.getInt("brewsCreatedH");
|
||||
// Check the hash to prevent tampering with statistics
|
||||
if (brewsCreated.hashCode() == hash) {
|
||||
P.p.brewsCreated = brewsCreated.get(0);
|
||||
P.p.exc = brewsCreated.get(1);
|
||||
P.p.good = brewsCreated.get(2);
|
||||
P.p.norm = brewsCreated.get(3);
|
||||
P.p.bad = brewsCreated.get(4);
|
||||
P.p.terr = brewsCreated.get(5);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if data is the newest version
|
||||
String version = data.getString("Version", null);
|
||||
if (version != null) {
|
||||
@ -99,6 +113,21 @@ public class BData {
|
||||
}
|
||||
}
|
||||
|
||||
// Store how many legacy brews were created
|
||||
if (P.p.brewsCreated <= 0) {
|
||||
P.p.brewsCreated = 0;
|
||||
P.p.exc = 0;
|
||||
P.p.good = 0;
|
||||
P.p.norm = 0;
|
||||
P.p.bad = 0;
|
||||
P.p.terr = 0;
|
||||
if (!Brew.noLegacy()) {
|
||||
for (Brew brew : Brew.legacyPotions.values()) {
|
||||
P.p.metricsForCreate(brew);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove Legacy Potions that haven't been touched in a long time, these may have been lost
|
||||
if (!Brew.noLegacy()) {
|
||||
int currentHoursAfterInstall = (int) ((double) (System.currentTimeMillis() - Brew.installTime) / 3600000D);
|
||||
|
@ -2,6 +2,9 @@ package com.dre.brewery.filedata;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dre.brewery.MCBarrel;
|
||||
import com.dre.brewery.utility.BUtil;
|
||||
@ -66,6 +69,16 @@ public class DataSave extends BukkitRunnable {
|
||||
|
||||
Brew.writePrevSeeds(configFile);
|
||||
|
||||
List<Integer> brewsCreated = new ArrayList<>(6);
|
||||
brewsCreated.add(P.p.brewsCreated);
|
||||
brewsCreated.add(P.p.exc);
|
||||
brewsCreated.add(P.p.good);
|
||||
brewsCreated.add(P.p.norm);
|
||||
brewsCreated.add(P.p.bad);
|
||||
brewsCreated.add(P.p.terr);
|
||||
configFile.set("brewsCreated", brewsCreated);
|
||||
configFile.set("brewsCreatedH", brewsCreated.hashCode());
|
||||
|
||||
if (!Brew.legacyPotions.isEmpty()) {
|
||||
Brew.saveLegacy(configFile.createSection("Brew"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user