From bbbc1b2407c4ee126c63307e05abe9f1c3a02c62 Mon Sep 17 00:00:00 2001 From: SamB440 Date: Fri, 10 Jan 2025 13:59:49 +0000 Subject: [PATCH 1/5] Add sponge support --- .../metrics/api/platform/PlatformType.kt | 1 + platforms/sponge/build.gradle.kts | 83 +++++++++++++++++++ .../metrics/sponge/SpongeDispatcher.kt | 56 +++++++++++++ .../sponge/UnifiedMetricsSpongePlugin.kt | 45 ++++++++++ .../UnifiedMetricsSpongeBootstrap.kt | 76 +++++++++++++++++ .../metrics/sponge/logger/Log4jLogger.kt | 43 ++++++++++ .../sponge/metric/events/EventsCollection.kt | 74 +++++++++++++++++ .../sponge/metric/server/ServerCollection.kt | 27 ++++++ .../sponge/metric/server/ServerCollector.kt | 34 ++++++++ .../sponge/metric/tick/TickCollection.kt | 53 ++++++++++++ .../sponge/metric/tick/TickReporter.kt | 53 ++++++++++++ .../sponge/metric/world/WorldCollection.kt | 26 ++++++ .../sponge/metric/world/WorldCollector.kt | 43 ++++++++++ settings.gradle.kts | 3 + 14 files changed, 617 insertions(+) create mode 100644 platforms/sponge/build.gradle.kts create mode 100644 platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/SpongeDispatcher.kt create mode 100644 platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/UnifiedMetricsSpongePlugin.kt create mode 100644 platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/bootstrap/UnifiedMetricsSpongeBootstrap.kt create mode 100644 platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/logger/Log4jLogger.kt create mode 100644 platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/events/EventsCollection.kt create mode 100644 platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/server/ServerCollection.kt create mode 100644 platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/server/ServerCollector.kt create mode 100644 platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickCollection.kt create mode 100644 platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickReporter.kt create mode 100644 platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/world/WorldCollection.kt create mode 100644 platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/world/WorldCollector.kt diff --git a/api/src/main/kotlin/dev/cubxity/plugins/metrics/api/platform/PlatformType.kt b/api/src/main/kotlin/dev/cubxity/plugins/metrics/api/platform/PlatformType.kt index d593e11f..8c172a8e 100644 --- a/api/src/main/kotlin/dev/cubxity/plugins/metrics/api/platform/PlatformType.kt +++ b/api/src/main/kotlin/dev/cubxity/plugins/metrics/api/platform/PlatformType.kt @@ -22,6 +22,7 @@ sealed class PlatformType(val name: String) { object Bukkit : PlatformType("Bukkit") object Minestom : PlatformType("Minestom") object Fabric : PlatformType("Fabric") + object Sponge : PlatformType("Sponge") // Proxies object Velocity : PlatformType("Velocity") diff --git a/platforms/sponge/build.gradle.kts b/platforms/sponge/build.gradle.kts new file mode 100644 index 00000000..8da4e7ba --- /dev/null +++ b/platforms/sponge/build.gradle.kts @@ -0,0 +1,83 @@ +/* + * This file is part of UnifiedMetrics. + * + * UnifiedMetrics is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * UnifiedMetrics is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with UnifiedMetrics. If not, see . + */ + +import org.spongepowered.gradle.plugin.config.PluginLoaders +import org.spongepowered.plugin.metadata.model.PluginDependency +import org.jetbrains.kotlin.gradle.dsl.JvmTarget + +plugins { + id("org.spongepowered.gradle.plugin") version("2.0.2") + id("com.github.johnrengelman.shadow") +} + +sponge { + apiVersion("12.0.0-SNAPSHOT") + loader { + name(PluginLoaders.JAVA_PLAIN) + version("1.0.0-SNAPSHOT") + } + plugin("unifiedmetrics") { + displayName("UnifiedMetrics") + entrypoint("dev.cubxity.plugins.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap") + description("Fully-featured metrics plugin for Minecraft servers") + license("GPL-3") + dependency("spongeapi") { + loadOrder(PluginDependency.LoadOrder.AFTER) + optional(false) + } + } +} + +dependencies { + api(project(":unifiedmetrics-core")) +} + +tasks { + shadowJar { + archiveClassifier.set("") + relocate("retrofit2", "dev.cubxity.plugins.metrics.libs.retrofit2") + relocate("com.charleskorn", "dev.cubxity.plugins.metrics.libs.com.charleskorn") + relocate("com.influxdb", "dev.cubxity.plugins.metrics.libs.com.influxdb") + relocate("okhttp", "dev.cubxity.plugins.metrics.libs.okhttp") + relocate("okio", "dev.cubxity.plugins.metrics.libs.okio") + relocate("io.prometheus", "dev.cubxity.plugins.metrics.libs.io.prometheus") + relocate("com.google.gson", "dev.cubxity.plugins.metrics.libs.gson") + relocate("org.apache.commons", "dev.cubxity.plugins.metrics.libs.commons") + relocate("org.intellij.lang.annotations", "dev.cubxity.plugins.metrics.libs.intellij.annotations") + relocate("org.jetbrains.annotations", "dev.cubxity.plugins.metrics.libs.jetbrains.annotations") + relocate("javax.annotation", "dev.cubxity.plugins.metrics.libs.javax.annotations") + relocate("org.reactivestreams", "dev.cubxity.plugins.metrics.libs.reactivestreams") + relocate("net.thauvin.erik.urlencoder", "dev.cubxity.plugins.metrics.libs.urlencoder") + relocate("it.krzeminski.snakeyaml", "dev.cubxxity.plugins.metrics.libs.snakeyaml") + relocate("io.reactivex.rxjava3", "dev.cubxity.plugins.metrics.libs.rxjava") + relocate("kotlin", "dev.cubxity.plugins.metrics.libs.kotlin") + relocate("kotlinx", "dev.cubxity.plugins.metrics.libs.kotlinx") + } + + compileKotlin { + compilerOptions.jvmTarget.set(JvmTarget.JVM_21) + } + + compileJava { + options.encoding = "UTF-8" + } +} + +java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 +} \ No newline at end of file diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/SpongeDispatcher.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/SpongeDispatcher.kt new file mode 100644 index 00000000..0318f6c5 --- /dev/null +++ b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/SpongeDispatcher.kt @@ -0,0 +1,56 @@ +/* + * This file is part of UnifiedMetrics. + * + * UnifiedMetrics is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * UnifiedMetrics is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with UnifiedMetrics. If not, see . + */ + +package dev.cubxity.plugins.metrics.sponge + +import dev.cubxity.plugins.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap +import kotlinx.coroutines.CancellableContinuation +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Delay +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.InternalCoroutinesApi +import kotlinx.coroutines.isActive +import org.spongepowered.api.scheduler.Task +import java.util.concurrent.TimeUnit +import kotlin.coroutines.CoroutineContext + +@OptIn(InternalCoroutinesApi::class) +class SpongeDispatcher(private val plugin: UnifiedMetricsSpongeBootstrap): CoroutineDispatcher(), Delay { + + override fun dispatch(context: CoroutineContext, block: Runnable) { + if (!context.isActive) return + if (plugin.server.onMainThread()) { + block.run() + } else { + plugin.server.scheduler().submit(Task.builder().execute(block).plugin(plugin.container).build()) + } + } + + @OptIn(ExperimentalCoroutinesApi::class) + override fun scheduleResumeAfterDelay(timeMillis: Long, continuation: CancellableContinuation) { + val task = plugin.server.scheduler().submit( + Task.builder() + .delay(timeMillis, TimeUnit.MILLISECONDS) + .execute(Runnable { + continuation.apply { resumeUndispatched(Unit) } + }) + .plugin(plugin.container) + .build() + ) + continuation.invokeOnCancellation { task.cancel() } + } +} \ No newline at end of file diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/UnifiedMetricsSpongePlugin.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/UnifiedMetricsSpongePlugin.kt new file mode 100644 index 00000000..61c74581 --- /dev/null +++ b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/UnifiedMetricsSpongePlugin.kt @@ -0,0 +1,45 @@ +/* + * This file is part of UnifiedMetrics. + * + * UnifiedMetrics is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * UnifiedMetrics is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with UnifiedMetrics. If not, see . + */ + +package dev.cubxity.plugins.metrics.sponge + +import dev.cubxity.plugins.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap +import dev.cubxity.plugins.metrics.api.UnifiedMetrics +import dev.cubxity.plugins.metrics.core.plugin.CoreUnifiedMetricsPlugin +import dev.cubxity.plugins.metrics.sponge.metric.events.EventsCollection +import dev.cubxity.plugins.metrics.sponge.metric.server.ServerCollection +import dev.cubxity.plugins.metrics.sponge.metric.tick.TickCollection +import dev.cubxity.plugins.metrics.sponge.metric.world.WorldCollection + +class UnifiedMetricsSpongePlugin( + override val bootstrap: UnifiedMetricsSpongeBootstrap +): CoreUnifiedMetricsPlugin() { + + override fun registerPlatformService(api: UnifiedMetrics) { + super.registerPlatformMetrics() + + apiProvider.metricsManager.apply { + with(config.metrics.collectors) { + if (server) registerCollection(ServerCollection(bootstrap)) + if (events) registerCollection(EventsCollection(bootstrap)) + if (tick) registerCollection(TickCollection(bootstrap)) + if (world) registerCollection(WorldCollection(bootstrap)) + } + } + } + +} \ No newline at end of file diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/bootstrap/UnifiedMetricsSpongeBootstrap.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/bootstrap/UnifiedMetricsSpongeBootstrap.kt new file mode 100644 index 00000000..45cd68a7 --- /dev/null +++ b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/bootstrap/UnifiedMetricsSpongeBootstrap.kt @@ -0,0 +1,76 @@ +/* + * This file is part of UnifiedMetrics. + * + * UnifiedMetrics is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * UnifiedMetrics is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with UnifiedMetrics. If not, see . + */ + +package dev.cubxity.plugins.metrics.sponge.bootstrap + +import com.google.inject.Inject +import dev.cubxity.plugins.metrics.api.logging.Logger +import dev.cubxity.plugins.metrics.api.platform.PlatformType +import dev.cubxity.plugins.metrics.common.UnifiedMetricsBootstrap +import dev.cubxity.plugins.metrics.sponge.SpongeDispatcher +import dev.cubxity.plugins.metrics.sponge.UnifiedMetricsSpongePlugin +import dev.cubxity.plugins.metrics.sponge.logger.Log4jLogger +import kotlinx.coroutines.CoroutineDispatcher +import org.spongepowered.api.Game +import org.spongepowered.api.MinecraftVersion +import org.spongepowered.api.Server +import org.spongepowered.api.config.ConfigDir +import org.spongepowered.api.event.Listener +import org.spongepowered.api.event.lifecycle.StartedEngineEvent +import org.spongepowered.api.event.lifecycle.StoppingEngineEvent +import org.spongepowered.api.plugin.PluginManager +import org.spongepowered.plugin.PluginContainer +import org.spongepowered.plugin.builtin.jvm.Plugin +import java.nio.file.Path + +@Plugin("unifiedmetrics") +class UnifiedMetricsSpongeBootstrap @Inject constructor( + val container: PluginContainer, + val pluginManager: PluginManager, + private val game: Game, + private val serverLogger: org.apache.logging.log4j.Logger, + private val serverVersion: MinecraftVersion, + @ConfigDir(sharedRoot = false) override val configDirectory: Path +): UnifiedMetricsBootstrap { + + val server: Server + get() = game.server() + + private val plugin = UnifiedMetricsSpongePlugin(this) + override val type: PlatformType + get() = PlatformType.Sponge + + private val containerVersion = container.metadata().version() + override val version: String + get() = "${containerVersion.majorVersion}.${containerVersion.minorVersion}.${containerVersion.incrementalVersion}#${containerVersion.buildNumber}" + override val serverBrand: String + get() = serverVersion.name() + override val dataDirectory: Path = configDirectory + override val logger: Logger + get() = Log4jLogger(serverLogger) + override val dispatcher: CoroutineDispatcher = SpongeDispatcher(this) + + @Listener + fun onServerStart(event: StartedEngineEvent) { + plugin.enable() + } + + @Listener + fun onServerStop(event: StoppingEngineEvent) { + plugin.disable() + } +} \ No newline at end of file diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/logger/Log4jLogger.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/logger/Log4jLogger.kt new file mode 100644 index 00000000..6451d16a --- /dev/null +++ b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/logger/Log4jLogger.kt @@ -0,0 +1,43 @@ +/* + * This file is part of UnifiedMetrics. + * + * UnifiedMetrics is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * UnifiedMetrics is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with UnifiedMetrics. If not, see . + */ + +package dev.cubxity.plugins.metrics.sponge.logger + +import dev.cubxity.plugins.metrics.api.logging.Logger +import org.apache.logging.log4j.Level + +class Log4jLogger(private val logger: org.apache.logging.log4j.Logger): Logger { + override fun info(message: String) { + logger.log(Level.INFO, message) + } + + override fun warn(message: String) { + logger.log(Level.WARN, message) + } + + override fun warn(message: String, error: Throwable) { + logger.log(Level.WARN, message, error) + } + + override fun severe(message: String) { + logger.log(Level.ERROR, message) + } + + override fun severe(message: String, error: Throwable) { + logger.log(Level.ERROR, message, error) + } +} \ No newline at end of file diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/events/EventsCollection.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/events/EventsCollection.kt new file mode 100644 index 00000000..f49b7078 --- /dev/null +++ b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/events/EventsCollection.kt @@ -0,0 +1,74 @@ +/* + * This file is part of UnifiedMetrics. + * + * UnifiedMetrics is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * UnifiedMetrics is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with UnifiedMetrics. If not, see . + */ + +package dev.cubxity.plugins.metrics.sponge.metric.events + +import dev.cubxity.plugins.metrics.api.metric.collector.Collector +import dev.cubxity.plugins.metrics.api.metric.collector.CollectorCollection +import dev.cubxity.plugins.metrics.api.metric.collector.Counter +import dev.cubxity.plugins.metrics.api.metric.store.VolatileDoubleStore +import dev.cubxity.plugins.metrics.common.metric.Metrics +import dev.cubxity.plugins.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap +import org.spongepowered.api.Sponge +import org.spongepowered.api.event.Listener +import org.spongepowered.api.event.message.PlayerChatEvent +import org.spongepowered.api.event.network.ServerSideConnectionEvent.* +import org.spongepowered.api.event.server.ClientPingServerEvent + +class EventsCollection(private val bootstrap: UnifiedMetricsSpongeBootstrap) : CollectorCollection { + + private val loginCounter = Counter(Metrics.Events.Login, valueStoreFactory = VolatileDoubleStore) + private val joinCounter = Counter(Metrics.Events.Join) + private val quitCounter = Counter(Metrics.Events.Quit, valueStoreFactory = VolatileDoubleStore) + private val chatCounter = Counter(Metrics.Events.Chat) + private val pingCounter = Counter(Metrics.Events.Ping, valueStoreFactory = VolatileDoubleStore) + + override val collectors: List = listOf(loginCounter, joinCounter, quitCounter, chatCounter, pingCounter) + + override fun initialize() { + Sponge.eventManager().registerListeners(bootstrap.container, this) + } + + override fun dispose() { + Sponge.eventManager().unregisterListeners(this) + } + + @Listener + fun onLogin(event: Join) { + joinCounter.inc() + } + + @Listener + fun onConnect(event: Auth) { + loginCounter.inc() + } + + @Listener + fun onDisconnect(event: Disconnect) { + quitCounter.inc() + } + + @Listener + fun onChat(event: PlayerChatEvent) { + chatCounter.inc() + } + + @Listener + fun onPing(event: ClientPingServerEvent) { + pingCounter.inc() + } +} \ No newline at end of file diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/server/ServerCollection.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/server/ServerCollection.kt new file mode 100644 index 00000000..e01fd466 --- /dev/null +++ b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/server/ServerCollection.kt @@ -0,0 +1,27 @@ +/* + * This file is part of UnifiedMetrics. + * + * UnifiedMetrics is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * UnifiedMetrics is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with UnifiedMetrics. If not, see . + */ + +package dev.cubxity.plugins.metrics.sponge.metric.server + +import dev.cubxity.plugins.metrics.api.metric.collector.Collector +import dev.cubxity.plugins.metrics.api.metric.collector.CollectorCollection +import dev.cubxity.plugins.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap + +class ServerCollection(bootstrap: UnifiedMetricsSpongeBootstrap): CollectorCollection { + + override val collectors: List = listOf(ServerCollector(bootstrap)) +} \ No newline at end of file diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/server/ServerCollector.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/server/ServerCollector.kt new file mode 100644 index 00000000..ffecb99c --- /dev/null +++ b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/server/ServerCollector.kt @@ -0,0 +1,34 @@ +/* + * This file is part of UnifiedMetrics. + * + * UnifiedMetrics is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * UnifiedMetrics is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with UnifiedMetrics. If not, see . + */ + +package dev.cubxity.plugins.metrics.sponge.metric.server + +import dev.cubxity.plugins.metrics.api.metric.collector.Collector +import dev.cubxity.plugins.metrics.api.metric.data.GaugeMetric +import dev.cubxity.plugins.metrics.api.metric.data.Metric +import dev.cubxity.plugins.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap + +class ServerCollector(private val bootstrap: UnifiedMetricsSpongeBootstrap): Collector { + + override fun collect(): List { + return listOf( + GaugeMetric("minecraft_plugins", value = bootstrap.pluginManager.plugins().size), + GaugeMetric("minecraft_players_count", value = bootstrap.server.onlinePlayers().size), + GaugeMetric("minecraft_players_max", value = bootstrap.server.maxPlayers()) + ) + } +} \ No newline at end of file diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickCollection.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickCollection.kt new file mode 100644 index 00000000..482d8510 --- /dev/null +++ b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickCollection.kt @@ -0,0 +1,53 @@ +/* + * This file is part of UnifiedMetrics. + * + * UnifiedMetrics is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * UnifiedMetrics is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with UnifiedMetrics. If not, see . + */ + +package dev.cubxity.plugins.metrics.sponge.metric.tick + +import dev.cubxity.plugins.metrics.api.metric.collector.Collector +import dev.cubxity.plugins.metrics.api.metric.collector.CollectorCollection +import dev.cubxity.plugins.metrics.api.metric.collector.Histogram +import dev.cubxity.plugins.metrics.api.metric.store.VolatileDoubleStore +import dev.cubxity.plugins.metrics.api.metric.store.VolatileLongStore +import dev.cubxity.plugins.metrics.common.metric.Metrics +import dev.cubxity.plugins.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap + +class TickCollection(bootstrap: UnifiedMetricsSpongeBootstrap): CollectorCollection { + + private val reporter = TickReporter(this, bootstrap) + + private val tickDuration = Histogram( + Metrics.Server.TickDurationSeconds, + sumStoreFactory = VolatileDoubleStore, + countStoreFactory = VolatileLongStore + ) + + override val collectors: List = listOf(tickDuration) + + override val isAsync: Boolean = true + + override fun initialize() { + reporter.initialize() + } + + override fun dispose() { + reporter.dispose() + } + + fun onTick(duration: Double) { + tickDuration += duration + } +} \ No newline at end of file diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickReporter.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickReporter.kt new file mode 100644 index 00000000..f22fc2dc --- /dev/null +++ b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickReporter.kt @@ -0,0 +1,53 @@ +/* + * This file is part of UnifiedMetrics. + * + * UnifiedMetrics is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * UnifiedMetrics is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with UnifiedMetrics. If not, see . + */ + +package dev.cubxity.plugins.metrics.sponge.metric.tick + +import dev.cubxity.plugins.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap +import org.spongepowered.api.Sponge +import org.spongepowered.api.scheduler.ScheduledTask +import org.spongepowered.api.scheduler.Task +import org.spongepowered.api.util.Ticks + +class TickReporter( + private val metric: TickCollection, + bootstrap: UnifiedMetricsSpongeBootstrap +) { + + private lateinit var task: ScheduledTask + + private val taskExecutor = Task.builder() + .delay(Ticks.of(1)) + .execute(Runnable { + metric.onTick(0.0) + this.startTask() + }) + .plugin(bootstrap.container) + + fun initialize() { + startTask() + } + + private fun startTask() { + task = Sponge.asyncScheduler().submit(taskExecutor.build()) + } + + fun dispose() { + task.cancel() + } + +} \ No newline at end of file diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/world/WorldCollection.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/world/WorldCollection.kt new file mode 100644 index 00000000..7084a71d --- /dev/null +++ b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/world/WorldCollection.kt @@ -0,0 +1,26 @@ +/* + * This file is part of UnifiedMetrics. + * + * UnifiedMetrics is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * UnifiedMetrics is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with UnifiedMetrics. If not, see . + */ + +package dev.cubxity.plugins.metrics.sponge.metric.world + +import dev.cubxity.plugins.metrics.api.metric.collector.Collector +import dev.cubxity.plugins.metrics.api.metric.collector.CollectorCollection +import dev.cubxity.plugins.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap + +class WorldCollection(bootstrap: UnifiedMetricsSpongeBootstrap): CollectorCollection { + override val collectors: List = listOf(WorldCollector(bootstrap)) +} \ No newline at end of file diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/world/WorldCollector.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/world/WorldCollector.kt new file mode 100644 index 00000000..bf2b9b6b --- /dev/null +++ b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/world/WorldCollector.kt @@ -0,0 +1,43 @@ +/* + * This file is part of UnifiedMetrics. + * + * UnifiedMetrics is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * UnifiedMetrics is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with UnifiedMetrics. If not, see . + */ + +package dev.cubxity.plugins.metrics.sponge.metric.world + +import dev.cubxity.plugins.metrics.api.metric.collector.Collector +import dev.cubxity.plugins.metrics.api.metric.data.GaugeMetric +import dev.cubxity.plugins.metrics.api.metric.data.Metric +import dev.cubxity.plugins.metrics.api.util.fastForEach +import dev.cubxity.plugins.metrics.common.metric.Metrics +import dev.cubxity.plugins.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap +import org.spongepowered.api.world.server.ServerWorld + +class WorldCollector(private val bootstrap: UnifiedMetricsSpongeBootstrap): Collector { + + override fun collect(): List { + val worldManager = bootstrap.server.worldManager() + val worlds: List = worldManager.worlds().toList() + val samples = ArrayList(worlds.size * 3) + + worlds.fastForEach { + val tags = mapOf("world" to it.key().value()) + samples.add(GaugeMetric(Metrics.Server.WorldEntitiesCount, tags, it.entities().size)) + samples.add(GaugeMetric(Metrics.Server.WorldPlayersCount, tags, it.players().size)) + samples.add(GaugeMetric(Metrics.Server.WorldLoadedChunks, tags, it.loadedChunks().toSet().size)) + } + return samples + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index d9bfa666..961dc630 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -30,6 +30,7 @@ include(modulePrefix + platformPrefix + "bukkit") include(modulePrefix + platformPrefix + "velocity") include(modulePrefix + platformPrefix + "bungee") include(modulePrefix + platformPrefix + "fabric") +include(modulePrefix + platformPrefix + "sponge") include(modulePrefix + driverPrefix + "influx") include(modulePrefix + driverPrefix + "prometheus") @@ -44,6 +45,7 @@ project(modulePrefix + platformPrefix + "bukkit").projectDir = File(platformsDir project(modulePrefix + platformPrefix + "velocity").projectDir = File(platformsDir, "velocity") project(modulePrefix + platformPrefix + "bungee").projectDir = File(platformsDir, "bungee") project(modulePrefix + platformPrefix + "fabric").projectDir = File(platformsDir, "fabric") +project(modulePrefix + platformPrefix + "sponge").projectDir = File(platformsDir, "sponge") val driversDir = File(rootDir, "drivers") project(modulePrefix + driverPrefix + "influx").projectDir = File(driversDir, "influx") @@ -56,5 +58,6 @@ pluginManagement { name = "Fabric" url = uri("https://maven.fabricmc.net/") } + maven("https://repo.spongepowered.org/repository/maven-public/") // Sponge } } From d4aa5a63985a615190dc200ebbbaca69079f66ea Mon Sep 17 00:00:00 2001 From: SamB440 Date: Fri, 10 Jan 2025 14:27:30 +0000 Subject: [PATCH 2/5] Add sponge to issue template and README --- .github/ISSUE_TEMPLATE/bug-report.yml | 1 + README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index 17b8bc79..2f1bbc5d 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -32,6 +32,7 @@ body: options: - Spigot (includes Spigot-based forks) - Fabric + - Sponge - Minestom - Velocity - Bungeecord / Waterfall diff --git a/README.md b/README.md index b1c0861a..c43a2e58 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Click [here](https://unifiedmetrics-demo.cubxity.dev) for live preview! - 1.8+ Spigot servers *(includes Spigot-based forks)* - 1.16+ Fabric servers +- Sponge API 12+ - Minestom - Velocity - BungeeCord From b2d3d5f41e191bd8a564f753187da3eab8063187 Mon Sep 17 00:00:00 2001 From: SamB440 Date: Fri, 10 Jan 2025 14:29:47 +0000 Subject: [PATCH 3/5] Update ServerCollector to use correct names --- .../metrics/sponge/metric/server/ServerCollector.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/server/ServerCollector.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/server/ServerCollector.kt index ffecb99c..037ad99f 100644 --- a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/server/ServerCollector.kt +++ b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/server/ServerCollector.kt @@ -20,15 +20,16 @@ package dev.cubxity.plugins.metrics.sponge.metric.server import dev.cubxity.plugins.metrics.api.metric.collector.Collector import dev.cubxity.plugins.metrics.api.metric.data.GaugeMetric import dev.cubxity.plugins.metrics.api.metric.data.Metric +import dev.cubxity.plugins.metrics.common.metric.Metrics import dev.cubxity.plugins.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap class ServerCollector(private val bootstrap: UnifiedMetricsSpongeBootstrap): Collector { override fun collect(): List { return listOf( - GaugeMetric("minecraft_plugins", value = bootstrap.pluginManager.plugins().size), - GaugeMetric("minecraft_players_count", value = bootstrap.server.onlinePlayers().size), - GaugeMetric("minecraft_players_max", value = bootstrap.server.maxPlayers()) + GaugeMetric(Metrics.Server.Plugins, value = bootstrap.pluginManager.plugins().size), + GaugeMetric(Metrics.Server.PlayersCount, value = bootstrap.server.onlinePlayers().size), + GaugeMetric(Metrics.Server.PlayersMax, value = bootstrap.server.maxPlayers()) ) } } \ No newline at end of file From d57d1393fb046b6120d9a5145c3adc2b0fee49d7 Mon Sep 17 00:00:00 2001 From: SamB440 Date: Fri, 10 Jan 2025 15:26:38 +0000 Subject: [PATCH 4/5] Properly track MSPT --- platforms/sponge/build.gradle.kts | 18 +++++ .../sponge/mixins/MinecraftServerMixin.java | 72 +++++++++++++++++++ .../metrics/sponge/events/TickEndEvent.kt | 27 +++++++ .../sponge/metric/tick/TickCollection.kt | 19 +++-- .../sponge/metric/tick/TickReporter.kt | 53 -------------- .../main/resources/unifiedmetrics.mixins.json | 12 ++++ 6 files changed, 141 insertions(+), 60 deletions(-) create mode 100644 platforms/sponge/src/main/java/dev/cubxity/plugins/metrics/sponge/mixins/MinecraftServerMixin.java create mode 100644 platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/events/TickEndEvent.kt delete mode 100644 platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickReporter.kt create mode 100644 platforms/sponge/src/main/resources/unifiedmetrics.mixins.json diff --git a/platforms/sponge/build.gradle.kts b/platforms/sponge/build.gradle.kts index 8da4e7ba..e15be0d7 100644 --- a/platforms/sponge/build.gradle.kts +++ b/platforms/sponge/build.gradle.kts @@ -16,14 +16,30 @@ */ import org.spongepowered.gradle.plugin.config.PluginLoaders +import org.spongepowered.gradle.vanilla.repository.MinecraftPlatform import org.spongepowered.plugin.metadata.model.PluginDependency import org.jetbrains.kotlin.gradle.dsl.JvmTarget plugins { id("org.spongepowered.gradle.plugin") version("2.0.2") + id("org.spongepowered.gradle.vanilla") version "0.2.1-SNAPSHOT" id("com.github.johnrengelman.shadow") } +minecraft { + latestRelease() + platform(MinecraftPlatform.SERVER) +} + +val mixinConfigsAttribute: String by extra { "unifiedmetrics.mixins.json" } +tasks.withType { + manifest { + attributes( + mapOf("MixinConfigs" to mixinConfigsAttribute) + ) + } +} + sponge { apiVersion("12.0.0-SNAPSHOT") loader { @@ -44,10 +60,12 @@ sponge { dependencies { api(project(":unifiedmetrics-core")) + compileOnly("org.spongepowered:mixin:0.8.6-SNAPSHOT") } tasks { shadowJar { + mergeServiceFiles() archiveClassifier.set("") relocate("retrofit2", "dev.cubxity.plugins.metrics.libs.retrofit2") relocate("com.charleskorn", "dev.cubxity.plugins.metrics.libs.com.charleskorn") diff --git a/platforms/sponge/src/main/java/dev/cubxity/plugins/metrics/sponge/mixins/MinecraftServerMixin.java b/platforms/sponge/src/main/java/dev/cubxity/plugins/metrics/sponge/mixins/MinecraftServerMixin.java new file mode 100644 index 00000000..c40a441d --- /dev/null +++ b/platforms/sponge/src/main/java/dev/cubxity/plugins/metrics/sponge/mixins/MinecraftServerMixin.java @@ -0,0 +1,72 @@ +/* + * This file is part of UnifiedMetrics. + * + * UnifiedMetrics is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * UnifiedMetrics is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with UnifiedMetrics. If not, see . + */ + +package dev.cubxity.plugins.metrics.sponge.mixins; + +import dev.cubxity.plugins.metrics.sponge.events.TickEndEvent; +import net.minecraft.server.MinecraftServer; +import org.spongepowered.api.Sponge; +import org.spongepowered.api.event.Cause; +import org.spongepowered.api.event.EventContext; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import static dev.cubxity.plugins.metrics.api.metric.collector.CollectorKt.NANOSECONDS_PER_MILLISECOND; +import static dev.cubxity.plugins.metrics.api.metric.collector.CollectorKt.NANOSECONDS_PER_SECOND; + +/** + * Designed to emulate paper's tick event as closely as possible. + */ +@Mixin(MinecraftServer.class) +public class MinecraftServerMixin { + + @Unique + private long unifiedmetrics$lastTick = 0; + + @Inject( + method = "runServer", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/MinecraftServer;buildServerStatus()Lnet/minecraft/network/protocol/status/ServerStatus;" + ) + ) + private void onRunServerBeforeLoop(CallbackInfo ci) { + unifiedmetrics$lastTick = System.nanoTime() - ((long) NANOSECONDS_PER_SECOND / 20); + } + + @Inject( + method = "tickServer", + at = @At("HEAD") + ) + private void onTickStart(CallbackInfo ci) { + unifiedmetrics$lastTick = System.nanoTime(); + } + + @Inject( + method = "tickServer", + at = @At( + value = "CONSTANT", + target = "Lnet/minecraft/util/profiling/ProfilerFiller;push(Ljava/lang/String;)V", + args = "stringValue=tallying") + ) + private void onTickEnd(CallbackInfo ci) { + Sponge.eventManager().post(new TickEndEvent((double)(System.nanoTime() - unifiedmetrics$lastTick) / NANOSECONDS_PER_MILLISECOND, Cause.of(EventContext.empty(), Sponge.server()))); + } +} diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/events/TickEndEvent.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/events/TickEndEvent.kt new file mode 100644 index 00000000..4a7e2813 --- /dev/null +++ b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/events/TickEndEvent.kt @@ -0,0 +1,27 @@ +/* + * This file is part of UnifiedMetrics. + * + * UnifiedMetrics is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * UnifiedMetrics is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with UnifiedMetrics. If not, see . + */ +package dev.cubxity.plugins.metrics.sponge.events + +import org.spongepowered.api.event.Cause +import org.spongepowered.api.event.impl.AbstractEvent + +class TickEndEvent(val duration: Double, private val cause: Cause) : AbstractEvent() { + + override fun cause(): Cause { + return cause + } +} \ No newline at end of file diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickCollection.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickCollection.kt index 482d8510..7d06569f 100644 --- a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickCollection.kt +++ b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickCollection.kt @@ -20,14 +20,16 @@ package dev.cubxity.plugins.metrics.sponge.metric.tick import dev.cubxity.plugins.metrics.api.metric.collector.Collector import dev.cubxity.plugins.metrics.api.metric.collector.CollectorCollection import dev.cubxity.plugins.metrics.api.metric.collector.Histogram +import dev.cubxity.plugins.metrics.api.metric.collector.MILLISECONDS_PER_SECOND import dev.cubxity.plugins.metrics.api.metric.store.VolatileDoubleStore import dev.cubxity.plugins.metrics.api.metric.store.VolatileLongStore import dev.cubxity.plugins.metrics.common.metric.Metrics import dev.cubxity.plugins.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap +import dev.cubxity.plugins.metrics.sponge.events.TickEndEvent +import org.spongepowered.api.Sponge +import org.spongepowered.api.event.Listener -class TickCollection(bootstrap: UnifiedMetricsSpongeBootstrap): CollectorCollection { - - private val reporter = TickReporter(this, bootstrap) +class TickCollection(private val bootstrap: UnifiedMetricsSpongeBootstrap) : CollectorCollection { private val tickDuration = Histogram( Metrics.Server.TickDurationSeconds, @@ -37,14 +39,17 @@ class TickCollection(bootstrap: UnifiedMetricsSpongeBootstrap): CollectorCollect override val collectors: List = listOf(tickDuration) - override val isAsync: Boolean = true - override fun initialize() { - reporter.initialize() + Sponge.eventManager().registerListeners(bootstrap.container, this) } override fun dispose() { - reporter.dispose() + Sponge.eventManager().unregisterListeners(this) + } + + @Listener + fun onTickEnd(event: TickEndEvent) { + onTick(event.duration / MILLISECONDS_PER_SECOND) } fun onTick(duration: Double) { diff --git a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickReporter.kt b/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickReporter.kt deleted file mode 100644 index f22fc2dc..00000000 --- a/platforms/sponge/src/main/kotlin/dev/cubxity/plugins/metrics/sponge/metric/tick/TickReporter.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of UnifiedMetrics. - * - * UnifiedMetrics is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * UnifiedMetrics is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with UnifiedMetrics. If not, see . - */ - -package dev.cubxity.plugins.metrics.sponge.metric.tick - -import dev.cubxity.plugins.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap -import org.spongepowered.api.Sponge -import org.spongepowered.api.scheduler.ScheduledTask -import org.spongepowered.api.scheduler.Task -import org.spongepowered.api.util.Ticks - -class TickReporter( - private val metric: TickCollection, - bootstrap: UnifiedMetricsSpongeBootstrap -) { - - private lateinit var task: ScheduledTask - - private val taskExecutor = Task.builder() - .delay(Ticks.of(1)) - .execute(Runnable { - metric.onTick(0.0) - this.startTask() - }) - .plugin(bootstrap.container) - - fun initialize() { - startTask() - } - - private fun startTask() { - task = Sponge.asyncScheduler().submit(taskExecutor.build()) - } - - fun dispose() { - task.cancel() - } - -} \ No newline at end of file diff --git a/platforms/sponge/src/main/resources/unifiedmetrics.mixins.json b/platforms/sponge/src/main/resources/unifiedmetrics.mixins.json new file mode 100644 index 00000000..311a4adb --- /dev/null +++ b/platforms/sponge/src/main/resources/unifiedmetrics.mixins.json @@ -0,0 +1,12 @@ +{ + "required": true, + "minVersion": "0.8.2", + "package": "dev.cubxity.plugins.metrics.sponge.mixins", + "compatibilityLevel": "JAVA_21", + "mixins": [ + "MinecraftServerMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file From a12337f05207b26ac3109e21e105aaff56b0261c Mon Sep 17 00:00:00 2001 From: SamB440 Date: Wed, 15 Jan 2025 17:06:57 +0000 Subject: [PATCH 5/5] Small fixes --- platforms/sponge/build.gradle.kts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/platforms/sponge/build.gradle.kts b/platforms/sponge/build.gradle.kts index e15be0d7..a87c62ea 100644 --- a/platforms/sponge/build.gradle.kts +++ b/platforms/sponge/build.gradle.kts @@ -50,7 +50,7 @@ sponge { displayName("UnifiedMetrics") entrypoint("dev.cubxity.plugins.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap") description("Fully-featured metrics plugin for Minecraft servers") - license("GPL-3") + license("LGPL-3") dependency("spongeapi") { loadOrder(PluginDependency.LoadOrder.AFTER) optional(false) @@ -74,13 +74,14 @@ tasks { relocate("okio", "dev.cubxity.plugins.metrics.libs.okio") relocate("io.prometheus", "dev.cubxity.plugins.metrics.libs.io.prometheus") relocate("com.google.gson", "dev.cubxity.plugins.metrics.libs.gson") + relocate("com.google.errorprone.annotations", "dev.cubxity.plugins.metrics.libs.errorprone") relocate("org.apache.commons", "dev.cubxity.plugins.metrics.libs.commons") relocate("org.intellij.lang.annotations", "dev.cubxity.plugins.metrics.libs.intellij.annotations") relocate("org.jetbrains.annotations", "dev.cubxity.plugins.metrics.libs.jetbrains.annotations") relocate("javax.annotation", "dev.cubxity.plugins.metrics.libs.javax.annotations") relocate("org.reactivestreams", "dev.cubxity.plugins.metrics.libs.reactivestreams") relocate("net.thauvin.erik.urlencoder", "dev.cubxity.plugins.metrics.libs.urlencoder") - relocate("it.krzeminski.snakeyaml", "dev.cubxxity.plugins.metrics.libs.snakeyaml") + relocate("it.krzeminski.snakeyaml", "dev.cubxity.plugins.metrics.libs.snakeyaml") relocate("io.reactivex.rxjava3", "dev.cubxity.plugins.metrics.libs.rxjava") relocate("kotlin", "dev.cubxity.plugins.metrics.libs.kotlin") relocate("kotlinx", "dev.cubxity.plugins.metrics.libs.kotlinx")