Skip to content

Commit

Permalink
#1 Add bStats support v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
CJCrafter committed Jul 15, 2022
1 parent 2bf937d commit 06a0642
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
15 changes: 11 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

group = "me.cjcrafter"
version = "1.0.0"
version = "1.0.1"

plugins {
`java-library`
Expand Down Expand Up @@ -35,21 +35,28 @@ repositories {
url = uri("https://maven.pkg.github.com/WeaponMechanics/MechanicsMain")
credentials {
username = "CJCrafter"
password = "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" // this is a public token created in CJCrafter's name which will never expire
password = "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" // this is a public token created in CJCrafter's name which will never expire
}
}
}

dependencies {
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
compileOnly("me.deecaad:mechanicscore:+")
compileOnly("me.deecaad:weaponmechanics:+")
compileOnly("me.deecaad:mechanicscore:1.3.3-BETA")
compileOnly("me.deecaad:weaponmechanics:1.8.3-BETA")
implementation("org.bstats:bstats-bukkit:3.0.0")
}

tasks.named<ShadowJar>("shadowJar") {
classifier = null
archiveFileName.set("ArmorMechanics-${project.version}.jar")
configurations = listOf(project.configurations["shadeOnly"], project.configurations["runtimeClasspath"])

dependencies {
relocate ("org.bstats", "me.cjcrafter.armormechanics.lib.bstats") {
include(dependency("org.bstats:"))
}
}
}

tasks.named("assemble").configure {
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/me/cjcrafter/armormechanics/ArmorMechanics.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import me.deecaad.core.utils.Debugger;
import me.deecaad.core.utils.FileUtil;
import me.deecaad.core.utils.ReflectionUtil;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
Expand All @@ -23,6 +25,7 @@ public class ArmorMechanics extends JavaPlugin {
public static ArmorMechanics INSTANCE;

private Debugger debug;
private Metrics metrics;

public final Map<String, BonusEffect> effects = new HashMap<>();
public final Map<String, ItemStack> armors = new HashMap<>();
Expand Down Expand Up @@ -58,6 +61,7 @@ public void onLoad() {
public void onEnable() {

reload();
registerBStats();

PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new ArmorEquipListener(), this);
Expand Down Expand Up @@ -104,6 +108,53 @@ public void reload() {
e.log(debug);
}
}
}

private void registerBStats() {
if (metrics != null) return;

debug.debug("Registering bStats");

// See https://bstats.org/plugin/bukkit/ArmorMechanics/15777. This is
// the bStats plugin id used to track information.
int id = 15777;

this.metrics = new Metrics(this, id);

metrics.addCustomChart(new SimplePie("registered_armors", () -> {
int count = armors.size();

if (count <= 10) {
return "0-10";
} else if (count <= 20) {
return "11-20";
} else if (count <= 30) {
return "21-30";
} else if (count <= 50) {
return "31-50";
} else if (count <= 100) {
return "51-100";
} else {
return ">100";
}
}));

metrics.addCustomChart(new SimplePie("registered_sets", () -> {
int count = sets.size();

if (count <= 2) {
return "0-2";
} else if (count <= 5) {
return "3-5";
} else if (count <= 10) {
return "6-10";
} else if (count <= 20) {
return "11-20";
} else if (count <= 50) {
return "21-50";
} else {
return ">50";
}
}));
}
}

0 comments on commit 06a0642

Please # to comment.