Implements BStats statistics
This commit is contained in:
		
							
								
								
									
										6
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								pom.xml
									
									
									
									
									
								
							@@ -100,6 +100,12 @@
 | 
			
		||||
            <version>1.1</version>
 | 
			
		||||
            <scope>compile</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.bstats</groupId>
 | 
			
		||||
            <artifactId>bstats-bukkit</artifactId>
 | 
			
		||||
            <version>3.0.1</version>
 | 
			
		||||
            <scope>compile</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
    </dependencies>
 | 
			
		||||
 | 
			
		||||
    <build>
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,7 @@ import net.knarcraft.stargate.portal.PortalRegistry;
 | 
			
		||||
import net.knarcraft.stargate.thread.BlockChangeThread;
 | 
			
		||||
import net.knarcraft.stargate.thread.ChunkUnloadThread;
 | 
			
		||||
import net.knarcraft.stargate.thread.StarGateThread;
 | 
			
		||||
import net.knarcraft.stargate.utility.BStatsHelper;
 | 
			
		||||
import org.bukkit.Server;
 | 
			
		||||
import org.bukkit.command.PluginCommand;
 | 
			
		||||
import org.bukkit.configuration.file.FileConfiguration;
 | 
			
		||||
@@ -367,6 +368,8 @@ public class Stargate extends JavaPlugin {
 | 
			
		||||
        //Check for any available updates
 | 
			
		||||
        UpdateChecker.checkForUpdate(this, "https://api.spigotmc.org/legacy/update.php?resource=87978",
 | 
			
		||||
                Stargate::getPluginVersion, Stargate::setUpdateAvailable);
 | 
			
		||||
 | 
			
		||||
        BStatsHelper.initialize(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,54 @@
 | 
			
		||||
package net.knarcraft.stargate.utility;
 | 
			
		||||
 | 
			
		||||
import net.knarcraft.stargate.Stargate;
 | 
			
		||||
import net.knarcraft.stargate.config.ConfigOption;
 | 
			
		||||
import net.knarcraft.stargate.portal.PortalHandler;
 | 
			
		||||
import net.knarcraft.stargate.portal.property.gate.GateHandler;
 | 
			
		||||
import org.bstats.bukkit.Metrics;
 | 
			
		||||
import org.bstats.charts.SimplePie;
 | 
			
		||||
import org.bstats.charts.SingleLineChart;
 | 
			
		||||
import org.bukkit.plugin.java.JavaPlugin;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A helper for dealing with BStats
 | 
			
		||||
 */
 | 
			
		||||
public final class BStatsHelper {
 | 
			
		||||
 | 
			
		||||
    private static boolean hasBeenInitialized = false;
 | 
			
		||||
 | 
			
		||||
    private BStatsHelper() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Initializes BStats
 | 
			
		||||
     *
 | 
			
		||||
     * @param plugin <p>The plugin to initialize BStats for</p>
 | 
			
		||||
     */
 | 
			
		||||
    public static void initialize(JavaPlugin plugin) {
 | 
			
		||||
        if (hasBeenInitialized) {
 | 
			
		||||
            throw new IllegalArgumentException("BStats initialized twice");
 | 
			
		||||
        } else {
 | 
			
		||||
            hasBeenInitialized = true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int pluginId = 10451;
 | 
			
		||||
        Metrics metrics = new Metrics(plugin, pluginId);
 | 
			
		||||
 | 
			
		||||
        Map<ConfigOption, Object> configValues = Stargate.getStargateConfig().getConfigOptions();
 | 
			
		||||
        Map<String, List<String>> portalNetworks = PortalHandler.getAllPortalNetworks();
 | 
			
		||||
        int totalPortals = 0;
 | 
			
		||||
        for (List<String> portals : portalNetworks.values()) {
 | 
			
		||||
            totalPortals += portals.size();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        metrics.addCustomChart(new SimplePie("language", () -> (String) configValues.get(ConfigOption.LANGUAGE)));
 | 
			
		||||
        metrics.addCustomChart(new SimplePie("gateformats", () -> String.valueOf(GateHandler.getGateCount())));
 | 
			
		||||
        int finalTotalPortals = totalPortals;
 | 
			
		||||
        metrics.addCustomChart(new SingleLineChart("gatesv3", () -> finalTotalPortals));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user