Including bStats is very easy. There are basically two ways to include bStats:
-
codeUsing Maven to shade bStatsNote: You are expected to have a basic understanding on how to use Maven!
1. Include the dependency.
There are 4 possible artifact ids: bstats-bukkit, bstats-bungeecord, bstats-sponge, and bstats-velocity.
3. Shade bStats into your plugin.<dependency> <groupId>org.bstats</groupId> <artifactId>bstats-bukkit</artifactId> <version>3.0.2</version> <scope>compile</scope> </dependency>
This step is very important. Shading means, that the necessary classes are copied into your plugin when you compile it. It also relocates the class to an other package. Make sure to change your.package to your own package! If you are using Sponge, do not relocate the bStats class (just remove the <configuration>...</configuration> part).
4. You're done!<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.1.0</version> <configuration> <relocations> <relocation> <pattern>org.bstats</pattern> <!-- Replace this with your package! --> <shadedPattern>your.package</shadedPattern> </relocation> </relocations> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Your final pom.xml now may look like this:<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>me.name</groupId> <artifactId>pluginname</artifactId> <version>1.0.0</version> <repositories> <repository> <id>spigot-repo</id> <url>https://hub.spigotmc.org/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <!-- Spigot as an example --> <dependency> <groupId>org.spigotmc</groupId> <artifactId>spigot-api</artifactId> <version>LATEST</version> <scope>provided</scope> </dependency> <!-- bStats --> <dependency> <groupId>org.bstats</groupId> <artifactId>bstats-bukkit</artifactId> <version>3.0.2</version> <scope>compile</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.1.0</version> <configuration> <relocations> <relocation> <pattern>org.bstats</pattern> <shadedPattern>me.name.util</shadedPattern> </relocation> </relocations> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
-
codeManually copy the Metrics classIf you don't want to use Maven that's no problem. You can just copy and paste the required class into your project. All classes can be found in the GitHub repository.
Just copy the class fitting your server software. Make sure to change the package from org.bstats to your own package.
Software Standard Bukkit / Spigot Metrics.java Bungeecord Metrics.java Sponge Metrics.java Velocity Metrics.java
Just take a look at the examples for your server software:
Software | Example |
---|---|
Bukkit / Spigot | ExamplePlugin.java |
Bungeecord | ExamplePlugin.java |
Sponge | ExamplePlugin.java |
Velocity | ExamplePlugin.java |