mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-18 08:15:12 +01:00
Move metrics management to another class
This commit is contained in:
parent
190b4c2c2e
commit
bd3761ad13
@ -1,9 +1,35 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Resources;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import net.minelink.ctplus.CombatTagPlus;
|
||||
|
||||
import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.api.NewAPI;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
@ -53,33 +79,6 @@ import fr.xephi.authme.util.GeoLiteAPI;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import net.minelink.ctplus.CombatTagPlus;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.mcstats.Metrics;
|
||||
import org.mcstats.Metrics.Graph;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* The AuthMe main class.
|
||||
@ -245,9 +244,9 @@ public class AuthMe extends JavaPlugin {
|
||||
// Setup otherAccounts file
|
||||
this.otherAccounts = OtherAccounts.getInstance();
|
||||
|
||||
|
||||
// Set up Metrics
|
||||
setupMetrics();
|
||||
final MetricsStarter metrics = new MetricsStarter(this);
|
||||
metrics.setupMetrics();
|
||||
|
||||
// Set console filter
|
||||
setupConsoleFilter();
|
||||
@ -482,41 +481,6 @@ public class AuthMe extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up Metrics.
|
||||
*/
|
||||
private void setupMetrics() {
|
||||
try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
Graph messagesLanguage = metrics.createGraph("Messages language");
|
||||
Graph databaseBackend = metrics.createGraph("Database backend");
|
||||
|
||||
// Custom graphs
|
||||
if (Settings.messageFile.exists()) {
|
||||
messagesLanguage.addPlotter(new Metrics.Plotter(Settings.messagesLanguage) {
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
databaseBackend.addPlotter(new Metrics.Plotter(Settings.getDataSource.toString()) {
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
metrics.start();
|
||||
ConsoleLogger.info("Metrics started successfully!");
|
||||
} catch (Exception e) {
|
||||
// Failed to submit the metrics data
|
||||
ConsoleLogger.writeStackTrace("Can't start Metrics! The plugin will work anyway...", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Save player data
|
||||
|
45
src/main/java/fr/xephi/authme/MetricsStarter.java
Normal file
45
src/main/java/fr/xephi/authme/MetricsStarter.java
Normal file
@ -0,0 +1,45 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.mcstats.Metrics;
|
||||
import org.mcstats.Metrics.Graph;
|
||||
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
public class MetricsStarter {
|
||||
|
||||
public AuthMe plugin;
|
||||
|
||||
public MetricsStarter(final AuthMe plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void setupMetrics() {
|
||||
try {
|
||||
final Metrics metrics = new Metrics(plugin);
|
||||
|
||||
final Graph messagesLanguage = metrics.createGraph("Messages Language");
|
||||
messagesLanguage.addPlotter(new Metrics.Plotter(Settings.messagesLanguage) {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
final Graph databaseBackend = metrics.createGraph("Database Backend");
|
||||
databaseBackend.addPlotter(new Metrics.Plotter(Settings.getDataSource.toString()) {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
// Submit metrics
|
||||
metrics.start();
|
||||
} catch (final IOException e) {
|
||||
// Failed to submit the metrics data
|
||||
ConsoleLogger.writeStackTrace("Can't start Metrics! The plugin will work anyway...", e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user