Skip to content

Commit

Permalink
Add metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobcat00 committed Jun 12, 2019
1 parent 9738058 commit 3c836c2
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
# Maven
log/
target/
dependency-reduced-pom.xml
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ from them.
This plugin is not associated with and uses no code from a plugin of the same
name created by Techdoodle.

This plugin uses the bStats metrics system to provide anonymous usage data. You
may opt-out globally by changing plugins/bStats/config.yml. The metrics are
available at https://bstats.org/plugin/bukkit/AutoBot

This program is distributed WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. **If you purchase
an API Key and you can't get this plugin to work on your server, I have no
Expand Down
36 changes: 35 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.bobcat00</groupId>
<artifactId>AutoBot</artifactId>
<version>1.00</version>
<version>1.01</version>
<build>
<resources>
<resource>
Expand Down Expand Up @@ -30,13 +30,40 @@
<target>1.8</target>
</configuration>
</plugin>
<!-- bStats -->
<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>com.bobcat00.autobot</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<!-- bStats -->
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
</repositories>
<dependencies>
<dependency>
Expand All @@ -46,5 +73,12 @@
<type>jar</type>
<scope>provided</scope>
</dependency>
<!-- bStats -->
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
75 changes: 75 additions & 0 deletions src/main/java/com/bobcat00/autobot/AutoBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.bobcat00.autobot;

import java.util.concurrent.Callable;

import org.bstats.bukkit.Metrics;
import org.bukkit.plugin.java.JavaPlugin;

import com.bobcat00.autobot.Listeners;
Expand Down Expand Up @@ -59,6 +62,78 @@ public void onEnable()
getLogger().info("Plugin enabled.");
getLogger().info("AutoBot uses the Cleverbot API from Existor. See https://www.cleverbot.com/api/");
}

// Metrics
Metrics metrics = new Metrics(this);
if (metrics.isEnabled())
{
// Expiration
metrics.addCustomChart(new Metrics.SimplePie("expiration", new Callable<String>()
{
@Override
public String call() throws Exception
{
final long expirationTime = config.getExpirationMinutes();
if (expirationTime == 0)
return "0";
else if (expirationTime <= 10)
return "1-10";
else if (expirationTime <= 20)
return "11-20";
else if (expirationTime <= 30)
return "21-30";
else if (expirationTime > 30)
return ">30";
else
return "Invalid";
}
} ));
// Single player
metrics.addCustomChart(new Metrics.SimplePie("single_player", new Callable<String>()
{
@Override
public String call() throws Exception
{
return config.getSinglePlayer() ? "Yes" : "No";
}
} ));
// Tweaks
metrics.addCustomChart(new Metrics.SimplePie("tweak1", new Callable<String>()
{
@Override
public String call() throws Exception
{
return chartData(config.getTweak1(), "Sensible", "Wacky");
}
} ));
metrics.addCustomChart(new Metrics.SimplePie("tweak2", new Callable<String>()
{
@Override
public String call() throws Exception
{
return chartData(config.getTweak2(), "Shy", "Talkative");
}
} ));
metrics.addCustomChart(new Metrics.SimplePie("tweak3", new Callable<String>()
{
@Override
public String call() throws Exception
{
return chartData(config.getTweak3(), "Self-centered", "Attentive");
}
} ));
getLogger().info("Enabled metrics. You may opt-out by changing plugins/bStats/config.yml");
}
}

private String chartData(final int value, final String low, final String high)
{
if (value <= 33)
return low;
else if (value >= 67)
return high;
else
return "Normal";
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ from them.
This plugin is not associated with and uses no code from a plugin of the same
name created by Techdoodle.

This plugin uses the bStats metrics system to provide anonymous usage data. You
may opt-out globally by changing plugins/bStats/config.yml. The metrics are
available at https://bstats.org/plugin/bukkit/AutoBot

This program is distributed WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. If you purchase
an API Key and you can't get this plugin to work on your server, I have no
Expand Down

0 comments on commit 3c836c2

Please sign in to comment.