Add bStats analytics

- Add bStats analytics because MCStats is down constantly
- Add custom graphs:
  - Language pie chart
  - Number of registered regions
  - Number of rental regions
  - Number of buy regions
- Closes #287
- In the future MCStats can be removed, for now I would like to keep complete data there for the times it does work
- Could add more graphs in the future for number of friends and things like that
This commit is contained in:
Thijs Wiefferink 2017-03-02 18:13:52 +01:00
parent 7cda35f4da
commit e6757d23de
4 changed files with 75 additions and 16 deletions

View File

@ -93,6 +93,11 @@
<version>1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<profiles>
@ -229,6 +234,11 @@
<pattern>me.wiefferink.interactivemessenger</pattern>
<shadedPattern>me.wiefferink.areashop.interactivemessenger</shadedPattern>
</relocation>
<!-- Relocate bstats -->
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>me.wiefferink.areashop.bstats</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>

View File

@ -5,7 +5,6 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import me.wiefferink.areashop.interfaces.AreaShopInterface;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
import me.wiefferink.areashop.lib.Metrics;
import me.wiefferink.areashop.lib.Updater;
import me.wiefferink.areashop.lib.Updater.UpdateResult;
import me.wiefferink.areashop.lib.Updater.UpdateType;
@ -20,6 +19,7 @@ import me.wiefferink.interactivemessenger.source.LanguageManager;
import net.milkbowl.vault.economy.Economy;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bstats.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
@ -301,9 +301,9 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
// Register dynamic permission (things declared in config)
registerDynamicPermissions();
// Dont initialize the updatechecker if disabled in the config
if(getConfig().getBoolean("checkForUpdates")) {
// Don't initialize the updatechecker if disabled in the config
if(getConfig().getBoolean("checkForUpdates")) {
new BukkitRunnable() {
@Override
public void run() {
@ -669,14 +669,55 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
* Start the Metrics stats collection
*/
private void startMetrics() {
try {
Metrics metrics = new Metrics(this);
metrics.start();
} catch (Exception e) {
AreaShop.debug("Could not start Metrics");
}
}
// Legacy MCstats statistics (remove at some point)
try {
new me.wiefferink.areashop.lib.Metrics(this).start();
AreaShop.debug("Started mcstats.org statistics service");
} catch (Exception e) {
AreaShop.debug("Could not start mcstats.org statistics service");
}
// bStats statistics
try {
Metrics metrics = new Metrics(this);
// Number of regions
metrics.addCustomChart(new Metrics.SingleLineChart("region_count") {
@Override
public int getValue() {
return getFileManager().getRegions().size();
}
});
// Number of rental regions
metrics.addCustomChart(new Metrics.SingleLineChart("rental_region_count") {
@Override
public int getValue() {
return getFileManager().getRents().size();
}
});
// Number of buy regions
metrics.addCustomChart(new Metrics.SingleLineChart("buy_region_count") {
@Override
public int getValue() {
return getFileManager().getBuys().size();
}
});
// Language
metrics.addCustomChart(new Metrics.SimplePie("language") {
@Override
public String getValue() {
return getConfig().getString("language");
}
});
AreaShop.debug("Started bstats.org statistics service");
} catch (Exception e) {
AreaShop.debug("Could not start bstats.org statistics service");
}
}
/**
* Sends an debug message to the console

View File

@ -705,7 +705,7 @@ public class FileManager extends Manager {
*/
public void saveVersions() {
if(!(new File(versionPath).exists())) {
AreaShop.info("versions file created, this should happen only after installing or upgrading the plugin");
AreaShop.debug("versions file created, this should happen only after installing or upgrading the plugin");
}
try {
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(versionPath));
@ -1008,7 +1008,7 @@ public class FileManager extends Manager {
* After conversion the region files need to be loaded
*/
@SuppressWarnings("unchecked")
public void preUpdateFiles() {
private void preUpdateFiles() {
Integer fileStatus = versions.get(AreaShop.versionFiles);
// If the the files are already the current version
@ -1294,7 +1294,9 @@ public class FileManager extends Manager {
// Update versions file to 2
versions.put(AreaShop.versionFiles, 2);
saveVersions();
AreaShop.info(" Updated to YAML based storage (v1 to v2)");
if (buyFileFound || rentFileFound) {
AreaShop.info(" Updated to YAML based storage (v1 to v2)");
}
}
}
@ -1302,7 +1304,7 @@ public class FileManager extends Manager {
* Checks for old file formats and converts them to the latest format.
* This is to be triggered after the load of the region files
*/
public void postUpdateFiles() {
private void postUpdateFiles() {
Integer fileStatus = versions.get(AreaShop.versionFiles);
// If the the files are already the current version
@ -1318,7 +1320,9 @@ public class FileManager extends Manager {
// Update versions file to 3
versions.put(AreaShop.versionFiles, 3);
saveVersions();
AreaShop.info(" Added last active time to regions (v2 to v3)");
if (getRegions().size() > 0) {
AreaShop.info(" Added last active time to regions (v2 to v3)");
}
}
}

View File

@ -25,6 +25,10 @@
<id>wiefferink-repo</id>
<url>http://maven.wiefferink.me</url>
</repository>
<repository>
<id>bstats-repo</id>
<url>http://repo.bstats.org/content/repositories/releases/</url>
</repository>
</repositories>
<properties>