feat: Implement metrics

This commit is contained in:
Adrian3d04 2022-08-14 00:30:50 +00:00
parent 0d8630452f
commit 03630dadb0
4 changed files with 38 additions and 5 deletions

View File

@ -1,3 +1,11 @@
dependencies { dependencies {
compileOnly("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT") compileOnly("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT")
} }
tasks.compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
}
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))

View File

@ -18,4 +18,11 @@ tasks {
relocate("net.byteflux.libby", "me.adrianed.authmevelocity.libs.libby") relocate("net.byteflux.libby", "me.adrianed.authmevelocity.libs.libby")
relocate("org.spongepowered", "me.adrianed.authmevelocity.libs.sponge") relocate("org.spongepowered", "me.adrianed.authmevelocity.libs.sponge")
} }
} compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
}
}
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))

View File

@ -14,6 +14,7 @@ dependencies {
compileOnly("com.github.4drian3d:MiniPlaceholders:1.1.1") compileOnly("com.github.4drian3d:MiniPlaceholders:1.1.1")
compileOnly("com.github.games647:fastlogin.velocity:1.11-SNAPSHOT") compileOnly("com.github.games647:fastlogin.velocity:1.11-SNAPSHOT")
shadow("net.byteflux:libby-velocity:1.1.5") shadow("net.byteflux:libby-velocity:1.1.5")
shadow("org.bstats:bstats-velocity:3.0.0")
compileOnly(project(":authmevelocity-common")) compileOnly(project(":authmevelocity-common"))
compileOnly(project(":authmevelocity-api-velocity")) compileOnly(project(":authmevelocity-api-velocity"))
} }
@ -28,6 +29,7 @@ tasks {
shadowJar { shadowJar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE duplicatesStrategy = DuplicatesStrategy.EXCLUDE
relocate("net.byteflux.libby", "me.adrianed.authmevelocity.libs.libby") relocate("net.byteflux.libby", "me.adrianed.authmevelocity.libs.libby")
relocate("org.bstats", "me.adrianed.authmevelocity.libs.bstats")
configurations = listOf(project.configurations.shadow.get()) configurations = listOf(project.configurations.shadow.get())
} }
} }

View File

@ -28,6 +28,8 @@ import net.byteflux.libby.VelocityLibraryManager;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.bstats.charts.SimplePie;
import org.bstats.velocity.Metrics;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.nio.file.Path; import java.nio.file.Path;
@ -59,15 +61,22 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
private final ProxyServer proxy; private final ProxyServer proxy;
private final Logger logger; private final Logger logger;
private final Path pluginDirectory; private final Path pluginDirectory;
private final Metrics.Factory metricsFactory;
private ConfigurationContainer<ProxyConfiguration> config; private ConfigurationContainer<ProxyConfiguration> config;
protected final Set<UUID> loggedPlayers = ConcurrentHashMap.newKeySet(); protected final Set<UUID> loggedPlayers = ConcurrentHashMap.newKeySet();
@Inject @Inject
public AuthMeVelocityPlugin(ProxyServer proxy, Logger logger, @DataDirectory Path dataDirectory) { public AuthMeVelocityPlugin(
ProxyServer proxy,
Logger logger,
@DataDirectory Path dataDirectory,
Metrics.Factory factory
) {
this.proxy = proxy; this.proxy = proxy;
this.logger = logger; this.logger = logger;
this.pluginDirectory = dataDirectory; this.pluginDirectory = dataDirectory;
this.metricsFactory = factory;
} }
@Subscribe @Subscribe
@ -81,6 +90,9 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
this.config = Loader.loadMainConfig(pluginDirectory, ProxyConfiguration.class, logger); this.config = Loader.loadMainConfig(pluginDirectory, ProxyConfiguration.class, logger);
final int pluginId = 16128;
Metrics metrics = metricsFactory.make(this, pluginId);
proxy.getChannelRegistrar().register(AUTHMEVELOCITY_CHANNEL); proxy.getChannelRegistrar().register(AUTHMEVELOCITY_CHANNEL);
List.of( List.of(
@ -90,12 +102,16 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
).forEach(listener -> ).forEach(listener ->
proxy.getEventManager().register(this, listener)); proxy.getEventManager().register(this, listener));
if (proxy.getPluginManager().isLoaded("fastlogin")) { boolean fastlogin = proxy.getPluginManager().isLoaded("fastlogin");
metrics.addCustomChart(new SimplePie("fastlogin_compatibility", () -> Boolean.toString(fastlogin)));
if (fastlogin) {
logDebug("Register FastLogin compatibility"); logDebug("Register FastLogin compatibility");
proxy.getEventManager().register(this, new FastLoginListener(proxy, this)); proxy.getEventManager().register(this, new FastLoginListener(proxy, this));
} }
if (proxy.getPluginManager().isLoaded("miniplaceholders")) { boolean miniplaceholders = proxy.getPluginManager().isLoaded("miniplaceholders");
metrics.addCustomChart(new SimplePie("miniplaceholders_compatibility", () -> Boolean.toString(miniplaceholders)));
if (miniplaceholders) {
logDebug("Register MiniPlaceholders compatibility"); logDebug("Register MiniPlaceholders compatibility");
AuthMePlaceholders.getExpansion(this).register(); AuthMePlaceholders.getExpansion(this).register();
} }