mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-17 07:45:09 +01:00
Add metrics for used economy and hooked dependencies
This commit is contained in:
parent
30ff61d14f
commit
999f596125
@ -110,6 +110,8 @@ public class ChestShop extends JavaPlugin {
|
||||
private static PluginDescriptionFile description;
|
||||
private static final ExecutorService executorService = Executors.newCachedThreadPool();
|
||||
|
||||
private static Metrics bStats;
|
||||
|
||||
private static BukkitAudiences audiences;
|
||||
|
||||
private static File dataFolder;
|
||||
@ -135,6 +137,7 @@ public class ChestShop extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
bStats = new Metrics(this, 1109);
|
||||
audiences = BukkitAudiences.create(this);
|
||||
turnOffDatabaseLogging();
|
||||
if (!handleMigrations()) {
|
||||
@ -445,7 +448,6 @@ public class ChestShop extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void startStatistics() {
|
||||
Metrics bStats = new Metrics(this, 1109);
|
||||
try (JarFile jarFile = new JarFile(this.getFile())) {
|
||||
String dist = jarFile.getManifest().getMainAttributes().getValue("Distribution-Type");
|
||||
bStats.addCustomChart(new SimplePie("distributionType", () -> dist));
|
||||
@ -511,7 +513,7 @@ public class ChestShop extends JavaPlugin {
|
||||
() -> Properties.SHOP_CONTAINERS.stream().map(Material::name).collect(Collectors.toMap(k -> k, k -> 1))));
|
||||
}
|
||||
|
||||
private DrilldownPie createStaticDrilldownStat(String statId, String value1, String value2) {
|
||||
public static DrilldownPie createStaticDrilldownStat(String statId, String value1, String value2) {
|
||||
final Map<String, Map<String, Integer>> map = ImmutableMap.of(value1, ImmutableMap.of(value2, 1));
|
||||
return new DrilldownPie(statId, () -> map);
|
||||
}
|
||||
@ -581,6 +583,10 @@ public class ChestShop extends JavaPlugin {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public static Metrics getMetrics() {
|
||||
return bStats;
|
||||
}
|
||||
|
||||
public static BukkitAudiences getAudiences() {
|
||||
return audiences;
|
||||
}
|
||||
|
@ -2,9 +2,12 @@ package com.Acrobot.ChestShop;
|
||||
|
||||
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Listeners.Economy.EconomyAdapter;
|
||||
import com.Acrobot.ChestShop.Listeners.Economy.Plugins.ReserveListener;
|
||||
import com.Acrobot.ChestShop.Listeners.Economy.Plugins.VaultListener;
|
||||
import com.Acrobot.ChestShop.Plugins.*;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.bstats.charts.DrilldownPie;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -14,11 +17,18 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Dependencies implements Listener {
|
||||
|
||||
private static final Map<String, String> versions = new HashMap<>();
|
||||
|
||||
public static void initializePlugins() {
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
|
||||
@ -62,13 +72,23 @@ public class Dependencies implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
return loadEconomy();
|
||||
if (loadEconomy()) {
|
||||
Map<String, Map<String, Integer>> map = versions.entrySet().stream()
|
||||
.map(e -> new AbstractMap.SimpleEntry<String, Map<String, Integer>>(e.getKey(), ImmutableMap.of(e.getValue(), 1)))
|
||||
.collect(Collectors.toMap(
|
||||
AbstractMap.SimpleEntry::getKey,
|
||||
AbstractMap.SimpleEntry::getValue
|
||||
));
|
||||
ChestShop.getMetrics().addCustomChart(new DrilldownPie("dependencies", () -> map));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean loadEconomy() {
|
||||
String plugin = "none";
|
||||
|
||||
Listener economy = null;
|
||||
EconomyAdapter economy = null;
|
||||
|
||||
if(Bukkit.getPluginManager().getPlugin("Reserve") != null) {
|
||||
plugin = "Reserve";
|
||||
@ -85,6 +105,10 @@ public class Dependencies implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
versions.put(plugin, Bukkit.getPluginManager().getPlugin(plugin).getDescription().getVersion());
|
||||
|
||||
ChestShop.getMetrics().addCustomChart(ChestShop.createStaticDrilldownStat("economyPlugin", economy.getProviderInfo().getName(), economy.getProviderInfo().getVersion()));
|
||||
|
||||
ChestShop.registerListener(economy);
|
||||
ChestShop.getBukkitLogger().info(plugin + " loaded!");
|
||||
return true;
|
||||
@ -187,6 +211,7 @@ public class Dependencies implements Listener {
|
||||
}
|
||||
|
||||
PluginDescriptionFile description = plugin.getDescription();
|
||||
versions.put(description.getName(), description.getVersion());
|
||||
ChestShop.getBukkitLogger().info(description.getName() + " version " + description.getVersion() + " loaded.");
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,8 @@ import java.math.BigDecimal;
|
||||
|
||||
public abstract class EconomyAdapter implements Listener {
|
||||
|
||||
public abstract ProviderInfo getProviderInfo();
|
||||
|
||||
public abstract void onAmountCheck(CurrencyAmountEvent event);
|
||||
|
||||
public abstract void onCurrencyCheck(CurrencyCheckEvent event);
|
||||
@ -74,4 +76,21 @@ public abstract class EconomyAdapter implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProviderInfo {
|
||||
private final String name;
|
||||
private final String version;
|
||||
|
||||
public ProviderInfo(String name, String version) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,11 @@ public class ReserveListener extends EconomyAdapter {
|
||||
ReserveListener.economyAPI = api;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderInfo getProviderInfo() {
|
||||
return new ProviderInfo(economyAPI.name(), economyAPI.version());
|
||||
}
|
||||
|
||||
public static EconomyAPI getProvider() {
|
||||
return economyAPI;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.server.ServiceRegisterEvent;
|
||||
import org.bukkit.event.server.ServiceUnregisterEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
@ -37,6 +38,7 @@ import com.Acrobot.ChestShop.Events.Economy.CurrencyTransferEvent;
|
||||
public class VaultListener extends EconomyAdapter {
|
||||
private RegisteredServiceProvider<Economy> rsp;
|
||||
private static Economy provider;
|
||||
private Plugin providingPlugin;
|
||||
|
||||
private VaultListener() {
|
||||
updateEconomyProvider();
|
||||
@ -47,6 +49,7 @@ public class VaultListener extends EconomyAdapter {
|
||||
|
||||
if (rsp != null) {
|
||||
provider = rsp.getProvider();
|
||||
providingPlugin = rsp.getPlugin();
|
||||
ChestShop.getBukkitLogger().log(Level.INFO, "Using " + provider.getName() + " as the Economy provider now.");
|
||||
}
|
||||
}
|
||||
@ -60,6 +63,11 @@ public class VaultListener extends EconomyAdapter {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderInfo getProviderInfo() {
|
||||
return new ProviderInfo(provider.getName(), providingPlugin.getDescription().getVersion());
|
||||
}
|
||||
|
||||
public static Economy getProvider() { return provider; }
|
||||
|
||||
public boolean transactionCanFail() {
|
||||
|
Loading…
Reference in New Issue
Block a user