TF-EssentialsX/Essentials/src/com/earth2me/essentials/metrics/MetricsStarter.java

103 lines
2 KiB
Java
Raw Normal View History

package com.earth2me.essentials.metrics;
import com.earth2me.essentials.IEssentials;
2012-03-15 01:17:12 +00:00
import com.earth2me.essentials.metrics.Metrics.Graph;
import java.io.IOException;
import java.util.logging.Level;
public class MetricsStarter implements Runnable
{
private final IEssentials ess;
private transient Boolean start;
2012-03-15 01:17:12 +00:00
private enum Modules
{
Essentials,
EssentialsChat,
EssentialsSpawn,
EssentialsProtect,
EssentialsGeoIP,
EssentialsXMPP
};
public MetricsStarter(final IEssentials plugin)
{
ess = plugin;
try
{
final Metrics metrics = new Metrics(ess);
if (!metrics.isOptOut())
{
if (ess.getSettings().isMetricsEnabled())
{
start = true;
}
else
{
ess.getLogger().info("This plugin collects minimal statistic data and sends it to http://metrics.essentials3.net.");
ess.getLogger().info("You can opt out by changing plugins/PluginMetrics/config.yml, set opt-out to true.");
ess.getLogger().info("This will start 5 minutes after the first admin/op joins.");
start = false;
}
return;
}
}
2012-03-15 01:32:08 +00:00
catch (IOException ex)
{
2012-03-15 01:32:08 +00:00
metricsError(ex);
}
}
@Override
public void run()
{
try
{
2012-03-15 01:17:12 +00:00
final Metrics metrics = new Metrics(ess);
Graph moduleGraph = metrics.createGraph("Modules Used");
for (Modules module : Modules.values())
{
final String moduleName = module.toString();
if (ess.getServer().getPluginManager().isPluginEnabled(moduleName))
{
moduleGraph.addPlotter(new Metrics.Plotter(moduleName)
{
@Override
public int getValue()
{
return 1;
}
});
}
}
metrics.start();
}
2012-03-15 01:32:08 +00:00
catch (IOException ex)
{
2012-03-15 01:32:08 +00:00
metricsError(ex);
}
}
public void metricsError(IOException ex)
{
if (ess.getSettings().isDebug())
{
ess.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage(), ex);
}
else
{
ess.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
}
}
public Boolean getStart()
{
return start;
}
}