2013-02-01 21:25:43 +00:00
|
|
|
package de.jaschastarke.minecraft.limitedcreative;
|
|
|
|
|
2013-03-20 20:33:52 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2013-02-01 21:25:43 +00:00
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
|
|
|
|
import de.jaschastarke.bukkit.lib.CoreModule;
|
|
|
|
import de.jaschastarke.bukkit.tools.stats.IStatistics;
|
2013-07-28 09:07:27 +00:00
|
|
|
import de.jaschastarke.bukkit.tools.stats.MCStatsMetrics;
|
|
|
|
import de.jaschastarke.bukkit.tools.stats.MCStatsMetrics.Graph;
|
2013-02-01 21:25:43 +00:00
|
|
|
import de.jaschastarke.bukkit.tools.stats.PiwikStatistics;
|
2013-07-28 09:07:27 +00:00
|
|
|
import de.jaschastarke.modularize.IModule;
|
|
|
|
import de.jaschastarke.modularize.ModuleEntry;
|
|
|
|
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
|
2013-02-01 21:25:43 +00:00
|
|
|
|
|
|
|
public class FeatureMetrics extends CoreModule<LimitedCreative> implements Listener {
|
|
|
|
public FeatureMetrics(LimitedCreative plugin) {
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
private IStatistics metric;
|
2013-07-28 09:07:27 +00:00
|
|
|
private MCStatsMetrics mcstats = null;
|
2013-02-01 21:25:43 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
2013-03-23 16:59:14 +00:00
|
|
|
super.onEnable();
|
2013-02-01 21:25:43 +00:00
|
|
|
metric = new PiwikStatistics(plugin);
|
2013-07-28 09:07:27 +00:00
|
|
|
if (mcstats == null) {
|
|
|
|
try {
|
|
|
|
mcstats = new MCStatsMetrics(plugin);
|
|
|
|
|
|
|
|
Graph moduleGraph = mcstats.createGraph("Module Usage");
|
|
|
|
for (final ModuleEntry<IModule> mod : plugin.getModules()) {
|
|
|
|
if (mod.getModule() instanceof CoreModule<?>) {
|
|
|
|
moduleGraph.addPlotter(new MCStatsMetrics.Plotter(((CoreModule<?>) mod.getModule()).getName()) {
|
|
|
|
@Override
|
|
|
|
public int getValue() {
|
|
|
|
return mod.getState() == ModuleState.ENABLED ? 1 : 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mcstats.start();
|
|
|
|
} catch (IOException e) {
|
|
|
|
// Failed to submit the stats :-(
|
|
|
|
getLog().warn("MCStats-Error: " + e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2013-02-01 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2013-03-23 16:59:14 +00:00
|
|
|
super.onDisable();
|
2013-02-01 21:25:43 +00:00
|
|
|
metric.unregister();
|
|
|
|
}
|
|
|
|
|
2013-03-20 20:33:52 +00:00
|
|
|
public void track(String event) throws IOException {
|
2013-02-01 21:25:43 +00:00
|
|
|
if (metric == null)
|
|
|
|
throw new IllegalAccessError("The feature hasn't been enabled");
|
|
|
|
metric.trackEvent(event);
|
|
|
|
}
|
|
|
|
}
|