Usage - Hidendra/Plugin-Metrics GitHub Wiki

There are two versions of MCStats / Plugin Metrics to choose from that you can add to your plugin:

  1. Metrics: The fully featured version of the service. It supports custom data and custom graphs and is required if you want to submit your own numerical data.
  2. MetricsLite: A basic, "lite" version of Metrics. This version is unable to submit your own custom data. This can be later swapped with the fully featured Metrics class if you so choose to want to use it instead.

Automatic (Maven shading)

  1. Add the repository

        <repositories>
            ...
            <repository>
                <id>Plugin Metrics</id>
                <url>http://repo.mcstats.org/content/repositories/public</url>
            </repository>
        </repositories>
  2. Add the version of metrics you want. The artifact metrics-lite is for the lite version, metrics non-lite. Replace MOD with the mod you are using (check the mods folder of this repository).

        <dependencies>
            ...
            <dependency>
                <groupId>org.mcstats.MOD</groupId>
                <artifactId>metrics</artifactId>
                <version>R7</version>
                <scope>compile</scope>
            </dependency>
        </dependencies>
  3. Add the shading plugin to the build. Replace YOUR.PACKAGE with your own package. If it isn't shaded correctly, it will be fairly obvious when you try to test so this should be easy to figure out ;)

        <build>
            ...
            <plugins>
                ...
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>2.3</version>
                    <configuration>
                        <artifactSet>
                            <includes>
                                <include>org.mcstats.*:*</include>
                            </includes>
                        </artifactSet>
                        <relocations>
                            <relocation>
                                <pattern>org.mcstats</pattern>
                                <shadedPattern>YOUR.PACKAGE</shadedPattern>
                            </relocation>
                        </relocations>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
  4. If you want to build your project, run the following command in your working directory (where the pom.xml is located):

    mvn package

Example pom.xml

This could be the pom.xml of a Bukkit plugin.

<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.author</groupId>
    <artifactId>pluginname</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    
    <repositories>
        <repository>
            <id>Plugin Metrics</id>
            <url>http://repo.mcstats.org/content/repositories/public</url>
        </repository>
    </repositories>
    
    <dependencies>
        <dependency>
            <groupId>org.bukkit</groupId>
            <artifactId>bukkit</artifactId>
            <version>LATEST</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mcstats.bukkit</groupId>
            <artifactId>metrics</artifactId>
            <version>R7</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.5</version>
                <configuration>
                    <artifactSet>
                        <includes>
                            <include>org.mcstats.*:*</include>
                        </includes>
                    </artifactSet>
                    <relocations>
                        <relocation>
                            <pattern>org.mcstats</pattern>
                            <shadedPattern>me.author.pluginname</shadedPattern>
                        </relocation>
                    </relocations>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Manual management (adding the class to your source)

Download one of the classes from the mods folder and place it into your plugin; preferably into your own package, so as to guarantee no conflicts with other plugins. If you are using Bukkit, choose that folder and then select metrics or metrics-lite. If you are using a different mod then select appropriately.

Adding Metrics to your code

As for basic usage, submitting data is extremely simple and can be done by adding something similar to the following to your onEnable() method. This only needs to be called once:

    try {
        Metrics metrics = new Metrics(this);
        metrics.start();
    } catch (IOException e) {
        // Failed to submit the stats :-(
    }

Note: If you chose to use metrics lite, use the class MetricsLite in place of Metrics

Plugin not showing up on http://mcstats.org?

Ensure the following:

  1. Your plugin is compiling and building correctly with zero errors
  2. In config/PluginMetrics/config.yml ensure opt-out is set to false
  3. If there is a firewall preventing outbound connections, ensure traffic is allowed to mcstats.org port 80

What's next?

Most authors will want access to the Admin Portal so they can edit settings or the author field on the website. Note that this is not required for stat collection -- it is simply an extra.

To obtain access:

  1. Register at http://mcstats.org/admin/
  2. Add your plugin
  • Note: Much like DBO, additions must be manually approved by staff (aka Hidendra). Once this is done you will receive an email if you provided one.

See also

⚠️ **GitHub.com Fallback** ⚠️