-
Notifications
You must be signed in to change notification settings - Fork 61
Add sponge platform #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Nuckerr
wants to merge
6
commits into
Cubxity:dev/0.3.x
Choose a base branch
from
Nuckerr:dev/0.3.x
base: dev/0.3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * 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 <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| import org.spongepowered.gradle.plugin.config.PluginLoaders | ||
| import org.spongepowered.plugin.metadata.model.PluginDependency | ||
|
|
||
| plugins { | ||
| id("com.github.johnrengelman.shadow") | ||
| id("org.spongepowered.gradle.plugin") version "2.0.2" | ||
| } | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| maven("https://repo.spongepowered.org/repository/maven-public/") | ||
| } | ||
|
|
||
| dependencies { | ||
| api(project(":unifiedmetrics-core")) | ||
| } | ||
|
|
||
| sponge { | ||
| apiVersion("8.0.0") | ||
| license("GNU") | ||
|
Nuckerr marked this conversation as resolved.
Outdated
|
||
| loader { | ||
| name(PluginLoaders.JAVA_PLAIN) | ||
| version("1.0") | ||
| } | ||
| plugin("unifiedmetrics") { | ||
| displayName("UnifiedMetrics") | ||
| version(project.version.toString()) | ||
| entrypoint("dev.cubxity.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap") | ||
| description("Fully-featured metrics plugin for Minecraft servers") | ||
| links { | ||
| homepage("https://github.com/Cubxity/UnifiedMetrics/wiki") | ||
| source("https://github.com/Cubxity/UnifiedMetrics/") | ||
| issues("https://github.com/Cubxity/UnifiedMetrics/issues") | ||
| } | ||
| contributor("Cubxity") { | ||
| description("Maintainer") | ||
| } | ||
| dependency("spongeapi") { | ||
| loadOrder(PluginDependency.LoadOrder.AFTER) | ||
| optional(false) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| 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") | ||
| } | ||
|
|
||
| } | ||
51 changes: 51 additions & 0 deletions
51
platforms/sponge/src/main/java/dev/cubxity/metrics/sponge/SpongeDispatcher.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * 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 <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package dev.cubxity.metrics.sponge | ||
|
|
||
| import dev.cubxity.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap | ||
| import kotlinx.coroutines.* | ||
| 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<Unit>) { | ||
| 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() } | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
platforms/sponge/src/main/java/dev/cubxity/metrics/sponge/UnifiedMetricsSpongePlugin.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package dev.cubxity.metrics.sponge | ||
|
|
||
| import dev.cubxity.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap | ||
| import dev.cubxity.metrics.sponge.metric.events.EventsCollection | ||
| import dev.cubxity.metrics.sponge.metric.server.ServerCollection | ||
| import dev.cubxity.metrics.sponge.metric.tick.TickCollection | ||
| import dev.cubxity.metrics.sponge.metric.world.WorldCollection | ||
| import dev.cubxity.plugins.metrics.api.UnifiedMetrics | ||
| import dev.cubxity.plugins.metrics.core.plugin.CoreUnifiedMetricsPlugin | ||
|
|
||
| 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)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } |
68 changes: 68 additions & 0 deletions
68
...ponge/src/main/java/dev/cubxity/metrics/sponge/bootstrap/UnifiedMetricsSpongeBootstrap.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * 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 <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package dev.cubxity.metrics.sponge.bootstrap | ||
|
|
||
| import com.google.inject.Inject | ||
| import dev.cubxity.metrics.sponge.SpongeDispatcher | ||
| import dev.cubxity.metrics.sponge.UnifiedMetricsSpongePlugin | ||
| import dev.cubxity.metrics.sponge.logger.Log4jLogger | ||
| import dev.cubxity.plugins.metrics.api.logging.Logger | ||
| import dev.cubxity.plugins.metrics.api.platform.PlatformType | ||
| import dev.cubxity.plugins.metrics.common.UnifiedMetricsBootstrap | ||
| import kotlinx.coroutines.CoroutineDispatcher | ||
| import org.spongepowered.api.Game | ||
| import org.spongepowered.api.MinecraftVersion | ||
| import org.spongepowered.api.Server | ||
| import org.spongepowered.api.config.ConfigManager | ||
| import org.spongepowered.api.event.Listener | ||
| import org.spongepowered.api.event.lifecycle.StartedEngineEvent | ||
| 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( | ||
| serverLogger: org.apache.logging.log4j.Logger, | ||
| //@ConfigDir(sharedRoot = false) override val dataDirectory: Path, | ||
|
Nuckerr marked this conversation as resolved.
Outdated
|
||
| val container: PluginContainer, | ||
| serverVersion: MinecraftVersion, | ||
| val pluginManager: PluginManager, | ||
| private val game: Game, | ||
| configManager: ConfigManager | ||
| ): UnifiedMetricsBootstrap { | ||
|
|
||
| val server: Server | ||
| get() = game.server() | ||
|
|
||
| private val plugin = UnifiedMetricsSpongePlugin(this) | ||
| override val type: PlatformType = PlatformType.Sponge | ||
|
Nuckerr marked this conversation as resolved.
Outdated
|
||
| private val containerVersion = container.metadata().version() | ||
| override val version: String = "${containerVersion.majorVersion}.${containerVersion.minorVersion}.${containerVersion.incrementalVersion}#${containerVersion.buildNumber}" | ||
|
Nuckerr marked this conversation as resolved.
Outdated
|
||
| override val serverBrand: String = serverVersion.name() | ||
|
Nuckerr marked this conversation as resolved.
Outdated
|
||
| override val configDirectory: Path = configManager.pluginConfig(container).configPath() | ||
|
Nuckerr marked this conversation as resolved.
Outdated
|
||
| override val dataDirectory: Path = configDirectory | ||
|
Nuckerr marked this conversation as resolved.
|
||
|
|
||
| override val logger: Logger = Log4jLogger(serverLogger) | ||
| override val dispatcher: CoroutineDispatcher = SpongeDispatcher(this) | ||
|
|
||
| @Listener | ||
| fun onServerStart(event: StartedEngineEvent<Server>) { | ||
| plugin.enable() | ||
|
Nuckerr marked this conversation as resolved.
|
||
| } | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
platforms/sponge/src/main/java/dev/cubxity/metrics/sponge/logger/Log4jLogger.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package dev.cubxity.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) | ||
| } | ||
| } |
74 changes: 74 additions & 0 deletions
74
platforms/sponge/src/main/java/dev/cubxity/metrics/sponge/metric/events/EventsCollection.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package dev.cubxity.metrics.sponge.metric.events | ||
|
|
||
| import dev.cubxity.metrics.sponge.bootstrap.UnifiedMetricsSpongeBootstrap | ||
| 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 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("minecraft_events_login_total") | ||
| private val joinCounter = Counter("minecraft_events_join_total") | ||
| private val quitCounter = Counter("minecraft_events_quit_total") | ||
| private val chatCounter = Counter("minecraft_events_chat_total") | ||
| private val pingCounter = Counter("minecraft_events_ping_total") | ||
|
|
||
| override val collectors: List<Collector> = 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: Login) { | ||
| loginCounter.inc() | ||
| } | ||
|
|
||
|
|
||
| @Listener | ||
| fun onDisconnect(event: Disconnect) { | ||
| println("disconnect") | ||
|
Nuckerr marked this conversation as resolved.
Outdated
|
||
| quitCounter.inc() | ||
| } | ||
|
|
||
| @Listener | ||
| fun onChat(event: PlayerChatEvent) { | ||
| chatCounter.inc() | ||
| } | ||
|
|
||
| @Listener | ||
| fun onPing(event: ClientPingServerEvent) { | ||
| pingCounter.inc() | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.