From 6536b6a5b7c07631380236dbdda6620172809820 Mon Sep 17 00:00:00 2001 From: WarmthDawn Date: Wed, 4 Jan 2023 21:09:08 +0800 Subject: [PATCH 01/24] feat: :tada: forge 1.18 --- platforms/forge/build.gradle.kts | 126 ++++++++++++++++++ platforms/forge/gradle.properties | 18 +++ .../ServerLoginNetworkHandlerMixin.java | 45 +++++++ .../ServerQueryNetworkHandlerMixin.java | 36 +++++ .../forge/UnifiedMetricsForgePlugin.kt | 49 +++++++ .../bootstrap/UnifiedMetricsForgeBootstrap.kt | 93 +++++++++++++ .../forge/events/PlayerConnectionEvent.kt | 27 ++++ .../metrics/forge/events/ServerPingEvent.kt | 22 +++ .../metrics/forge/logger/Log4jLogger.kt | 43 ++++++ .../forge/metrics/events/EventsCollection.kt | 71 ++++++++++ .../forge/metrics/server/ServerCollection.kt | 26 ++++ .../forge/metrics/server/ServerCollector.kt | 36 +++++ .../forge/metrics/tick/TickCollection.kt | 63 +++++++++ .../forge/metrics/world/WorldCollection.kt | 26 ++++ .../forge/metrics/world/WorldCollector.kt | 40 ++++++ .../src/main/resources/META-INF/mods.toml | 58 ++++++++ .../forge/src/main/resources/pack.mcmeta | 8 ++ .../main/resources/unifiedmetrics.mixins.json | 10 ++ settings.gradle.kts | 10 ++ 19 files changed, 807 insertions(+) create mode 100644 platforms/forge/build.gradle.kts create mode 100644 platforms/forge/gradle.properties create mode 100644 platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginNetworkHandlerMixin.java create mode 100644 platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerQueryNetworkHandlerMixin.java create mode 100644 platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/UnifiedMetricsForgePlugin.kt create mode 100644 platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt create mode 100644 platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/PlayerConnectionEvent.kt create mode 100644 platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/ServerPingEvent.kt create mode 100644 platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/logger/Log4jLogger.kt create mode 100644 platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/events/EventsCollection.kt create mode 100644 platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollection.kt create mode 100644 platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollector.kt create mode 100644 platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/tick/TickCollection.kt create mode 100644 platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollection.kt create mode 100644 platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt create mode 100644 platforms/forge/src/main/resources/META-INF/mods.toml create mode 100644 platforms/forge/src/main/resources/pack.mcmeta create mode 100644 platforms/forge/src/main/resources/unifiedmetrics.mixins.json diff --git a/platforms/forge/build.gradle.kts b/platforms/forge/build.gradle.kts new file mode 100644 index 00000000..832e666c --- /dev/null +++ b/platforms/forge/build.gradle.kts @@ -0,0 +1,126 @@ +/* + * 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 . + */ + +plugins { + id("dev.architectury.loom") version "0.12.0-SNAPSHOT" + id("net.kyori.blossom") +} + +val transitiveInclude: Configuration by configurations.creating { + exclude(group = "com.mojang") + exclude(group = "org.jetbrains.kotlin") + exclude(group = "org.jetbrains.kotlinx") +} + +repositories { + // Add KFF Maven repository + maven { + name = "Kotlin for Forge" + url = uri("https://thedarkcolour.github.io/KotlinForForge/") + } +} + +dependencies { + minecraft("com.mojang:minecraft:1.18.2") + mappings("net.fabricmc:yarn:1.18.2+build.4:v2") + forge("net.minecraftforge:forge:1.18.2-40.1.73") + modApi("thedarkcolour:kotlinforforge:3.8.0") + + api(project(":unifiedmetrics-core")) + + transitiveInclude(project(":unifiedmetrics-core")) + + transitiveInclude.incoming.artifacts.forEach { + val dependency: Any = when (val component = it.id.componentIdentifier) { + is ProjectComponentIdentifier -> project(component.projectPath) + else -> component.toString() + } + + include(dependency) + } +} + +loom { + // since loom 0.10, you are **required** to use the + // "forge" block to configure forge-specific features, + // such as the mixinConfigs array or datagen + forge { + // specify the mixin configs used in this mod + // this will be added to the jar manifest as well! + mixinConfigs( + "unifiedmetrics.mixins.json" + ) + + // missing access transformers? + // don't worry, you can still use them! + // note that your AT *MUST* be located at + // src/main/resources/META-INF/accesstransformer.cfg + // to work as there is currently no config option to change this. + // also, any names used in your access transformer will need to be + // in SRG mapped ("func_" / "field_" with MCP class names) to work! + // (both of these things may be subject to change in the future) + + // this will create a data generator configuration + // that you can use to automatically generate assets and data + // using architectury loom. Note that this currently *only* works + // for forge projects made with architectury loom! + dataGen { + mod("unifiedmetrics") + } + } + + // This allows you to modify your launch configurations, + // for example to add custom arguments. In this case, we want + // the data generator to check our resources directory for + // existing files. (see Forge's ExistingFileHelper for more info) + launches { + named("data") { + arg("--existing", file("src/main/resources").absolutePath) + } + } + + runs { + named("server") { + isIdeConfigGenerated = true + } + } +} + +tasks { + compileKotlin { + kotlinOptions.jvmTarget = "17" + } + + processResources { + inputs.property("version", project.version) + + filesMatching("META-INF/mods.toml") { + expand("version" to project.version) + } + } + + compileJava { + options.encoding = "UTF-8" + options.release.set(17) + } + +} + +blossom { + replaceTokenIn("src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt") + replaceToken("@version@", version) +} \ No newline at end of file diff --git a/platforms/forge/gradle.properties b/platforms/forge/gradle.properties new file mode 100644 index 00000000..24883de3 --- /dev/null +++ b/platforms/forge/gradle.properties @@ -0,0 +1,18 @@ +# +# 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 . +# + +loom.platform=forge \ No newline at end of file diff --git a/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginNetworkHandlerMixin.java b/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginNetworkHandlerMixin.java new file mode 100644 index 00000000..6ae505e7 --- /dev/null +++ b/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginNetworkHandlerMixin.java @@ -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.forge.mixins; + +import dev.cubxity.plugins.metrics.forge.events.PlayerConnectionEvent; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerLoginNetworkHandler; +import net.minecraftforge.common.MinecraftForge; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ServerLoginNetworkHandler.class) +public abstract class ServerLoginNetworkHandlerMixin { + + + @Shadow + @Final + private MinecraftServer server; + + @Inject(method = "", at = @At("RETURN")) + private void initConnection(CallbackInfo ci) { + ServerLoginNetworkHandler handler = (ServerLoginNetworkHandler) (Object) this; + MinecraftServer server = this.server; + MinecraftForge.EVENT_BUS.post(new PlayerConnectionEvent(handler, server)); + } +} diff --git a/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerQueryNetworkHandlerMixin.java b/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerQueryNetworkHandlerMixin.java new file mode 100644 index 00000000..299f6a0b --- /dev/null +++ b/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerQueryNetworkHandlerMixin.java @@ -0,0 +1,36 @@ +/* + * 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.forge.mixins; + +import dev.cubxity.plugins.metrics.forge.events.ServerPingEvent; +import net.minecraft.server.network.ServerQueryNetworkHandler; +import net.minecraftforge.common.MinecraftForge; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ServerQueryNetworkHandler.class) +public abstract class ServerQueryNetworkHandlerMixin { + + @Inject(method = "onRequest", at = @At("HEAD")) + private void handleOnRequest(CallbackInfo ci) { + MinecraftForge.EVENT_BUS.post(new ServerPingEvent()); + } + +} diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/UnifiedMetricsForgePlugin.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/UnifiedMetricsForgePlugin.kt new file mode 100644 index 00000000..d09ff5d5 --- /dev/null +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/UnifiedMetricsForgePlugin.kt @@ -0,0 +1,49 @@ +/* + * 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.forge + +import dev.cubxity.plugins.metrics.api.UnifiedMetrics +import dev.cubxity.plugins.metrics.core.plugin.CoreUnifiedMetricsPlugin +import dev.cubxity.plugins.metrics.forge.bootstrap.UnifiedMetricsForgeBootstrap +import dev.cubxity.plugins.metrics.forge.metrics.events.EventsCollection +import dev.cubxity.plugins.metrics.forge.metrics.server.ServerCollection +import dev.cubxity.plugins.metrics.forge.metrics.tick.TickCollection +import dev.cubxity.plugins.metrics.forge.metrics.world.WorldCollection +import java.util.concurrent.Executors + +class UnifiedMetricsForgePlugin( + override val bootstrap: UnifiedMetricsForgeBootstrap +): CoreUnifiedMetricsPlugin() { + + override fun registerPlatformService(api: UnifiedMetrics) { + + } + + override fun registerPlatformMetrics() { + super.registerPlatformMetrics() + + apiProvider.metricsManager.apply { + with(config.metrics.collectors) { + if (server) registerCollection(ServerCollection(bootstrap)) + if (world) registerCollection(WorldCollection(bootstrap)) + if (tick) registerCollection(TickCollection()) + if (events) registerCollection(EventsCollection()) + } + } + } +} \ No newline at end of file diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt new file mode 100644 index 00000000..c186c53c --- /dev/null +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt @@ -0,0 +1,93 @@ +/* + * 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.forge.bootstrap + +import dev.cubxity.plugins.metrics.api.platform.PlatformType +import dev.cubxity.plugins.metrics.common.UnifiedMetricsBootstrap +import dev.cubxity.plugins.metrics.common.plugin.dispatcher.CurrentThreadDispatcher +import dev.cubxity.plugins.metrics.forge.UnifiedMetricsForgePlugin +import dev.cubxity.plugins.metrics.forge.logger.Log4jLogger +import kotlinx.coroutines.CoroutineDispatcher +import net.minecraft.server.MinecraftServer +import net.minecraftforge.event.server.ServerStartedEvent +import net.minecraftforge.event.server.ServerStoppingEvent +import net.minecraftforge.fml.common.Mod +import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent +import net.minecraftforge.fml.loading.FMLPaths +import org.apache.logging.log4j.LogManager +import thedarkcolour.kotlinforforge.forge.FORGE_BUS +import thedarkcolour.kotlinforforge.forge.MOD_BUS +import thedarkcolour.kotlinforforge.forge.runForDist +import java.nio.file.Path + +private const val pluginVersion = "@version@" + +//class ExampleModForge { +// init { +// // Submit our event bus to let architectury register our content on the right time +// EventBuses.registerModEventBus(ExampleMod.MOD_ID, FMLJavaModLoadingContext.get().modEventBus) +// FMLJavaModLoadingContext.get().modEventBus.addListener(this::onGatherData) +// init() +// } +// +// private fun onGatherData(event: GatherDataEvent) { +// val gen = event.generator +// gen.addProvider(true, ChineseProvider(gen)) +// } +//} +@Mod("unifiedmetrics") +class UnifiedMetricsForgeBootstrap : UnifiedMetricsBootstrap { + private val plugin = UnifiedMetricsForgePlugin(this) + lateinit var server: MinecraftServer + + override val type: PlatformType + get() = PlatformType.Fabric + + override val version: String + get() = pluginVersion + + override val serverBrand: String + get() = server.serverModName + + override val dataDirectory: Path = FMLPaths.CONFIGDIR.get().resolve("unifiedmetrics") + + override val configDirectory: Path = FMLPaths.CONFIGDIR.get().resolve("unifiedmetrics") + + override val logger = Log4jLogger(LogManager.getLogger("UnifiedMetrics")) + + override val dispatcher: CoroutineDispatcher = CurrentThreadDispatcher + + init { + MOD_BUS.addListener(::onServerSetup) + } + + private fun onServerSetup(event: FMLDedicatedServerSetupEvent) { + FORGE_BUS.addListener(::onServerStarted) + FORGE_BUS.addListener(::onServerStopping) + } + + private fun onServerStarted(event: ServerStartedEvent) { + this.server = event.server + plugin.enable() + } + + + private fun onServerStopping(event: ServerStoppingEvent) { + plugin.disable() + } +} \ No newline at end of file diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/PlayerConnectionEvent.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/PlayerConnectionEvent.kt new file mode 100644 index 00000000..7694b27d --- /dev/null +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/PlayerConnectionEvent.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.forge.events + +import net.minecraft.server.MinecraftServer +import net.minecraft.server.network.ServerLoginNetworkHandler +import net.minecraftforge.eventbus.api.Event + +class PlayerConnectionEvent( + val handler: ServerLoginNetworkHandler, + val server: MinecraftServer +): Event() \ No newline at end of file diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/ServerPingEvent.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/ServerPingEvent.kt new file mode 100644 index 00000000..398a6229 --- /dev/null +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/ServerPingEvent.kt @@ -0,0 +1,22 @@ +/* + * 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.forge.events + +import net.minecraftforge.eventbus.api.Event + +class ServerPingEvent: Event() \ No newline at end of file diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/logger/Log4jLogger.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/logger/Log4jLogger.kt new file mode 100644 index 00000000..03510a33 --- /dev/null +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/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.forge.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/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/events/EventsCollection.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/events/EventsCollection.kt new file mode 100644 index 00000000..cf7141f6 --- /dev/null +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/events/EventsCollection.kt @@ -0,0 +1,71 @@ +/* + * 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.forge.metrics.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.forge.events.PlayerConnectionEvent +import dev.cubxity.plugins.metrics.forge.events.ServerPingEvent +import net.minecraftforge.event.ServerChatEvent +import net.minecraftforge.event.entity.player.PlayerEvent +import net.minecraftforge.eventbus.api.SubscribeEvent +import thedarkcolour.kotlinforforge.forge.FORGE_BUS + +class EventsCollection : CollectorCollection { + private val loginCounter = Counter(Metrics.Events.Login) + private val joinCounter = Counter(Metrics.Events.Join) + private val quitCounter = Counter(Metrics.Events.Quit) + private val chatCounter = Counter(Metrics.Events.Chat, valueStoreFactory = VolatileDoubleStore) + private val pingCounter = Counter(Metrics.Events.Ping) + + override val collectors: List = + listOf(loginCounter, joinCounter, quitCounter, chatCounter, pingCounter) + + override fun initialize() { + FORGE_BUS.register(this) + } + + + @SubscribeEvent + fun onLogin(event: PlayerConnectionEvent) { + loginCounter.inc() + } + + @SubscribeEvent + fun onJoin(event: PlayerEvent.PlayerLoggedInEvent) { + joinCounter.inc() + } + + @SubscribeEvent + fun onQuit(event: PlayerEvent.PlayerLoggedOutEvent) { + quitCounter.inc() + } + + @SubscribeEvent + fun onChat(event: ServerChatEvent) { + chatCounter.inc() + } + + @SubscribeEvent + fun onPing(event: ServerPingEvent) { + pingCounter.inc() + } +} \ No newline at end of file diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollection.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollection.kt new file mode 100644 index 00000000..57478f53 --- /dev/null +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollection.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.forge.metrics.server + +import dev.cubxity.plugins.metrics.api.metric.collector.Collector +import dev.cubxity.plugins.metrics.api.metric.collector.CollectorCollection +import dev.cubxity.plugins.metrics.forge.bootstrap.UnifiedMetricsForgeBootstrap + +class ServerCollection(bootstrap: UnifiedMetricsForgeBootstrap) : CollectorCollection { + override val collectors: List = listOf(ServerCollector(bootstrap)) +} \ No newline at end of file diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollector.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollector.kt new file mode 100644 index 00000000..777406b7 --- /dev/null +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollector.kt @@ -0,0 +1,36 @@ +/* + * 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.forge.metrics.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.forge.bootstrap.UnifiedMetricsForgeBootstrap +import net.minecraftforge.fml.ModList + +class ServerCollector(private val bootstrap: UnifiedMetricsForgeBootstrap): Collector { + override fun collect(): List { + val server = bootstrap.server + return listOf( + GaugeMetric(Metrics.Server.Plugins, value = ModList.get().size()), + GaugeMetric(Metrics.Server.PlayersCount, value = server.currentPlayerCount), + GaugeMetric(Metrics.Server.PlayersMax, value = server.maxPlayerCount) + ) + } +} \ No newline at end of file diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/tick/TickCollection.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/tick/TickCollection.kt new file mode 100644 index 00000000..5f663e7b --- /dev/null +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/tick/TickCollection.kt @@ -0,0 +1,63 @@ +/* + * 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.forge.metrics.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 net.minecraftforge.event.TickEvent +import net.minecraftforge.eventbus.api.EventPriority +import net.minecraftforge.eventbus.api.SubscribeEvent +import thedarkcolour.kotlinforforge.forge.FORGE_BUS + +class TickCollection : CollectorCollection { + private val tickDuration = Histogram( + Metrics.Server.TickDurationSeconds, + sumStoreFactory = VolatileDoubleStore, + countStoreFactory = VolatileLongStore + ) + + override val collectors: List = listOf(tickDuration) + + + override fun initialize() { + FORGE_BUS.register(this) + } + + private var lastTickTime = 0L + + @SubscribeEvent(priority = EventPriority.HIGHEST) + fun onTickPre(event: TickEvent.ServerTickEvent) { + if(event.phase == TickEvent.Phase.START) { + lastTickTime = System.nanoTime() + } + } + + + @SubscribeEvent(priority = EventPriority.LOWEST) + fun onTickPost(event: TickEvent.ServerTickEvent) { + if(event.phase == TickEvent.Phase.END) { + val tickTime = System.nanoTime() - lastTickTime + tickDuration += (tickTime / MILLISECONDS_PER_SECOND) + } + } +} \ No newline at end of file diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollection.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollection.kt new file mode 100644 index 00000000..c808a76b --- /dev/null +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/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.forge.metrics.world + +import dev.cubxity.plugins.metrics.api.metric.collector.Collector +import dev.cubxity.plugins.metrics.api.metric.collector.CollectorCollection +import dev.cubxity.plugins.metrics.forge.bootstrap.UnifiedMetricsForgeBootstrap + +class WorldCollection(bootstrap: UnifiedMetricsForgeBootstrap) : CollectorCollection { + override val collectors: List = listOf(WorldCollector(bootstrap)) +} \ No newline at end of file diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt new file mode 100644 index 00000000..a2d568eb --- /dev/null +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt @@ -0,0 +1,40 @@ +/* + * 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.forge.metrics.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.common.metric.Metrics +import dev.cubxity.plugins.metrics.forge.bootstrap.UnifiedMetricsForgeBootstrap + +class WorldCollector(private val bootstrap: UnifiedMetricsForgeBootstrap) : Collector { + override fun collect(): List { + val worlds = bootstrap.server.worlds + val samples = ArrayList(worlds.count() * 3) + + worlds.forEach { world -> + val tags = mapOf("world" to world.registryKey.value.toString()) + samples.add(GaugeMetric(Metrics.Server.WorldEntitiesCount, tags, world.iterateEntities().count())) + samples.add(GaugeMetric(Metrics.Server.WorldPlayersCount, tags, world.players.size)) + samples.add(GaugeMetric(Metrics.Server.WorldLoadedChunks, tags, world.chunkManager.loadedChunkCount)) + } + + return samples + } +} \ No newline at end of file diff --git a/platforms/forge/src/main/resources/META-INF/mods.toml b/platforms/forge/src/main/resources/META-INF/mods.toml new file mode 100644 index 00000000..da8f5853 --- /dev/null +++ b/platforms/forge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,58 @@ +# This is an example mods.toml file. It contains the data relating to the loading mods. +# There are several mandatory fields (#mandatory), and many more that are optional (#optional). +# The overall format is standard TOML format, v0.5.0. +# Note that there are a couple of TOML lists in this file. +# Find more information on toml format here: https://github.com/toml-lang/toml +# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml +modLoader="kotlinforforge" #mandatory +# A version range to match for said mod loader - for regular FML @Mod it will be the forge version +loaderVersion="[3,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. +# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. +license="LGPL-3.0" +# A URL to refer people to when problems occur with this mod +#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional +# A list of mods - how many allowed here is determined by the individual mod loader +[[mods]] #mandatory +# The modid of the mod +modId="unifiedmetrics" #mandatory +# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it +# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata +# see the associated build.gradle script for how to populate this completely automatically during a build +version="${version}" #mandatory + # A display name for the mod +displayName="Unified Metrics" #mandatory +# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/ +#updateJSONURL="https://change.me.example.invalid/updates.json" #optional +# A URL for the "homepage" for this mod, displayed in the mod UI +#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional +# A file name (in the root of the mod JAR) containing a logo for display +# logoFile="examplemod.png" #optional +# A text field displayed in the mod UI +# credits="Thanks for this example mod goes to Java" #optional +# A text field displayed in the mod UI +authors="Cubxity" #optional +# The description text for the mod (multi line!) (#mandatory) +description=''' +Fully-featured metrics plugin for Minecraft servers +''' +# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. +[[dependencies.unifiedmetrics]] #optional + # the modid of the dependency + modId="forge" #mandatory + # Does this dependency have to exist - if not, ordering below must be specified + mandatory=true #mandatory + # The version range of the dependency + versionRange="[40,)" #mandatory + # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory + ordering="NONE" + # Side this dependency is applied on - BOTH, CLIENT or SERVER + side="BOTH" +# Here's another dependency +[[dependencies.unifiedmetrics]] + modId="minecraft" + mandatory=true +# This version range declares a minimum of the current minecraft version up to but not including the next major version + versionRange="[1.18.2, 1.19)" + ordering="NONE" + side="BOTH" diff --git a/platforms/forge/src/main/resources/pack.mcmeta b/platforms/forge/src/main/resources/pack.mcmeta new file mode 100644 index 00000000..522d8492 --- /dev/null +++ b/platforms/forge/src/main/resources/pack.mcmeta @@ -0,0 +1,8 @@ +{ + "pack": { + "description": "unifiedmetrics resources", + "pack_format": 9, + "forge:resource_pack_format": 8, + "forge:data_pack_format": 9 + } +} diff --git a/platforms/forge/src/main/resources/unifiedmetrics.mixins.json b/platforms/forge/src/main/resources/unifiedmetrics.mixins.json new file mode 100644 index 00000000..3f673cb1 --- /dev/null +++ b/platforms/forge/src/main/resources/unifiedmetrics.mixins.json @@ -0,0 +1,10 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "dev.cubxity.plugins.metrics.forge.mixins", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "ServerLoginNetworkHandlerMixin", + "ServerQueryNetworkHandlerMixin", + ] +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 3daa9cf9..5e578170 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -30,6 +30,7 @@ include(modulePrefix + platformPrefix + "minestom") include(modulePrefix + platformPrefix + "velocity") include(modulePrefix + platformPrefix + "bungee") include(modulePrefix + platformPrefix + "fabric") +include(modulePrefix + platformPrefix + "forge") include(modulePrefix + driverPrefix + "influx") include(modulePrefix + driverPrefix + "prometheus") @@ -44,6 +45,7 @@ project(modulePrefix + platformPrefix + "minestom").projectDir = File(platformsD 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 + "forge").projectDir = File(platformsDir, "forge") val driversDir = File(rootDir, "drivers") project(modulePrefix + driverPrefix + "influx").projectDir = File(driversDir, "influx") @@ -56,5 +58,13 @@ pluginManagement { name = "Fabric" url = uri("https://maven.fabricmc.net/") } + maven { + name = "Architectury" + url = uri("https://maven.architectury.dev/") + } + maven { + name = "Forge" + url = uri("https://files.minecraftforge.net/maven/") + } } } From 9f20e19966c2dd7567c0f2d1aced11278bdb7326 Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Wed, 4 Jan 2023 23:37:14 +0800 Subject: [PATCH 02/24] fix: compile error --- platforms/forge/build.gradle.kts | 6 ++++++ platforms/forge/src/main/resources/META-INF/mods.toml | 2 +- .../forge/src/main/resources/unifiedmetrics.mixins.json | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/platforms/forge/build.gradle.kts b/platforms/forge/build.gradle.kts index 832e666c..74d17d41 100644 --- a/platforms/forge/build.gradle.kts +++ b/platforms/forge/build.gradle.kts @@ -20,6 +20,12 @@ plugins { id("net.kyori.blossom") } + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + val transitiveInclude: Configuration by configurations.creating { exclude(group = "com.mojang") exclude(group = "org.jetbrains.kotlin") diff --git a/platforms/forge/src/main/resources/META-INF/mods.toml b/platforms/forge/src/main/resources/META-INF/mods.toml index da8f5853..1a748e7e 100644 --- a/platforms/forge/src/main/resources/META-INF/mods.toml +++ b/platforms/forge/src/main/resources/META-INF/mods.toml @@ -17,7 +17,7 @@ license="LGPL-3.0" # The modid of the mod modId="unifiedmetrics" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it -# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata +# The plugin version will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # see the associated build.gradle script for how to populate this completely automatically during a build version="${version}" #mandatory # A display name for the mod diff --git a/platforms/forge/src/main/resources/unifiedmetrics.mixins.json b/platforms/forge/src/main/resources/unifiedmetrics.mixins.json index 3f673cb1..24d2b43e 100644 --- a/platforms/forge/src/main/resources/unifiedmetrics.mixins.json +++ b/platforms/forge/src/main/resources/unifiedmetrics.mixins.json @@ -5,6 +5,6 @@ "compatibilityLevel": "JAVA_8", "mixins": [ "ServerLoginNetworkHandlerMixin", - "ServerQueryNetworkHandlerMixin", + "ServerQueryNetworkHandlerMixin" ] } \ No newline at end of file From 5bee21406f1a0252251382d5ba875f347441dd93 Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Thu, 5 Jan 2023 01:03:17 +0800 Subject: [PATCH 03/24] fix: platform type --- .../dev/cubxity/plugins/metrics/api/platform/PlatformType.kt | 1 + .../metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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..f68132c0 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 Forge : PlatformType("Forge") // Proxies object Velocity : PlatformType("Velocity") diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt index c186c53c..837cfa25 100644 --- a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt @@ -56,7 +56,7 @@ class UnifiedMetricsForgeBootstrap : UnifiedMetricsBootstrap { lateinit var server: MinecraftServer override val type: PlatformType - get() = PlatformType.Fabric + get() = PlatformType.Forge override val version: String get() = pluginVersion From ee84d5995f5b6a1ab2327e62cde72ee8a2eaf30f Mon Sep 17 00:00:00 2001 From: WarmthDawn Date: Thu, 5 Jan 2023 17:42:33 +0800 Subject: [PATCH 04/24] refactor: change build script to forge mdk --- gradle/wrapper/gradle-wrapper.properties | 2 +- platforms/forge/build.gradle.kts | 120 ++++++++---------- platforms/forge/gradle.properties | 18 --- ...> ServerLoginPacketListenerImplMixin.java} | 10 +- ... ServerStatusPacketListenerImplMixin.java} | 10 +- .../forge/events/PlayerConnectionEvent.kt | 4 +- .../forge/metrics/server/ServerCollector.kt | 4 +- .../forge/metrics/world/WorldCollector.kt | 10 +- .../main/resources/unifiedmetrics.mixins.json | 16 +-- settings.gradle.kts | 4 - 10 files changed, 82 insertions(+), 116 deletions(-) delete mode 100644 platforms/forge/gradle.properties rename platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/{ServerLoginNetworkHandlerMixin.java => ServerLoginPacketListenerImplMixin.java} (84%) rename platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/{ServerQueryNetworkHandlerMixin.java => ServerStatusPacketListenerImplMixin.java} (80%) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2d23ddb2..56350a50 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -17,6 +17,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/platforms/forge/build.gradle.kts b/platforms/forge/build.gradle.kts index 74d17d41..1ba18792 100644 --- a/platforms/forge/build.gradle.kts +++ b/platforms/forge/build.gradle.kts @@ -14,22 +14,53 @@ * You should have received a copy of the GNU Lesser General Public License * along with UnifiedMetrics. If not, see . */ +buildscript { + repositories { + maven("https://maven.minecraftforge.net") + maven("https://maven.parchmentmc.org") + mavenCentral() + } + dependencies { + classpath(group = "net.minecraftforge.gradle", name = "ForgeGradle", version = "5.1.+") { + isChanging = true + } + classpath("org.parchmentmc:librarian:1.+") + } +} plugins { - id("dev.architectury.loom") version "0.12.0-SNAPSHOT" id("net.kyori.blossom") + id("com.github.johnrengelman.shadow") } +apply { + plugin("net.minecraftforge.gradle") + plugin("org.parchmentmc.librarian.forgegradle") +} java { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } -val transitiveInclude: Configuration by configurations.creating { - exclude(group = "com.mojang") - exclude(group = "org.jetbrains.kotlin") - exclude(group = "org.jetbrains.kotlinx") +configure { + mappings("parchment", "2022.11.06-1.18.2") + + runs { + create("server") { + workingDirectory = project.file("run").canonicalPath + // "SCAN": For mods scan. + // "REGISTRIES": For firing of registry events. + // "REGISTRYDUMP": For getting the contents of all registries. + property("forge.logging.markers", "REGISTRIES") + property("forge.logging.console.level", "debug") + mods { + create("unifiedmetrics") { + source(sourceSets["main"]) + } + } + } + } } repositories { @@ -41,69 +72,12 @@ repositories { } dependencies { - minecraft("com.mojang:minecraft:1.18.2") - mappings("net.fabricmc:yarn:1.18.2+build.4:v2") - forge("net.minecraftforge:forge:1.18.2-40.1.73") - modApi("thedarkcolour:kotlinforforge:3.8.0") - + "minecraft"("net.minecraftforge:forge:1.18.2-40.2.0") + val fg = project.extensions.getByType() api(project(":unifiedmetrics-core")) + implementation("thedarkcolour:kotlinforforge:3.8.0") - transitiveInclude(project(":unifiedmetrics-core")) - - transitiveInclude.incoming.artifacts.forEach { - val dependency: Any = when (val component = it.id.componentIdentifier) { - is ProjectComponentIdentifier -> project(component.projectPath) - else -> component.toString() - } - - include(dependency) - } -} - -loom { - // since loom 0.10, you are **required** to use the - // "forge" block to configure forge-specific features, - // such as the mixinConfigs array or datagen - forge { - // specify the mixin configs used in this mod - // this will be added to the jar manifest as well! - mixinConfigs( - "unifiedmetrics.mixins.json" - ) - - // missing access transformers? - // don't worry, you can still use them! - // note that your AT *MUST* be located at - // src/main/resources/META-INF/accesstransformer.cfg - // to work as there is currently no config option to change this. - // also, any names used in your access transformer will need to be - // in SRG mapped ("func_" / "field_" with MCP class names) to work! - // (both of these things may be subject to change in the future) - - // this will create a data generator configuration - // that you can use to automatically generate assets and data - // using architectury loom. Note that this currently *only* works - // for forge projects made with architectury loom! - dataGen { - mod("unifiedmetrics") - } - } - - // This allows you to modify your launch configurations, - // for example to add custom arguments. In this case, we want - // the data generator to check our resources directory for - // existing files. (see Forge's ExistingFileHelper for more info) - launches { - named("data") { - arg("--existing", file("src/main/resources").absolutePath) - } - } - - runs { - named("server") { - isIdeConfigGenerated = true - } - } + implementation(kotlin("stdlib")) } tasks { @@ -111,6 +85,16 @@ tasks { kotlinOptions.jvmTarget = "17" } + 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") + } + processResources { inputs.property("version", project.version) @@ -124,6 +108,10 @@ tasks { options.release.set(17) } + jar { + finalizedBy("reobfJar") + } + } blossom { diff --git a/platforms/forge/gradle.properties b/platforms/forge/gradle.properties deleted file mode 100644 index 24883de3..00000000 --- a/platforms/forge/gradle.properties +++ /dev/null @@ -1,18 +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 . -# - -loom.platform=forge \ No newline at end of file diff --git a/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginNetworkHandlerMixin.java b/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginPacketListenerImplMixin.java similarity index 84% rename from platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginNetworkHandlerMixin.java rename to platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginPacketListenerImplMixin.java index 6ae505e7..76e20c06 100644 --- a/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginNetworkHandlerMixin.java +++ b/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginPacketListenerImplMixin.java @@ -19,7 +19,7 @@ import dev.cubxity.plugins.metrics.forge.events.PlayerConnectionEvent; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ServerLoginNetworkHandler; +import net.minecraft.server.network.ServerLoginPacketListenerImpl; import net.minecraftforge.common.MinecraftForge; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -28,17 +28,17 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(ServerLoginNetworkHandler.class) -public abstract class ServerLoginNetworkHandlerMixin { +@Mixin(ServerLoginPacketListenerImpl.class) +public abstract class ServerLoginPacketListenerImplMixin { @Shadow @Final - private MinecraftServer server; + MinecraftServer server; @Inject(method = "", at = @At("RETURN")) private void initConnection(CallbackInfo ci) { - ServerLoginNetworkHandler handler = (ServerLoginNetworkHandler) (Object) this; + ServerLoginPacketListenerImpl handler = (ServerLoginPacketListenerImpl) (Object) this; MinecraftServer server = this.server; MinecraftForge.EVENT_BUS.post(new PlayerConnectionEvent(handler, server)); } diff --git a/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerQueryNetworkHandlerMixin.java b/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerStatusPacketListenerImplMixin.java similarity index 80% rename from platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerQueryNetworkHandlerMixin.java rename to platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerStatusPacketListenerImplMixin.java index 299f6a0b..caf6cc07 100644 --- a/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerQueryNetworkHandlerMixin.java +++ b/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerStatusPacketListenerImplMixin.java @@ -18,18 +18,18 @@ package dev.cubxity.plugins.metrics.forge.mixins; import dev.cubxity.plugins.metrics.forge.events.ServerPingEvent; -import net.minecraft.server.network.ServerQueryNetworkHandler; +import net.minecraft.server.network.ServerStatusPacketListenerImpl; import net.minecraftforge.common.MinecraftForge; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(ServerQueryNetworkHandler.class) -public abstract class ServerQueryNetworkHandlerMixin { +@Mixin(ServerStatusPacketListenerImpl.class) +public abstract class ServerStatusPacketListenerImplMixin { - @Inject(method = "onRequest", at = @At("HEAD")) - private void handleOnRequest(CallbackInfo ci) { + @Inject(method = "handleStatusRequest", at = @At("HEAD")) + private void handleHandleStatusRequest(CallbackInfo ci) { MinecraftForge.EVENT_BUS.post(new ServerPingEvent()); } diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/PlayerConnectionEvent.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/PlayerConnectionEvent.kt index 7694b27d..c3211d27 100644 --- a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/PlayerConnectionEvent.kt +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/PlayerConnectionEvent.kt @@ -18,10 +18,10 @@ package dev.cubxity.plugins.metrics.forge.events import net.minecraft.server.MinecraftServer -import net.minecraft.server.network.ServerLoginNetworkHandler +import net.minecraft.server.network.ServerLoginPacketListenerImpl import net.minecraftforge.eventbus.api.Event class PlayerConnectionEvent( - val handler: ServerLoginNetworkHandler, + val handler: ServerLoginPacketListenerImpl, val server: MinecraftServer ): Event() \ No newline at end of file diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollector.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollector.kt index 777406b7..dadd4466 100644 --- a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollector.kt +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollector.kt @@ -29,8 +29,8 @@ class ServerCollector(private val bootstrap: UnifiedMetricsForgeBootstrap): Coll val server = bootstrap.server return listOf( GaugeMetric(Metrics.Server.Plugins, value = ModList.get().size()), - GaugeMetric(Metrics.Server.PlayersCount, value = server.currentPlayerCount), - GaugeMetric(Metrics.Server.PlayersMax, value = server.maxPlayerCount) + GaugeMetric(Metrics.Server.PlayersCount, value = server.playerCount), + GaugeMetric(Metrics.Server.PlayersMax, value = server.maxPlayers) ) } } \ No newline at end of file diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt index a2d568eb..ca622789 100644 --- a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt @@ -25,14 +25,14 @@ import dev.cubxity.plugins.metrics.forge.bootstrap.UnifiedMetricsForgeBootstrap class WorldCollector(private val bootstrap: UnifiedMetricsForgeBootstrap) : Collector { override fun collect(): List { - val worlds = bootstrap.server.worlds + val worlds = bootstrap.server.allLevels val samples = ArrayList(worlds.count() * 3) worlds.forEach { world -> - val tags = mapOf("world" to world.registryKey.value.toString()) - samples.add(GaugeMetric(Metrics.Server.WorldEntitiesCount, tags, world.iterateEntities().count())) - samples.add(GaugeMetric(Metrics.Server.WorldPlayersCount, tags, world.players.size)) - samples.add(GaugeMetric(Metrics.Server.WorldLoadedChunks, tags, world.chunkManager.loadedChunkCount)) + val tags = mapOf("world" to world.dimension().registry().toString()) + samples.add(GaugeMetric(Metrics.Server.WorldEntitiesCount, tags, world.allEntities.count())) + samples.add(GaugeMetric(Metrics.Server.WorldPlayersCount, tags, world.players().size)) + samples.add(GaugeMetric(Metrics.Server.WorldLoadedChunks, tags, world.chunkSource.loadedChunksCount)) } return samples diff --git a/platforms/forge/src/main/resources/unifiedmetrics.mixins.json b/platforms/forge/src/main/resources/unifiedmetrics.mixins.json index 24d2b43e..4e2d207e 100644 --- a/platforms/forge/src/main/resources/unifiedmetrics.mixins.json +++ b/platforms/forge/src/main/resources/unifiedmetrics.mixins.json @@ -1,10 +1,10 @@ { - "required": true, - "minVersion": "0.8", - "package": "dev.cubxity.plugins.metrics.forge.mixins", - "compatibilityLevel": "JAVA_8", - "mixins": [ - "ServerLoginNetworkHandlerMixin", - "ServerQueryNetworkHandlerMixin" - ] + "required": true, + "minVersion": "0.8", + "package": "dev.cubxity.plugins.metrics.forge.mixins", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "ServerLoginPacketListenerImplMixin", + "ServerStatusPacketListenerImplMixin" + ] } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 5e578170..144856f1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -58,10 +58,6 @@ pluginManagement { name = "Fabric" url = uri("https://maven.fabricmc.net/") } - maven { - name = "Architectury" - url = uri("https://maven.architectury.dev/") - } maven { name = "Forge" url = uri("https://files.minecraftforge.net/maven/") From 3f7ac512f63d27ec849ffed8b70fafe9b8755835 Mon Sep 17 00:00:00 2001 From: WarmthDawn Date: Thu, 5 Jan 2023 19:44:40 +0800 Subject: [PATCH 05/24] fix: kff build script --- platforms/forge/build.gradle.kts | 13 ++----------- .../forge/bootstrap/UnifiedMetricsForgeBootstrap.kt | 13 ------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/platforms/forge/build.gradle.kts b/platforms/forge/build.gradle.kts index 1ba18792..bbb59a1d 100644 --- a/platforms/forge/build.gradle.kts +++ b/platforms/forge/build.gradle.kts @@ -38,6 +38,8 @@ apply { plugin("org.parchmentmc.librarian.forgegradle") } +apply(from = "https://raw.githubusercontent.com/thedarkcolour/KotlinForForge/site/thedarkcolour/kotlinforforge/gradle/kff-3.8.0.gradle") + java { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 @@ -63,21 +65,10 @@ configure { } } -repositories { - // Add KFF Maven repository - maven { - name = "Kotlin for Forge" - url = uri("https://thedarkcolour.github.io/KotlinForForge/") - } -} - dependencies { "minecraft"("net.minecraftforge:forge:1.18.2-40.2.0") val fg = project.extensions.getByType() api(project(":unifiedmetrics-core")) - implementation("thedarkcolour:kotlinforforge:3.8.0") - - implementation(kotlin("stdlib")) } tasks { diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt index 837cfa25..41f8c247 100644 --- a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt @@ -37,19 +37,6 @@ import java.nio.file.Path private const val pluginVersion = "@version@" -//class ExampleModForge { -// init { -// // Submit our event bus to let architectury register our content on the right time -// EventBuses.registerModEventBus(ExampleMod.MOD_ID, FMLJavaModLoadingContext.get().modEventBus) -// FMLJavaModLoadingContext.get().modEventBus.addListener(this::onGatherData) -// init() -// } -// -// private fun onGatherData(event: GatherDataEvent) { -// val gen = event.generator -// gen.addProvider(true, ChineseProvider(gen)) -// } -//} @Mod("unifiedmetrics") class UnifiedMetricsForgeBootstrap : UnifiedMetricsBootstrap { private val plugin = UnifiedMetricsForgePlugin(this) From bff2973fa28309e71cb221c3f491a65eb7d11203 Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Thu, 5 Jan 2023 23:31:11 +0800 Subject: [PATCH 06/24] fix: shadowjar --- platforms/forge/build.gradle.kts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/platforms/forge/build.gradle.kts b/platforms/forge/build.gradle.kts index bbb59a1d..abb19e76 100644 --- a/platforms/forge/build.gradle.kts +++ b/platforms/forge/build.gradle.kts @@ -67,8 +67,8 @@ configure { dependencies { "minecraft"("net.minecraftforge:forge:1.18.2-40.2.0") - val fg = project.extensions.getByType() - api(project(":unifiedmetrics-core")) + val f = project.extensions.getByType() + shadow(project(":unifiedmetrics-core")) } tasks { @@ -77,13 +77,16 @@ tasks { } shadowJar { + dependsOn("reobfJar") archiveClassifier.set("") + configurations = listOf(project.configurations.shadow.get()) 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") + exclude("com/**", "io/**", "javax/**", "kotlin/**", "kotlinx/**", "org/**") } processResources { @@ -102,7 +105,6 @@ tasks { jar { finalizedBy("reobfJar") } - } blossom { From 6ba2db86d60c0087ea7f002c5f70b08c8458b306 Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Thu, 5 Jan 2023 23:36:26 +0800 Subject: [PATCH 07/24] fix: shadowjar --- platforms/forge/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/forge/build.gradle.kts b/platforms/forge/build.gradle.kts index abb19e76..f7202bcd 100644 --- a/platforms/forge/build.gradle.kts +++ b/platforms/forge/build.gradle.kts @@ -86,7 +86,7 @@ tasks { 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") - exclude("com/**", "io/**", "javax/**", "kotlin/**", "kotlinx/**", "org/**") + exclude("com/google/**", "io/reactivex/**", "javax/**", "kotlin/**", "kotlinx/**", "org/**") } processResources { From a30141a5f24667a426228c86c7146702aee26db5 Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Thu, 5 Jan 2023 23:53:56 +0800 Subject: [PATCH 08/24] fix: shadowjar --- platforms/forge/build.gradle.kts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/platforms/forge/build.gradle.kts b/platforms/forge/build.gradle.kts index f7202bcd..0a835686 100644 --- a/platforms/forge/build.gradle.kts +++ b/platforms/forge/build.gradle.kts @@ -86,7 +86,11 @@ tasks { 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") - exclude("com/google/**", "io/reactivex/**", "javax/**", "kotlin/**", "kotlinx/**", "org/**") + relocate("org.yaml.snakeyaml", "dev.cubxity.plugins.metrics.libs.org.yaml.snakeyaml") + relocate("org.snakeyaml", "dev.cubxity.plugins.metrics.libs.org.snakeyaml") + relocate("com.google.gson", "dev.cubxity.plugins.metrics.libs.org.yaml.snakeyaml") + relocate("io.reactivex", "dev.cubxity.plugins.metrics.libs.io.reactivex") + exclude("javax/**", "kotlin/**", "kotlinx/**") } processResources { From ba582a6e4747712a9e59972682881bf42aa86420 Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Thu, 5 Jan 2023 23:59:02 +0800 Subject: [PATCH 09/24] fix: shadowjar --- platforms/forge/build.gradle.kts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platforms/forge/build.gradle.kts b/platforms/forge/build.gradle.kts index 0a835686..eb1779f0 100644 --- a/platforms/forge/build.gradle.kts +++ b/platforms/forge/build.gradle.kts @@ -90,7 +90,9 @@ tasks { relocate("org.snakeyaml", "dev.cubxity.plugins.metrics.libs.org.snakeyaml") relocate("com.google.gson", "dev.cubxity.plugins.metrics.libs.org.yaml.snakeyaml") relocate("io.reactivex", "dev.cubxity.plugins.metrics.libs.io.reactivex") - exclude("javax/**", "kotlin/**", "kotlinx/**") + relocate("org.apache.common", "dev.cubxity.plugins.metrics.libs.org.apache.common") + relocate("org.reactivestreams", "dev.cubxity.plugins.metrics.libs.org.reactivestreams") + exclude("javax/**", "kotlin/**", "kotlinx/**", "org/jetbrains/**", "org/intellij/**") } processResources { From 236b451095b4aaf54cfb7cb6add409fd96adef73 Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Fri, 6 Jan 2023 00:33:12 +0800 Subject: [PATCH 10/24] fix: sort build step --- platforms/forge/build.gradle.kts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platforms/forge/build.gradle.kts b/platforms/forge/build.gradle.kts index eb1779f0..8abf8c8d 100644 --- a/platforms/forge/build.gradle.kts +++ b/platforms/forge/build.gradle.kts @@ -77,7 +77,6 @@ tasks { } shadowJar { - dependsOn("reobfJar") archiveClassifier.set("") configurations = listOf(project.configurations.shadow.get()) relocate("retrofit2", "dev.cubxity.plugins.metrics.libs.retrofit2") @@ -93,6 +92,8 @@ tasks { relocate("org.apache.common", "dev.cubxity.plugins.metrics.libs.org.apache.common") relocate("org.reactivestreams", "dev.cubxity.plugins.metrics.libs.org.reactivestreams") exclude("javax/**", "kotlin/**", "kotlinx/**", "org/jetbrains/**", "org/intellij/**") + + finalizedBy("reobfJar") } processResources { From 80bd9659f91f1beb5e511bf013b444946ecb1c31 Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Fri, 6 Jan 2023 11:07:54 +0800 Subject: [PATCH 11/24] fix: get world name --- .../plugins/metrics/forge/metrics/world/WorldCollector.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt index ca622789..de7f3f88 100644 --- a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt @@ -29,7 +29,7 @@ class WorldCollector(private val bootstrap: UnifiedMetricsForgeBootstrap) : Coll val samples = ArrayList(worlds.count() * 3) worlds.forEach { world -> - val tags = mapOf("world" to world.dimension().registry().toString()) + val tags = mapOf("world" to world.dimension().location().toString()) samples.add(GaugeMetric(Metrics.Server.WorldEntitiesCount, tags, world.allEntities.count())) samples.add(GaugeMetric(Metrics.Server.WorldPlayersCount, tags, world.players().size)) samples.add(GaugeMetric(Metrics.Server.WorldLoadedChunks, tags, world.chunkSource.loadedChunksCount)) From 3897299bc0ad87ad061b4085fd32f9506e841539 Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Fri, 6 Jan 2023 22:57:12 +0800 Subject: [PATCH 12/24] fix: fix mspt metric --- .../plugins/metrics/forge/metrics/tick/TickCollection.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/tick/TickCollection.kt b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/tick/TickCollection.kt index 5f663e7b..4cc336e4 100644 --- a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/tick/TickCollection.kt +++ b/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/tick/TickCollection.kt @@ -20,7 +20,7 @@ package dev.cubxity.plugins.metrics.forge.metrics.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.collector.NANOSECONDS_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 @@ -52,12 +52,11 @@ class TickCollection : CollectorCollection { } } - @SubscribeEvent(priority = EventPriority.LOWEST) fun onTickPost(event: TickEvent.ServerTickEvent) { if(event.phase == TickEvent.Phase.END) { val tickTime = System.nanoTime() - lastTickTime - tickDuration += (tickTime / MILLISECONDS_PER_SECOND) + tickDuration += (tickTime / NANOSECONDS_PER_SECOND) } } } \ No newline at end of file From 6c6268909785a710e1ef53ec98a487d14f0221ac Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Sat, 7 Jan 2023 16:25:15 +0800 Subject: [PATCH 13/24] refactor: rename submodule --- platforms/{forge => forge-1.18.2}/build.gradle.kts | 0 .../forge/mixins/ServerLoginPacketListenerImplMixin.java | 0 .../forge/mixins/ServerStatusPacketListenerImplMixin.java | 0 .../plugins/metrics/forge/UnifiedMetricsForgePlugin.kt | 0 .../metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt | 0 .../plugins/metrics/forge/events/PlayerConnectionEvent.kt | 0 .../cubxity/plugins/metrics/forge/events/ServerPingEvent.kt | 0 .../dev/cubxity/plugins/metrics/forge/logger/Log4jLogger.kt | 0 .../plugins/metrics/forge/metrics/events/EventsCollection.kt | 0 .../plugins/metrics/forge/metrics/server/ServerCollection.kt | 0 .../plugins/metrics/forge/metrics/server/ServerCollector.kt | 0 .../plugins/metrics/forge/metrics/tick/TickCollection.kt | 0 .../plugins/metrics/forge/metrics/world/WorldCollection.kt | 0 .../plugins/metrics/forge/metrics/world/WorldCollector.kt | 0 .../src/main/resources/META-INF/mods.toml | 0 .../{forge => forge-1.18.2}/src/main/resources/pack.mcmeta | 0 .../src/main/resources/unifiedmetrics.mixins.json | 0 settings.gradle.kts | 4 ++-- 18 files changed, 2 insertions(+), 2 deletions(-) rename platforms/{forge => forge-1.18.2}/build.gradle.kts (100%) rename platforms/{forge => forge-1.18.2}/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginPacketListenerImplMixin.java (100%) rename platforms/{forge => forge-1.18.2}/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerStatusPacketListenerImplMixin.java (100%) rename platforms/{forge => forge-1.18.2}/src/main/kotlin/dev/cubxity/plugins/metrics/forge/UnifiedMetricsForgePlugin.kt (100%) rename platforms/{forge => forge-1.18.2}/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt (100%) rename platforms/{forge => forge-1.18.2}/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/PlayerConnectionEvent.kt (100%) rename platforms/{forge => forge-1.18.2}/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/ServerPingEvent.kt (100%) rename platforms/{forge => forge-1.18.2}/src/main/kotlin/dev/cubxity/plugins/metrics/forge/logger/Log4jLogger.kt (100%) rename platforms/{forge => forge-1.18.2}/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/events/EventsCollection.kt (100%) rename platforms/{forge => forge-1.18.2}/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollection.kt (100%) rename platforms/{forge => forge-1.18.2}/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollector.kt (100%) rename platforms/{forge => forge-1.18.2}/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/tick/TickCollection.kt (100%) rename platforms/{forge => forge-1.18.2}/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollection.kt (100%) rename platforms/{forge => forge-1.18.2}/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt (100%) rename platforms/{forge => forge-1.18.2}/src/main/resources/META-INF/mods.toml (100%) rename platforms/{forge => forge-1.18.2}/src/main/resources/pack.mcmeta (100%) rename platforms/{forge => forge-1.18.2}/src/main/resources/unifiedmetrics.mixins.json (100%) diff --git a/platforms/forge/build.gradle.kts b/platforms/forge-1.18.2/build.gradle.kts similarity index 100% rename from platforms/forge/build.gradle.kts rename to platforms/forge-1.18.2/build.gradle.kts diff --git a/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginPacketListenerImplMixin.java b/platforms/forge-1.18.2/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginPacketListenerImplMixin.java similarity index 100% rename from platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginPacketListenerImplMixin.java rename to platforms/forge-1.18.2/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerLoginPacketListenerImplMixin.java diff --git a/platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerStatusPacketListenerImplMixin.java b/platforms/forge-1.18.2/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerStatusPacketListenerImplMixin.java similarity index 100% rename from platforms/forge/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerStatusPacketListenerImplMixin.java rename to platforms/forge-1.18.2/src/main/java/dev/cubxity/plugins/metrics/forge/mixins/ServerStatusPacketListenerImplMixin.java diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/UnifiedMetricsForgePlugin.kt b/platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/UnifiedMetricsForgePlugin.kt similarity index 100% rename from platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/UnifiedMetricsForgePlugin.kt rename to platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/UnifiedMetricsForgePlugin.kt diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt b/platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt similarity index 100% rename from platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt rename to platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/PlayerConnectionEvent.kt b/platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/PlayerConnectionEvent.kt similarity index 100% rename from platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/PlayerConnectionEvent.kt rename to platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/PlayerConnectionEvent.kt diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/ServerPingEvent.kt b/platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/ServerPingEvent.kt similarity index 100% rename from platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/ServerPingEvent.kt rename to platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/events/ServerPingEvent.kt diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/logger/Log4jLogger.kt b/platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/logger/Log4jLogger.kt similarity index 100% rename from platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/logger/Log4jLogger.kt rename to platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/logger/Log4jLogger.kt diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/events/EventsCollection.kt b/platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/events/EventsCollection.kt similarity index 100% rename from platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/events/EventsCollection.kt rename to platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/events/EventsCollection.kt diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollection.kt b/platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollection.kt similarity index 100% rename from platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollection.kt rename to platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollection.kt diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollector.kt b/platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollector.kt similarity index 100% rename from platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollector.kt rename to platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/server/ServerCollector.kt diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/tick/TickCollection.kt b/platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/tick/TickCollection.kt similarity index 100% rename from platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/tick/TickCollection.kt rename to platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/tick/TickCollection.kt diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollection.kt b/platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollection.kt similarity index 100% rename from platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollection.kt rename to platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollection.kt diff --git a/platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt b/platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt similarity index 100% rename from platforms/forge/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt rename to platforms/forge-1.18.2/src/main/kotlin/dev/cubxity/plugins/metrics/forge/metrics/world/WorldCollector.kt diff --git a/platforms/forge/src/main/resources/META-INF/mods.toml b/platforms/forge-1.18.2/src/main/resources/META-INF/mods.toml similarity index 100% rename from platforms/forge/src/main/resources/META-INF/mods.toml rename to platforms/forge-1.18.2/src/main/resources/META-INF/mods.toml diff --git a/platforms/forge/src/main/resources/pack.mcmeta b/platforms/forge-1.18.2/src/main/resources/pack.mcmeta similarity index 100% rename from platforms/forge/src/main/resources/pack.mcmeta rename to platforms/forge-1.18.2/src/main/resources/pack.mcmeta diff --git a/platforms/forge/src/main/resources/unifiedmetrics.mixins.json b/platforms/forge-1.18.2/src/main/resources/unifiedmetrics.mixins.json similarity index 100% rename from platforms/forge/src/main/resources/unifiedmetrics.mixins.json rename to platforms/forge-1.18.2/src/main/resources/unifiedmetrics.mixins.json diff --git a/settings.gradle.kts b/settings.gradle.kts index 144856f1..1af803b9 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -30,7 +30,7 @@ include(modulePrefix + platformPrefix + "minestom") include(modulePrefix + platformPrefix + "velocity") include(modulePrefix + platformPrefix + "bungee") include(modulePrefix + platformPrefix + "fabric") -include(modulePrefix + platformPrefix + "forge") +include(modulePrefix + platformPrefix + "forge-1.18.2") include(modulePrefix + driverPrefix + "influx") include(modulePrefix + driverPrefix + "prometheus") @@ -45,7 +45,7 @@ project(modulePrefix + platformPrefix + "minestom").projectDir = File(platformsD 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 + "forge").projectDir = File(platformsDir, "forge") +project(modulePrefix + platformPrefix + "forge-1.18.2").projectDir = File(platformsDir, "forge-1.18.2") val driversDir = File(rootDir, "drivers") project(modulePrefix + driverPrefix + "influx").projectDir = File(driversDir, "influx") From 049ec3e1eaac4844a0002cfb1ad61dd1507521e8 Mon Sep 17 00:00:00 2001 From: WarmthDawn Date: Mon, 20 Feb 2023 17:35:15 +0800 Subject: [PATCH 14/24] refactor: change build script to arch loom --- gradle/wrapper/gradle-wrapper.properties | 2 +- platforms/forge-1.18.2/build.gradle.kts | 87 ++++++++++++------------ platforms/forge-1.18.2/gradle.properties | 18 +++++ settings.gradle.kts | 10 +++ 4 files changed, 71 insertions(+), 46 deletions(-) create mode 100644 platforms/forge-1.18.2/gradle.properties diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 56350a50..2d23ddb2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -17,6 +17,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/platforms/forge-1.18.2/build.gradle.kts b/platforms/forge-1.18.2/build.gradle.kts index 8abf8c8d..6c7e006c 100644 --- a/platforms/forge-1.18.2/build.gradle.kts +++ b/platforms/forge-1.18.2/build.gradle.kts @@ -14,61 +14,64 @@ * You should have received a copy of the GNU Lesser General Public License * along with UnifiedMetrics. If not, see . */ -buildscript { - repositories { - maven("https://maven.minecraftforge.net") - maven("https://maven.parchmentmc.org") - mavenCentral() - } - dependencies { - classpath(group = "net.minecraftforge.gradle", name = "ForgeGradle", version = "5.1.+") { - isChanging = true - } - classpath("org.parchmentmc:librarian:1.+") - } -} plugins { id("net.kyori.blossom") id("com.github.johnrengelman.shadow") + id("dev.architectury.loom") version "0.12.0-SNAPSHOT" } -apply { - plugin("net.minecraftforge.gradle") - plugin("org.parchmentmc.librarian.forgegradle") -} - -apply(from = "https://raw.githubusercontent.com/thedarkcolour/KotlinForForge/site/thedarkcolour/kotlinforforge/gradle/kff-3.8.0.gradle") +//apply(from = "https://raw.githubusercontent.com/thedarkcolour/KotlinForForge/site/thedarkcolour/kotlinforforge/gradle/kff-3.8.0.gradle") java { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } -configure { - mappings("parchment", "2022.11.06-1.18.2") - - runs { - create("server") { - workingDirectory = project.file("run").canonicalPath - // "SCAN": For mods scan. - // "REGISTRIES": For firing of registry events. - // "REGISTRYDUMP": For getting the contents of all registries. - property("forge.logging.markers", "REGISTRIES") - property("forge.logging.console.level", "debug") - mods { - create("unifiedmetrics") { - source(sourceSets["main"]) - } - } - } + + +loom { + silentMojangMappingsLicense() + + forge { + mixinConfigs("unifiedmetrics.mixins.json") } } +repositories { + maven { + name = "ParchmentMC" + url = uri("https://maven.parchmentmc.org") + } + + maven { + name = "Kotlin for Forge" + url = uri("https://thedarkcolour.github.io/KotlinForForge/") + } +} + + dependencies { - "minecraft"("net.minecraftforge:forge:1.18.2-40.2.0") - val f = project.extensions.getByType() + + + minecraft("com.mojang:minecraft:1.18.2") + mappings(loom.layered { + officialMojangMappings() + parchment("org.parchmentmc.data:parchment-1.18.2:2022.11.06@zip") + }) + + forge("net.minecraftforge:forge:1.18.2-40.2.0") + + implementation("thedarkcolour:kotlinforforge:3.8.0") + shadow(project(":unifiedmetrics-core")) + + forgeRuntimeLibrary(project(":unifiedmetrics-core")) + forgeRuntimeLibrary("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") + forgeRuntimeLibrary("org.jetbrains.kotlin:kotlin-reflect:1.8.0") + forgeRuntimeLibrary("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2") + forgeRuntimeLibrary("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.5.2") + forgeRuntimeLibrary("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1") } tasks { @@ -78,7 +81,7 @@ tasks { shadowJar { archiveClassifier.set("") - configurations = listOf(project.configurations.shadow.get()) + configurations = listOf(project.configurations.shadow.get()) 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") @@ -93,12 +96,10 @@ tasks { relocate("org.reactivestreams", "dev.cubxity.plugins.metrics.libs.org.reactivestreams") exclude("javax/**", "kotlin/**", "kotlinx/**", "org/jetbrains/**", "org/intellij/**") - finalizedBy("reobfJar") } processResources { inputs.property("version", project.version) - filesMatching("META-INF/mods.toml") { expand("version" to project.version) } @@ -108,10 +109,6 @@ tasks { options.encoding = "UTF-8" options.release.set(17) } - - jar { - finalizedBy("reobfJar") - } } blossom { diff --git a/platforms/forge-1.18.2/gradle.properties b/platforms/forge-1.18.2/gradle.properties new file mode 100644 index 00000000..24883de3 --- /dev/null +++ b/platforms/forge-1.18.2/gradle.properties @@ -0,0 +1,18 @@ +# +# 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 . +# + +loom.platform=forge \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 1af803b9..beed9786 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -58,9 +58,19 @@ pluginManagement { name = "Fabric" url = uri("https://maven.fabricmc.net/") } + maven { + name = "ArchitecturyLoom" + url = uri("https://maven.architectury.dev/") + } + + maven { + name = "ParchmentMC" + url = uri("https://maven.parchmentmc.org") + } maven { name = "Forge" url = uri("https://files.minecraftforge.net/maven/") } + } } From fc703295d7dde9659858a287490855c1fa4fd73c Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Tue, 14 Mar 2023 22:53:28 +0800 Subject: [PATCH 15/24] fix: try to sort build step --- platforms/forge-1.18.2/build.gradle.kts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/platforms/forge-1.18.2/build.gradle.kts b/platforms/forge-1.18.2/build.gradle.kts index 6c7e006c..1c4a11b1 100644 --- a/platforms/forge-1.18.2/build.gradle.kts +++ b/platforms/forge-1.18.2/build.gradle.kts @@ -75,10 +75,20 @@ dependencies { } tasks { + java { + withSourcesJar() + } + compileKotlin { kotlinOptions.jvmTarget = "17" } + remapJar { + dependsOn(shadowJar) + mustRunAfter(shadowJar) + inputFile.set(shadowJar.get().archiveFile) + } + shadowJar { archiveClassifier.set("") configurations = listOf(project.configurations.shadow.get()) @@ -95,7 +105,6 @@ tasks { relocate("org.apache.common", "dev.cubxity.plugins.metrics.libs.org.apache.common") relocate("org.reactivestreams", "dev.cubxity.plugins.metrics.libs.org.reactivestreams") exclude("javax/**", "kotlin/**", "kotlinx/**", "org/jetbrains/**", "org/intellij/**") - } processResources { @@ -114,4 +123,4 @@ tasks { blossom { replaceTokenIn("src/main/kotlin/dev/cubxity/plugins/metrics/forge/bootstrap/UnifiedMetricsForgeBootstrap.kt") replaceToken("@version@", version) -} \ No newline at end of file +} From ed52b1d528c7f94e9f394f18499259ef50fb5710 Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Sat, 25 Mar 2023 21:50:39 +0800 Subject: [PATCH 16/24] fix: try to sort build step --- platforms/forge-1.18.2/build.gradle.kts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/platforms/forge-1.18.2/build.gradle.kts b/platforms/forge-1.18.2/build.gradle.kts index 1c4a11b1..016570db 100644 --- a/platforms/forge-1.18.2/build.gradle.kts +++ b/platforms/forge-1.18.2/build.gradle.kts @@ -14,6 +14,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with UnifiedMetrics. If not, see . */ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { id("net.kyori.blossom") @@ -52,8 +53,6 @@ repositories { dependencies { - - minecraft("com.mojang:minecraft:1.18.2") mappings(loom.layered { officialMojangMappings() @@ -75,22 +74,24 @@ dependencies { } tasks { - java { - withSourcesJar() - } - compileKotlin { kotlinOptions.jvmTarget = "17" } + prepareRemapJar { + dependsOn(shadowJar) + mustRunAfter(shadowJar) + } + remapJar { + archiveClassifier.set("remap") dependsOn(shadowJar) mustRunAfter(shadowJar) - inputFile.set(shadowJar.get().archiveFile) + inputFile.set(shadowJar.get().archiveFile.get()) } shadowJar { - archiveClassifier.set("") + archiveClassifier.set("all") configurations = listOf(project.configurations.shadow.get()) relocate("retrofit2", "dev.cubxity.plugins.metrics.libs.retrofit2") relocate("com.charleskorn", "dev.cubxity.plugins.metrics.libs.com.charleskorn") From a4cbb0f273e09668ad3c69f29b42a1e564effb7d Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Sat, 25 Mar 2023 22:27:22 +0800 Subject: [PATCH 17/24] chore: update loom --- platforms/forge-1.18.2/build.gradle.kts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/platforms/forge-1.18.2/build.gradle.kts b/platforms/forge-1.18.2/build.gradle.kts index 016570db..586afa3c 100644 --- a/platforms/forge-1.18.2/build.gradle.kts +++ b/platforms/forge-1.18.2/build.gradle.kts @@ -19,7 +19,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { id("net.kyori.blossom") id("com.github.johnrengelman.shadow") - id("dev.architectury.loom") version "0.12.0-SNAPSHOT" + id("dev.architectury.loom") version "1.1-SNAPSHOT" } //apply(from = "https://raw.githubusercontent.com/thedarkcolour/KotlinForForge/site/thedarkcolour/kotlinforforge/gradle/kff-3.8.0.gradle") @@ -78,11 +78,6 @@ tasks { kotlinOptions.jvmTarget = "17" } - prepareRemapJar { - dependsOn(shadowJar) - mustRunAfter(shadowJar) - } - remapJar { archiveClassifier.set("remap") dependsOn(shadowJar) From 2eb6318698eda177d282b54b09b2be1e8e3e2d41 Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Sat, 25 Mar 2023 23:10:22 +0800 Subject: [PATCH 18/24] fix: sort build step --- platforms/forge-1.18.2/build.gradle.kts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platforms/forge-1.18.2/build.gradle.kts b/platforms/forge-1.18.2/build.gradle.kts index 586afa3c..04bbfad0 100644 --- a/platforms/forge-1.18.2/build.gradle.kts +++ b/platforms/forge-1.18.2/build.gradle.kts @@ -80,12 +80,12 @@ tasks { remapJar { archiveClassifier.set("remap") - dependsOn(shadowJar) - mustRunAfter(shadowJar) - inputFile.set(shadowJar.get().archiveFile.get()) + inputFile.set(jar.get().archiveFile.get()) } shadowJar { + dependsOn(remapJar) + mustRunAfter(remapJar) archiveClassifier.set("all") configurations = listOf(project.configurations.shadow.get()) relocate("retrofit2", "dev.cubxity.plugins.metrics.libs.retrofit2") From bcd8af976eef8a3e12701546cfc98ff16c4377e5 Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Sun, 26 Mar 2023 22:15:47 +0800 Subject: [PATCH 19/24] fix: set mixin refmap name --- platforms/forge-1.18.2/build.gradle.kts | 8 ++++++-- .../main/resources/unifiedmetrics.mixins.json | 16 ++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/platforms/forge-1.18.2/build.gradle.kts b/platforms/forge-1.18.2/build.gradle.kts index 04bbfad0..a0847323 100644 --- a/platforms/forge-1.18.2/build.gradle.kts +++ b/platforms/forge-1.18.2/build.gradle.kts @@ -37,6 +37,10 @@ loom { forge { mixinConfigs("unifiedmetrics.mixins.json") } + + mixin { + defaultRefmapName.set("mixin.refmap.json") + } } repositories { @@ -79,14 +83,14 @@ tasks { } remapJar { - archiveClassifier.set("remap") + archiveClassifier.set("") inputFile.set(jar.get().archiveFile.get()) } shadowJar { dependsOn(remapJar) mustRunAfter(remapJar) - archiveClassifier.set("all") + archiveClassifier.set("") configurations = listOf(project.configurations.shadow.get()) relocate("retrofit2", "dev.cubxity.plugins.metrics.libs.retrofit2") relocate("com.charleskorn", "dev.cubxity.plugins.metrics.libs.com.charleskorn") diff --git a/platforms/forge-1.18.2/src/main/resources/unifiedmetrics.mixins.json b/platforms/forge-1.18.2/src/main/resources/unifiedmetrics.mixins.json index 4e2d207e..99882eb3 100644 --- a/platforms/forge-1.18.2/src/main/resources/unifiedmetrics.mixins.json +++ b/platforms/forge-1.18.2/src/main/resources/unifiedmetrics.mixins.json @@ -1,10 +1,10 @@ { - "required": true, - "minVersion": "0.8", - "package": "dev.cubxity.plugins.metrics.forge.mixins", - "compatibilityLevel": "JAVA_8", - "mixins": [ - "ServerLoginPacketListenerImplMixin", - "ServerStatusPacketListenerImplMixin" - ] + "required": true, + "minVersion": "0.8", + "package": "dev.cubxity.plugins.metrics.forge.mixins", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "ServerLoginPacketListenerImplMixin", + "ServerStatusPacketListenerImplMixin" + ] } \ No newline at end of file From 7e3d234f029f4ca71d528f07a07ae97f999936cc Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Mon, 27 Mar 2023 00:36:22 +0800 Subject: [PATCH 20/24] fix: try to set shadow jar input --- platforms/forge-1.18.2/build.gradle.kts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/platforms/forge-1.18.2/build.gradle.kts b/platforms/forge-1.18.2/build.gradle.kts index a0847323..73e359a8 100644 --- a/platforms/forge-1.18.2/build.gradle.kts +++ b/platforms/forge-1.18.2/build.gradle.kts @@ -14,23 +14,18 @@ * You should have received a copy of the GNU Lesser General Public License * along with UnifiedMetrics. If not, see . */ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { id("net.kyori.blossom") id("com.github.johnrengelman.shadow") - id("dev.architectury.loom") version "1.1-SNAPSHOT" + id("dev.architectury.loom") version "1.1.324" } -//apply(from = "https://raw.githubusercontent.com/thedarkcolour/KotlinForForge/site/thedarkcolour/kotlinforforge/gradle/kff-3.8.0.gradle") - java { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } - - loom { silentMojangMappingsLicense() @@ -55,7 +50,6 @@ repositories { } } - dependencies { minecraft("com.mojang:minecraft:1.18.2") mappings(loom.layered { @@ -88,9 +82,10 @@ tasks { } shadowJar { + archiveClassifier.set("") dependsOn(remapJar) mustRunAfter(remapJar) - archiveClassifier.set("") + from(remapJar) configurations = listOf(project.configurations.shadow.get()) relocate("retrofit2", "dev.cubxity.plugins.metrics.libs.retrofit2") relocate("com.charleskorn", "dev.cubxity.plugins.metrics.libs.com.charleskorn") From 62c98104906c44e731eb19ffa6c425611ea0af2f Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Mon, 27 Mar 2023 11:29:36 +0800 Subject: [PATCH 21/24] fix: try to set shadow jar input --- platforms/forge-1.18.2/build.gradle.kts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/platforms/forge-1.18.2/build.gradle.kts b/platforms/forge-1.18.2/build.gradle.kts index 73e359a8..825cfa6f 100644 --- a/platforms/forge-1.18.2/build.gradle.kts +++ b/platforms/forge-1.18.2/build.gradle.kts @@ -77,15 +77,20 @@ tasks { } remapJar { - archiveClassifier.set("") + archiveClassifier.set("remap") inputFile.set(jar.get().archiveFile.get()) } shadowJar { - archiveClassifier.set("") + enabled = false // disable shadowJar for default settings can not satisfy out requirement. + } + + create("fatJar") { + archiveClassifier.set("all") dependsOn(remapJar) mustRunAfter(remapJar) - from(remapJar) + from(zipTree(remapJar.get().archiveFile)) + duplicatesStrategy = DuplicatesStrategy.WARN configurations = listOf(project.configurations.shadow.get()) relocate("retrofit2", "dev.cubxity.plugins.metrics.libs.retrofit2") relocate("com.charleskorn", "dev.cubxity.plugins.metrics.libs.com.charleskorn") @@ -113,6 +118,10 @@ tasks { options.encoding = "UTF-8" options.release.set(17) } + + assemble { + dependsOn(named("fatJar")) + } } blossom { From 5a239b22085c8853252349c48073514da2556bef Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Mon, 27 Mar 2023 11:39:08 +0800 Subject: [PATCH 22/24] chore: change shadow jar archiveClassifier --- platforms/forge-1.18.2/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/forge-1.18.2/build.gradle.kts b/platforms/forge-1.18.2/build.gradle.kts index 825cfa6f..cbba4174 100644 --- a/platforms/forge-1.18.2/build.gradle.kts +++ b/platforms/forge-1.18.2/build.gradle.kts @@ -86,7 +86,7 @@ tasks { } create("fatJar") { - archiveClassifier.set("all") + archiveClassifier.set("") dependsOn(remapJar) mustRunAfter(remapJar) from(zipTree(remapJar.get().archiveFile)) From 41734527502aba2ecb3f92f3a7aff38a371048b2 Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Tue, 28 Mar 2023 15:55:19 +0800 Subject: [PATCH 23/24] fix: package manifest --- platforms/forge-1.18.2/build.gradle.kts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/platforms/forge-1.18.2/build.gradle.kts b/platforms/forge-1.18.2/build.gradle.kts index cbba4174..1d8b861c 100644 --- a/platforms/forge-1.18.2/build.gradle.kts +++ b/platforms/forge-1.18.2/build.gradle.kts @@ -1,3 +1,5 @@ +import com.github.jengelman.gradle.plugins.shadow.transformers.ManifestAppenderTransformer + /* * This file is part of UnifiedMetrics. * @@ -26,11 +28,13 @@ java { targetCompatibility = JavaVersion.VERSION_17 } +val mixinConfigName = "unifiedmetrics.mixins.json" + loom { silentMojangMappingsLicense() forge { - mixinConfigs("unifiedmetrics.mixins.json") + mixinConfigs(mixinConfigName) } mixin { @@ -89,8 +93,8 @@ tasks { archiveClassifier.set("") dependsOn(remapJar) mustRunAfter(remapJar) - from(zipTree(remapJar.get().archiveFile)) - duplicatesStrategy = DuplicatesStrategy.WARN + from(zipTree(remapJar.get().archiveFile.get())) + duplicatesStrategy = DuplicatesStrategy.FAIL configurations = listOf(project.configurations.shadow.get()) relocate("retrofit2", "dev.cubxity.plugins.metrics.libs.retrofit2") relocate("com.charleskorn", "dev.cubxity.plugins.metrics.libs.com.charleskorn") @@ -105,6 +109,9 @@ tasks { relocate("org.apache.common", "dev.cubxity.plugins.metrics.libs.org.apache.common") relocate("org.reactivestreams", "dev.cubxity.plugins.metrics.libs.org.reactivestreams") exclude("javax/**", "kotlin/**", "kotlinx/**", "org/jetbrains/**", "org/intellij/**") + manifest { + attributes["MixinConfigs"] = mixinConfigName + } } processResources { From 879112aab376cbe299d2de440faeff9f88bad40a Mon Sep 17 00:00:00 2001 From: Eric_Lian Date: Thu, 6 Apr 2023 17:23:58 +0800 Subject: [PATCH 24/24] style: clean code --- platforms/forge-1.18.2/build.gradle.kts | 2 -- 1 file changed, 2 deletions(-) diff --git a/platforms/forge-1.18.2/build.gradle.kts b/platforms/forge-1.18.2/build.gradle.kts index 1d8b861c..ce7b49f5 100644 --- a/platforms/forge-1.18.2/build.gradle.kts +++ b/platforms/forge-1.18.2/build.gradle.kts @@ -1,5 +1,3 @@ -import com.github.jengelman.gradle.plugins.shadow.transformers.ManifestAppenderTransformer - /* * This file is part of UnifiedMetrics. *