Including bStats is very easy. There are basically two ways to include bStats:

  • codeUsing Maven to shade bStats
    Note: You are expected to have a basic understanding on how to use Maven!
    1. Include the repository
    bStats uses CodeMC. If you are upgrading from version 1.2 you can no longer use repo.bstats.org.
    <repository>
      <id>CodeMC</id>
      <url>https://repo.codemc.org/repository/maven-public</url>
    </repository>
    2. Include the dependency.
    There are 3 possible artifact ids: bstats-bukkit, bstats-bungeecord and bstats-sponge and their lite counterparts: bstats-bukkit-lite, bstats-bungeecord-lite and bstats-sponge-lite
    <dependency>
      <groupId>org.bstats</groupId>
      <artifactId>bstats-bukkit</artifactId>
      <version>1.4</version>
      <scope>compile</scope>
    </dependency>
    3. Shade bStats into your plugin.
    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).
    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-shade-plugin</artifactId>
          <version>3.1.0</version>
          <!-- Do not include the <configuration>...</configuration> part if you are using Sponge! -->
          <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>
    4. You're done!
    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>
        <repository>
          <id>CodeMC</id>
          <url>https://repo.codemc.org/repository/maven-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>1.4</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>
              <minimizeJar>true</minimizeJar>
              <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 class
    If 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 Lite Version
    Bukkit / Spigot Metrics.java MetricsLite.java
    Bungeecord Metrics.java MetricsLite.java
    Manually copying the metric class is not supported for Sponge!
After adding the Metrics class to your plugin, you now have to initialise the class. How this is done depends on the server software you are using.
Just take a look at the examples for your server software:
Software Example
Bukkit / Spigot ExamplePlugin.java
Bungeecord ExamplePlugin.java
Sponge ExamplePlugin.java
You may notice all examples also include a very basic example on how to use custom charts. You can find a detailed tutorial on how to use them here. If you don't need custom charts you can (but not have to) use the lite version of the Metrics class, too, which is called MetricsLite.