Skip to content

Commit

Permalink
feat: Implement bstats metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed Nov 26, 2022
1 parent f1db3fe commit c9bda53
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ bin/
.classpath
.factorypath
.project
.vscode/
.vscode/
/run/
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ val geantyref: String = property("geantyrefVersion") as String
val caffeine: String = property("caffeineVersion") as String

dependencies {
implementation("org.bstats:bstats-velocity:3.0.0")
implementation("com.github.AlessioDP.libby:libby-velocity:43d25ade72")
compileOnly("org.spongepowered:configurate-hocon:$configurate")
compileOnly("io.leangen.geantyref:geantyref:$geantyref")
Expand All @@ -33,6 +34,7 @@ dependencies {
testImplementation("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT")
testImplementation("org.slf4j:slf4j-api:2.0.4")
testImplementation("com.github.ben-manes.caffeine:caffeine:$caffeine")
testImplementation("org.bstats:bstats-velocity:3.0.0")
}

blossom {
Expand All @@ -57,6 +59,7 @@ tasks {
relocate("net.byteflux", "me.dreamerzero.kickredirect.libs.byteflux")
relocate("io.leangen.geantyref", "me.dreamerzero.kickredirect.libs.geantyref")
relocate("com.github.ben-manes.caffeine", "me.dreamerzero.kickredirect.libs.caffeine")
relocate("org.bstats", "me.dreamerzero.kickredirect.libs.bstats")
}

test {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = me.dreamerzero.kickredirect
version = 2.0.4
version = 2.0.5-SNAPSHOT
description = Set the redirect result of your servers shutdown
url = https://github.com/4drian3d/KickRedirect
id = kickredirect
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/me/dreamerzero/kickredirect/Dependencies.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package me.dreamerzero.kickredirect;

import com.velocitypowered.api.plugin.PluginManager;
import me.dreamerzero.kickredirect.utils.Constants;
import net.byteflux.libby.Library;
import net.byteflux.libby.VelocityLibraryManager;
import net.byteflux.libby.relocation.Relocation;
import org.slf4j.Logger;

import java.nio.file.Path;

public final class Dependencies {
private Dependencies() {}
static void loadDependencies(KickRedirect plugin, Logger logger, PluginManager manager, Path path) {
final VelocityLibraryManager<KickRedirect> libraryManager
= new VelocityLibraryManager<>(logger, path, manager, plugin, "libs");
final Relocation configurateRelocation
= new Relocation("org{}spongepowered", "me.dreamerzero.kickredirect.libs.sponge");
final Relocation geantyrefRelocation =
new Relocation("io{}leangen{}geantyref", "me.dreamerzero.kickredirect.libs.geantyref");
final Library hocon = Library.builder()
.groupId("org{}spongepowered")
.artifactId("configurate-hocon")
.version(Constants.CONFIGURATE)
.id("configurate-hocon")
.relocate(configurateRelocation)
.relocate(geantyrefRelocation)
.build();
final Library confCore = Library.builder()
.groupId("org{}spongepowered")
.artifactId("configurate-core")
.version(Constants.CONFIGURATE)
.id("configurate-core")
.relocate(configurateRelocation)
.relocate(geantyrefRelocation)
.build();
final Library geantyref = Library.builder()
.groupId("io{}leangen{}geantyref")
.artifactId("geantyref")
.version(Constants.GEANTYREF)
.id("geantyref")
.relocate(geantyrefRelocation)
.build();
final Library caffeine = Library.builder()
.groupId("com{}github{}ben-manes{}caffeine")
.artifactId("caffeine")
.version(Constants.CAFFEINE)
.id("caffeine")
.relocate("com{}github{}ben-manes{}caffeine", "me.dreamerzero.kickredirect.libs.caffeine")
.build();

libraryManager.addMavenCentral();
libraryManager.loadLibrary(geantyref);
libraryManager.loadLibrary(hocon);
libraryManager.loadLibrary(confCore);
libraryManager.loadLibrary(caffeine);
}
}
60 changes: 9 additions & 51 deletions src/main/java/me/dreamerzero/kickredirect/KickRedirect.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;

import org.bstats.velocity.Metrics;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

Expand All @@ -28,9 +29,6 @@
import me.dreamerzero.kickredirect.listener.KickListener;
import me.dreamerzero.kickredirect.utils.Constants;
import me.dreamerzero.kickredirect.utils.DebugInfo;
import net.byteflux.libby.Library;
import net.byteflux.libby.VelocityLibraryManager;
import net.byteflux.libby.relocation.Relocation;
import net.kyori.adventure.text.minimessage.MiniMessage;

@Plugin(
Expand All @@ -54,6 +52,7 @@ public final class KickRedirect {
private final Path pluginPath;
private final Logger logger;
private final PluginManager pluginManager;
private final Metrics.Factory metrics;
private Formatter formatter;
private ConfigurationContainer<Configuration.Config> config;
private ConfigurationContainer<Configuration.Messages> messages;
Expand All @@ -64,16 +63,20 @@ public KickRedirect(
final ProxyServer proxy,
final @DataDirectory Path pluginPath,
final Logger logger,
final PluginManager pluginManager
final PluginManager pluginManager,
final Metrics.Factory metrics
) {
this.pluginPath = pluginPath;
this.proxy = proxy;
this.logger = logger;
this.pluginManager = pluginManager;
this.metrics = metrics;
}

@Subscribe
public void onProxyInitialization(final ProxyInitializeEvent event){
public void onProxyInitialization(final ProxyInitializeEvent event) {
int pluginId = 16944;
metrics.make(this, pluginId);
this.initialize(false);
}

Expand Down Expand Up @@ -110,51 +113,6 @@ public Cache<UUID, DebugInfo> debugCache() {
return this.cache;
}

private void loadDependencies() {
final VelocityLibraryManager<KickRedirect> libraryManager
= new VelocityLibraryManager<>(this.logger, this.pluginPath, pluginManager, this, "libs");
final Relocation configurateRelocation
= new Relocation("org{}spongepowered", "me.dreamerzero.kickredirect.libs.sponge");
final Relocation geantyrefRelocation =
new Relocation("io{}leangen{}geantyref", "me.dreamerzero.kickredirect.libs.geantyref");
final Library hocon = Library.builder()
.groupId("org{}spongepowered")
.artifactId("configurate-hocon")
.version(Constants.CONFIGURATE)
.id("configurate-hocon")
.relocate(configurateRelocation)
.relocate(geantyrefRelocation)
.build();
final Library confCore = Library.builder()
.groupId("org{}spongepowered")
.artifactId("configurate-core")
.version(Constants.CONFIGURATE)
.id("configurate-core")
.relocate(configurateRelocation)
.relocate(geantyrefRelocation)
.build();
final Library geantyref = Library.builder()
.groupId("io{}leangen{}geantyref")
.artifactId("geantyref")
.version(Constants.GEANTYREF)
.id("geantyref")
.relocate(geantyrefRelocation)
.build();
final Library caffeine = Library.builder()
.groupId("com{}github{}ben-manes{}caffeine")
.artifactId("caffeine")
.version(Constants.CAFFEINE)
.id("caffeine")
.relocate("com{}github{}ben-manes{}caffeine", "me.dreamerzero.kickredirect.libs.caffeine")
.build();

libraryManager.addMavenCentral();
libraryManager.loadLibrary(geantyref);
libraryManager.loadLibrary(hocon);
libraryManager.loadLibrary(confCore);
libraryManager.loadLibrary(caffeine);
}

public boolean loadConfig() {
this.config = Configuration.loadMainConfig(this);
this.messages = Configuration.loadMessages(this);
Expand All @@ -167,7 +125,7 @@ void initialize(final boolean test) {
MiniMessage.miniMessage().deserialize("<gradient:red:#fff494>[KickRedirect]</gradient> <gradient:#78edff:#699dff>Starting plugin...")
);
if (!test) {
this.loadDependencies();
Dependencies.loadDependencies(this, this.logger, pluginManager, pluginPath);
}
if (!this.loadConfig()) {
return;
Expand Down
14 changes: 5 additions & 9 deletions src/test/java/me/dreamerzero/kickredirect/EventBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.velocitypowered.api.event.player.KickedFromServerEvent;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.plugin.PluginManager;

import me.dreamerzero.kickredirect.listener.DebugListener;
import me.dreamerzero.kickredirect.listener.KickListener;
Expand All @@ -27,10 +26,11 @@ public final class EventBundle {
private EventBundle(final Builder builder) {
this.proxyServer = builder.proxy == null ? new TestProxyServer() : builder.proxy;
this.plugin = new KickRedirect(
this.proxyServer,
builder.path,
LoggerFactory.getLogger(EventBundle.class),
this.proxyServer.getPluginManager()
this.proxyServer,
builder.path,
LoggerFactory.getLogger(EventBundle.class),
this.proxyServer.getPluginManager(),
null
);
plugin.initialize(true);
if(builder.debug)
Expand All @@ -48,10 +48,6 @@ public KickRedirect getPlugin() {
return plugin;
}

public PluginManager getPluginManager() {
return proxyServer.getPluginManager();
}

public TestContinuation getContinuation() {
return continuation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;

@SuppressWarnings("deprecation")
public class TestPlayer implements Player {
private final boolean op;
private final String name;
Expand Down

0 comments on commit c9bda53

Please sign in to comment.