mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-11-25 03:55:35 +01:00
Hook with other bukkit metrics
This commit is contained in:
parent
a84348f478
commit
e9db802e2d
@ -31,6 +31,7 @@ import com.boydti.fawe.regions.FaweMaskManager;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
import com.boydti.fawe.util.metrics.BStats;
|
||||
import com.sk89q.bukkit.util.FallbackRegistrationListener;
|
||||
import com.sk89q.worldedit.bukkit.BukkitPlayerBlockBag;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
@ -53,6 +54,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.primesoft.blockshub.BlocksHubBukkit;
|
||||
|
||||
public class FaweBukkit implements IFawe, Listener {
|
||||
@ -190,6 +192,34 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
public void startMetrics() {
|
||||
Metrics metrics = new Metrics(plugin);
|
||||
metrics.start();
|
||||
TaskManager.IMP.task(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ArrayList<Class<?>> services = new ArrayList(Bukkit.getServicesManager().getKnownServices());
|
||||
services.forEach(service -> {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION");
|
||||
ArrayList<RegisteredServiceProvider<?>> providers = new ArrayList(Bukkit.getServicesManager().getRegistrations(service));
|
||||
for (RegisteredServiceProvider<?> provider : providers) {
|
||||
Object instance = provider.getProvider();
|
||||
|
||||
// Link it to FAWE's metrics instead
|
||||
BStats.linkMetrics(instance);
|
||||
|
||||
// Disable the other metrics
|
||||
Bukkit.getServicesManager().unregister(service, instance);
|
||||
try {
|
||||
Class<? extends Object> clazz = instance.getClass();
|
||||
Field logFailedRequests = ReflectionUtils.setAccessible(clazz.getDeclaredField("logFailedRequests"));
|
||||
logFailedRequests.set(null, false);
|
||||
Field URL = clazz.getDeclaredField("URL");
|
||||
ReflectionUtils.setFailsafeFieldValue(URL, null, null);
|
||||
} catch (NoSuchFieldError | IllegalAccessException ignore) {}
|
||||
}
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -289,14 +289,14 @@ public class Fawe {
|
||||
TaskManager.IMP = this.IMP.getTaskManager();
|
||||
if (Settings.IMP.METRICS) {
|
||||
try {
|
||||
BStats stats = new BStats();
|
||||
this.IMP.startMetrics();
|
||||
TaskManager.IMP.task(new Runnable() {
|
||||
TaskManager.IMP.later(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Run it when the plugin loads
|
||||
BStats stats = new BStats();
|
||||
stats.start();
|
||||
}
|
||||
});
|
||||
}, 1);
|
||||
} catch (Throwable ignore) {
|
||||
ignore.printStackTrace();
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -59,7 +58,8 @@ public class BStats implements Closeable {
|
||||
private boolean logFailedRequests = false;
|
||||
|
||||
// A list with all known metrics class objects including this one
|
||||
private static final Collection<Object> knownMetricsInstances = new ConcurrentLinkedQueue<>();
|
||||
private static Class<?> usedMetricsClass;
|
||||
private static final ConcurrentLinkedQueue<Object> knownMetricsInstances = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public BStats() {
|
||||
this("FastAsyncWorldEdit", Fawe.get().getVersion().toString(), Fawe.imp().getPlatformVersion(), Fawe.imp().getPlatform(), Fawe.imp().isOnlineMode());
|
||||
@ -106,7 +106,12 @@ public class BStats implements Closeable {
|
||||
// Load the data
|
||||
serverUUID = UUID.fromString(config.getString("serverUuid"));
|
||||
|
||||
Class<?> usedMetricsClass = getFirstBStatsClass();
|
||||
if (usedMetricsClass != null) {
|
||||
// Already an instance of this class
|
||||
linkMetrics(this);
|
||||
return;
|
||||
}
|
||||
this.usedMetricsClass = getFirstBStatsClass();
|
||||
if (usedMetricsClass == null) {
|
||||
// Failed to get first metrics class
|
||||
return;
|
||||
@ -115,7 +120,6 @@ public class BStats implements Closeable {
|
||||
// We are the first! :)
|
||||
linkMetrics(this);
|
||||
enabled = true;
|
||||
startSubmitting();
|
||||
} else {
|
||||
// We aren't the first so we link to the first metrics class
|
||||
try {
|
||||
@ -128,6 +132,12 @@ public class BStats implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (enabled) {
|
||||
startSubmitting();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Links an other metrics class with this class.
|
||||
* This method is called using Reflection.
|
||||
@ -246,8 +256,7 @@ public class BStats implements Closeable {
|
||||
} else {
|
||||
pluginData.add(gson.fromJson(plugin.toString(), JsonObject.class));
|
||||
}
|
||||
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NullPointerException | JsonSyntaxException ignored) { }
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NullPointerException | JsonSyntaxException ignored) {}
|
||||
}
|
||||
|
||||
data.add("plugins", pluginData);
|
||||
|
Loading…
Reference in New Issue
Block a user