diff --git a/.gitignore b/.gitignore index 3855ad4..e3dbc61 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,5 @@ astra.properties local.properties .gradle/ build/ -orm/src/test/resources/mysql.json \ No newline at end of file +orm/src/test/resources/mysql.json +core-neoforge/runs \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index ebf876d..0c8b766 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { alias(libs.plugins.klibs.gradle.detekt.compose) apply false alias(libs.plugins.klibs.gradle.dokka.root) apply false alias(libs.plugins.klibs.gradle.dokka.module) apply false - alias(libs.plugins.klibs.gradle.java.core) apply false + alias(libs.plugins.klibs.gradle.java.version) apply false alias(libs.plugins.klibs.gradle.publication) apply false alias(libs.plugins.klibs.gradle.rootinfo) apply false } @@ -21,6 +21,6 @@ subprojects.forEach { it.apply(plugin = "ru.astrainteractive.gradleplugin.publication") } it.plugins.withId("org.jetbrains.kotlin.jvm") { - it.apply(plugin = "ru.astrainteractive.gradleplugin.java.core") + it.apply(plugin = "ru.astrainteractive.gradleplugin.java.version") } } diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/coroutine/ForgeMainDispatcher.kt b/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/coroutine/ForgeMainDispatcher.kt deleted file mode 100644 index 5270efc..0000000 --- a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/coroutine/ForgeMainDispatcher.kt +++ /dev/null @@ -1,31 +0,0 @@ -package ru.astrainteractive.astralibs.coroutine - -import kotlinx.coroutines.CoroutineDispatcher -import net.minecraftforge.fml.DistExecutor -import net.minecraftforge.fml.loading.FMLEnvironment -import ru.astrainteractive.astralibs.async.CoroutineTimings -import ru.astrainteractive.klibs.mikro.core.util.tryCast -import kotlin.coroutines.AbstractCoroutineContextElement -import kotlin.coroutines.CoroutineContext - -class ForgeMainDispatcher : CoroutineDispatcher() { - - override fun isDispatchNeeded(context: CoroutineContext): Boolean { - return true - } - - override fun dispatch(context: CoroutineContext, block: Runnable) { - DistExecutor.safeRunWhenOn(FMLEnvironment.dist) { - val key = context.tryCast()?.key - val timingsKey = key?.tryCast() - val timedRunnable = timingsKey?.let(context::get) - - if (timedRunnable == null) { - DistExecutor.SafeRunnable { block.run() } - } else { - timedRunnable.queue.add(block) - DistExecutor.SafeRunnable { timedRunnable.run() } - } - } - } -} diff --git a/core-forge/build.gradle.kts b/core-neoforge/build.gradle.kts similarity index 61% rename from core-forge/build.gradle.kts rename to core-neoforge/build.gradle.kts index d3e82ee..e241ee1 100644 --- a/core-forge/build.gradle.kts +++ b/core-neoforge/build.gradle.kts @@ -1,15 +1,15 @@ +import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireJinfo + plugins { kotlin("jvm") kotlin("plugin.serialization") - alias(libs.plugins.forgegradle) + alias(libs.plugins.neoforgegradle) } dependencies { // Kotlin compileOnly(libs.kotlin.coroutines.core) - compileOnly(libs.klibs.mikro.core) - compileOnly(libs.kyori.api) compileOnly(libs.kyori.gson) compileOnly(libs.kyori.legacy) @@ -25,16 +25,18 @@ dependencies { implementation(projects.command) } -dependencies { - minecraft( - "net.minecraftforge", - "forge", - "${libs.versions.minecraft.mojang.version.get()}-${libs.versions.minecraft.forgeversion.get()}" +tasks.withType { + javaCompiler.set( + javaToolchains.compilerFor { + requireJinfo.jtarget.majorVersion + .let(JavaLanguageVersion::of) + .let(languageVersion::set) + } ) } -minecraft { - mappings("official", libs.versions.minecraft.mojang.version.get()) +dependencies { + compileOnly(libs.minecraft.neoforgeversion) } configurations.runtimeElements { diff --git a/core-neoforge/gradle.properties b/core-neoforge/gradle.properties new file mode 100644 index 0000000..d431dff --- /dev/null +++ b/core-neoforge/gradle.properties @@ -0,0 +1 @@ +makeevrserg.java.source=21 diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/command/registrar/ForgeCommandRegistrarContext.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/command/registrar/NeoForgeCommandRegistrarContext.kt similarity index 87% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/command/registrar/ForgeCommandRegistrarContext.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/command/registrar/NeoForgeCommandRegistrarContext.kt index 8b80d00..27419fb 100644 --- a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/command/registrar/ForgeCommandRegistrarContext.kt +++ b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/command/registrar/NeoForgeCommandRegistrarContext.kt @@ -9,11 +9,11 @@ import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn import net.minecraft.commands.CommandSourceStack -import net.minecraftforge.event.RegisterCommandsEvent -import net.minecraftforge.eventbus.api.EventPriority +import net.neoforged.bus.api.EventPriority +import net.neoforged.neoforge.event.RegisterCommandsEvent import ru.astrainteractive.astralibs.event.flowEvent -class ForgeCommandRegistrarContext( +class NeoForgeCommandRegistrarContext( private val mainScope: CoroutineScope, ) { private val registerCommandsEvent = flowEvent(EventPriority.HIGHEST) diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/command/util/ForgeCommandExt.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/command/util/NeoForgeCommandExt.kt similarity index 100% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/command/util/ForgeCommandExt.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/command/util/NeoForgeCommandExt.kt diff --git a/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/coroutine/NeoForgeMainDispatcher.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/coroutine/NeoForgeMainDispatcher.kt new file mode 100644 index 0000000..670a1ec --- /dev/null +++ b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/coroutine/NeoForgeMainDispatcher.kt @@ -0,0 +1,28 @@ +package ru.astrainteractive.astralibs.coroutine + +import kotlinx.coroutines.MainCoroutineDispatcher +import net.minecraft.client.Minecraft +import net.neoforged.api.distmarker.Dist +import net.neoforged.fml.loading.FMLEnvironment +import ru.astrainteractive.astralibs.server.util.NeoForgeUtil +import java.util.concurrent.Executor +import kotlin.coroutines.CoroutineContext + +class NeoForgeMainDispatcher : MainCoroutineDispatcher() { + override val immediate: MainCoroutineDispatcher + get() = this + private val executor = when (FMLEnvironment.dist) { + Dist.CLIENT -> Minecraft.getInstance() + Dist.DEDICATED_SERVER -> Executor { block -> + NeoForgeUtil.requireServer().executeBlocking(block) // .doRunTask(task) + } + } + + override fun isDispatchNeeded(context: CoroutineContext): Boolean { + return true + } + + override fun dispatch(context: CoroutineContext, block: Runnable) { + executor.execute(block) + } +} diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/event/ForgeEvent.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/event/NeoForgeEvent.kt similarity index 75% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/event/ForgeEvent.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/event/NeoForgeEvent.kt index e9434b1..e5a1741 100644 --- a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/event/ForgeEvent.kt +++ b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/event/NeoForgeEvent.kt @@ -4,9 +4,9 @@ import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.launch -import net.minecraftforge.common.MinecraftForge -import net.minecraftforge.eventbus.api.Event -import net.minecraftforge.eventbus.api.EventPriority +import net.neoforged.bus.api.Event +import net.neoforged.bus.api.EventPriority +import net.neoforged.neoforge.common.NeoForge import java.util.function.Consumer fun flowEvent( @@ -17,14 +17,14 @@ fun flowEvent( val consumer = Consumer { event -> launch { send(event) } } - MinecraftForge.EVENT_BUS.addListener( + NeoForge.EVENT_BUS.addListener( priority, isCancelled, type, consumer ) awaitClose { - MinecraftForge.EVENT_BUS.unregister(consumer) + NeoForge.EVENT_BUS.unregister(consumer) } } diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/event/PlayerMoveEvent.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/event/PlayerMoveEvent.kt similarity index 92% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/event/PlayerMoveEvent.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/event/PlayerMoveEvent.kt index 40df742..e0ba595 100644 --- a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/event/PlayerMoveEvent.kt +++ b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/event/PlayerMoveEvent.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.onEach import net.minecraft.world.entity.player.Player import net.minecraft.world.level.storage.ServerLevelData -import net.minecraftforge.event.entity.living.LivingEvent +import net.neoforged.neoforge.event.tick.PlayerTickEvent import ru.astrainteractive.astralibs.server.location.Location import ru.astrainteractive.klibs.mikro.core.util.cast import ru.astrainteractive.klibs.mikro.core.util.tryCast @@ -16,7 +16,7 @@ import kotlin.time.Duration.Companion.seconds import kotlin.time.toJavaDuration class PlayerMoveEvent( - val instance: LivingEvent.LivingTickEvent, + val instance: PlayerTickEvent.Post, val oldLocation: Location, val newLocation: Location, val player: Player @@ -27,7 +27,7 @@ fun playerMoveFlowEvent() = flow { .newBuilder() .expireAfterAccess(10.seconds.toJavaDuration()) .build() - flowEvent() + flowEvent() .filter { it.entity is Player } .onEach { event -> val player = event.entity.tryCast() ?: return@onEach diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/ForgeMinecraftNativeBridge.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/NeoForgeMinecraftNativeBridge.kt similarity index 84% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/ForgeMinecraftNativeBridge.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/NeoForgeMinecraftNativeBridge.kt index caebd78..5857d53 100644 --- a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/ForgeMinecraftNativeBridge.kt +++ b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/NeoForgeMinecraftNativeBridge.kt @@ -5,12 +5,12 @@ import ru.astrainteractive.astralibs.permission.Permissible import ru.astrainteractive.astralibs.server.player.MinecraftPlayer import ru.astrainteractive.astralibs.server.player.OfflineMinecraftPlayer import ru.astrainteractive.astralibs.server.player.OnlineMinecraftPlayer -import ru.astrainteractive.astralibs.server.util.ForgeUtil +import ru.astrainteractive.astralibs.server.util.NeoForgeUtil import ru.astrainteractive.astralibs.server.util.asOnlineMinecraftPlayer import ru.astrainteractive.astralibs.server.util.getOnlinePlayer import java.util.UUID -class ForgeMinecraftNativeBridge : MinecraftNativeBridge { +class NeoForgeMinecraftNativeBridge : MinecraftNativeBridge { override fun OnlineMinecraftPlayer.asAudience(): Audience { return OnlinePlayerAudience(this) } @@ -28,12 +28,12 @@ class ForgeMinecraftNativeBridge : MinecraftNativeBridge { } private fun findOnlinePlayer(uuid: UUID): OnlineMinecraftPlayer? { - val player = ForgeUtil.getOnlinePlayer(uuid) ?: return null + val player = NeoForgeUtil.getOnlinePlayer(uuid) ?: return null return player.asOnlineMinecraftPlayer() } private fun findOfflinePlayer(uuid: UUID): OfflineMinecraftPlayer? { - val player = ForgeUtil.getOnlinePlayer(uuid) ?: return null + val player = NeoForgeUtil.getOnlinePlayer(uuid) ?: return null return OfflineMinecraftPlayer( uuid = player.uuid, ) diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/ForgePlatformServer.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/NeoForgePlatformServer.kt similarity index 70% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/ForgePlatformServer.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/NeoForgePlatformServer.kt index b94bcf9..438650a 100644 --- a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/ForgePlatformServer.kt +++ b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/NeoForgePlatformServer.kt @@ -2,7 +2,7 @@ package ru.astrainteractive.astralibs.server import ru.astrainteractive.astralibs.server.player.OfflineMinecraftPlayer import ru.astrainteractive.astralibs.server.player.OnlineMinecraftPlayer -import ru.astrainteractive.astralibs.server.util.ForgeUtil +import ru.astrainteractive.astralibs.server.util.NeoForgeUtil import ru.astrainteractive.astralibs.server.util.asOfflineMinecraftPlayer import ru.astrainteractive.astralibs.server.util.asOnlineMinecraftPlayer import ru.astrainteractive.astralibs.server.util.getOnlinePlayer @@ -10,26 +10,26 @@ import ru.astrainteractive.astralibs.server.util.getOnlinePlayers import ru.astrainteractive.astralibs.server.util.getPlayerGameProfile import java.util.UUID -object ForgePlatformServer : PlatformServer { +object NeoForgePlatformServer : PlatformServer { override fun getOnlinePlayers(): List { - return ForgeUtil + return NeoForgeUtil .getOnlinePlayers() .map { serverPlayer -> serverPlayer.asOnlineMinecraftPlayer() } } override fun findOnlinePlayer(uuid: UUID): OnlineMinecraftPlayer? { - return ForgeUtil.getOnlinePlayer(uuid)?.asOnlineMinecraftPlayer() + return NeoForgeUtil.getOnlinePlayer(uuid)?.asOnlineMinecraftPlayer() } override fun findOfflinePlayer(uuid: UUID): OfflineMinecraftPlayer? { - return ForgeUtil.getPlayerGameProfile(uuid)?.asOfflineMinecraftPlayer() + return NeoForgeUtil.getPlayerGameProfile(uuid)?.asOfflineMinecraftPlayer() } override fun findOnlinePlayer(name: String): OnlineMinecraftPlayer? { - return ForgeUtil.getOnlinePlayer(name)?.asOnlineMinecraftPlayer() + return NeoForgeUtil.getOnlinePlayer(name)?.asOnlineMinecraftPlayer() } override fun findOfflinePlayer(name: String): OfflineMinecraftPlayer? { - return ForgeUtil.getPlayerGameProfile(name)?.asOfflineMinecraftPlayer() + return NeoForgeUtil.getPlayerGameProfile(name)?.asOfflineMinecraftPlayer() } } diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/OnlinePlayerAudience.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/OnlinePlayerAudience.kt similarity index 100% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/OnlinePlayerAudience.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/OnlinePlayerAudience.kt diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/OnlinePlayerLocatable.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/OnlinePlayerLocatable.kt similarity index 100% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/OnlinePlayerLocatable.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/OnlinePlayerLocatable.kt diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/OnlinePlayerTeleportable.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/OnlinePlayerTeleportable.kt similarity index 100% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/OnlinePlayerTeleportable.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/OnlinePlayerTeleportable.kt diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/AudienceExt.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/AudienceExt.kt similarity index 89% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/AudienceExt.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/AudienceExt.kt index ee8f4b1..14938bb 100644 --- a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/AudienceExt.kt +++ b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/AudienceExt.kt @@ -14,6 +14,6 @@ fun CommandSourceStack.asAudience() = Audience { component -> } fun OnlineMinecraftPlayer.asAudience() = Audience { component -> - val player = ForgeUtil.getOnlinePlayer(uuid) ?: return@Audience + val player = NeoForgeUtil.getOnlinePlayer(uuid) ?: return@Audience player.sendSystemMessage(component.toNative()) } diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/LocatableExt.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/LocatableExt.kt similarity index 90% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/LocatableExt.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/LocatableExt.kt index 31c9513..601a368 100644 --- a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/LocatableExt.kt +++ b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/LocatableExt.kt @@ -8,7 +8,7 @@ import ru.astrainteractive.astralibs.server.player.OnlineMinecraftPlayer import ru.astrainteractive.klibs.mikro.core.util.cast fun OnlineMinecraftPlayer.asLocatable() = Locatable { - val player = ForgeUtil.getOnlinePlayer(uuid) ?: error("$this is not online") + val player = NeoForgeUtil.getOnlinePlayer(uuid) ?: error("$this is not online") Location( x = player.x, y = player.y, diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/NativeComponentExt.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/NativeComponentExt.kt similarity index 74% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/NativeComponentExt.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/NativeComponentExt.kt index f286a4b..bad6086 100644 --- a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/NativeComponentExt.kt +++ b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/NativeComponentExt.kt @@ -7,11 +7,18 @@ import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer fun net.kyori.adventure.text.Component.toNative(): Component { val json = KyoriComponentSerializer.Json val jsonComponent = json.serializer.serialize(this) - return Serializer.fromJson(jsonComponent) ?: Component.empty() + + return Serializer.fromJson( + jsonComponent, + NeoForgeUtil.requireServer().registryAccess() + ) ?: Component.empty() } fun Component.toKyori(): net.kyori.adventure.text.Component { - val json = Serializer.toJson(this) + val json = Serializer.toJson( + this, + NeoForgeUtil.requireServer().registryAccess() + ) return KyoriComponentSerializer.Json.serializer.deserialize(json) } diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/ForgeUtil.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/NeoForgeUtil.kt similarity index 66% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/ForgeUtil.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/NeoForgeUtil.kt index 6ffd874..eef9df4 100644 --- a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/ForgeUtil.kt +++ b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/NeoForgeUtil.kt @@ -12,20 +12,21 @@ import kotlinx.coroutines.flow.stateIn import net.minecraft.server.MinecraftServer import net.minecraft.server.level.ServerPlayer import net.minecraft.world.level.Level -import net.minecraftforge.event.server.ServerStartedEvent -import net.minecraftforge.fml.loading.FMLLoader +import net.neoforged.fml.loading.FMLLoader +import net.neoforged.neoforge.event.server.ServerStartedEvent +import net.neoforged.neoforge.server.ServerLifecycleHooks import ru.astrainteractive.astralibs.event.flowEvent import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger import ru.astrainteractive.klibs.mikro.core.logging.Logger import java.util.UUID /** - * Don't forget to instantiate [ForgeUtil] on init at loader + * Don't forget to instantiate [NeoForgeUtil] on init at loader */ -object ForgeUtil : Logger by JUtiltLogger("AstraLibs-ForgeUtil") { +object NeoForgeUtil : Logger by JUtiltLogger("AstraLibs-ForgeUtil") { private val serverFlow = flowEvent() .map { event -> event.server } - .flowOn(Dispatchers.IO) + .flowOn(Dispatchers.Unconfined) .stateIn(GlobalScope, SharingStarted.Eagerly, null) val serverOrNull: MinecraftServer? @@ -41,14 +42,20 @@ object ForgeUtil : Logger by JUtiltLogger("AstraLibs-ForgeUtil") { return serverFlow.filterNotNull().first() } + fun requireServer(): MinecraftServer { + return ServerLifecycleHooks + .getCurrentServer() + ?: error("Server is not available") + } + fun bootstrap() = Unit } -fun ForgeUtil.isModLoaded(modId: String): Boolean { +fun NeoForgeUtil.isModLoaded(modId: String): Boolean { return FMLLoader.getLoadingModList().getModFileById(modId) != null } -fun ForgeUtil.getDefaultWorldName(): String? { +fun NeoForgeUtil.getDefaultWorldName(): String? { return serverOrNull ?.getLevel(Level.OVERWORLD) ?.level @@ -57,15 +64,15 @@ fun ForgeUtil.getDefaultWorldName(): String? { ?.path } -fun ForgeUtil.getPlayerGameProfile(uuid: UUID): GameProfile? { +fun NeoForgeUtil.getPlayerGameProfile(uuid: UUID): GameProfile? { return serverOrNull?.profileCache?.get(uuid)?.orElse(null) } -fun ForgeUtil.getPlayerGameProfile(name: String): GameProfile? { +fun NeoForgeUtil.getPlayerGameProfile(name: String): GameProfile? { return serverOrNull?.profileCache?.get(name)?.orElse(null) } -fun ForgeUtil.getOnlinePlayers(): List { +fun NeoForgeUtil.getOnlinePlayers(): List { return serverOrNull ?.playerList ?.players @@ -74,14 +81,14 @@ fun ForgeUtil.getOnlinePlayers(): List { .filterNotNull() } -fun ForgeUtil.getOnlinePlayer(uuid: UUID): ServerPlayer? { +fun NeoForgeUtil.getOnlinePlayer(uuid: UUID): ServerPlayer? { return serverOrNull?.playerList?.getPlayer(uuid) } -fun ForgeUtil.getOnlinePlayer(name: String): ServerPlayer? { +fun NeoForgeUtil.getOnlinePlayer(name: String): ServerPlayer? { return serverOrNull?.playerList?.getPlayerByName(name) } -fun ForgeUtil.getNextTickTime(): Double { +fun NeoForgeUtil.getNextTickTime(): Double { return serverOrNull?.nextTickTime?.toDouble() ?: 0.0 } diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/PermissibleExt.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/PermissibleExt.kt similarity index 87% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/PermissibleExt.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/PermissibleExt.kt index 5b08b93..7ad448d 100644 --- a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/PermissibleExt.kt +++ b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/PermissibleExt.kt @@ -5,7 +5,7 @@ import ru.astrainteractive.astralibs.permission.LuckPermsPermissible import ru.astrainteractive.astralibs.permission.Permissible fun Player.asPermissible(): Permissible { - return if (ForgeUtil.isModLoaded("luckperms")) { + return if (NeoForgeUtil.isModLoaded("luckperms")) { LuckPermsPermissible(this.uuid) } else { error("No permission provider loaded!") diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/PlayerExt.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/PlayerExt.kt similarity index 100% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/PlayerExt.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/PlayerExt.kt diff --git a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/TeleportableExt.kt b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/TeleportableExt.kt similarity index 83% rename from core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/TeleportableExt.kt rename to core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/TeleportableExt.kt index 51bdfd6..90a95ee 100644 --- a/core-forge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/TeleportableExt.kt +++ b/core-neoforge/src/main/kotlin/ru/astrainteractive/astralibs/server/util/TeleportableExt.kt @@ -5,8 +5,8 @@ import ru.astrainteractive.astralibs.server.Teleportable import ru.astrainteractive.astralibs.server.player.OnlineMinecraftPlayer fun OnlineMinecraftPlayer.asTeleportable() = Teleportable { location -> - val player = ForgeUtil.getOnlinePlayer(uuid) ?: return@Teleportable - val level = ForgeUtil.serverOrNull + val player = NeoForgeUtil.getOnlinePlayer(uuid) ?: return@Teleportable + val level = NeoForgeUtil.serverOrNull ?.allLevels ?.firstOrNull { (it.level.levelData as ServerLevelData).levelName == location.worldName } ?: return@Teleportable diff --git a/gradle.properties b/gradle.properties index d4279f2..675bb19 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ makeevrserg.java.ktarget=21 # Project makeevrserg.project.name=AstraLibs makeevrserg.project.group=ru.astrainteractive.astralibs -makeevrserg.project.version.string=3.29.1 +makeevrserg.project.version.string=3.30.0 makeevrserg.project.description=Core utilities for spigot development makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com makeevrserg.project.url=https://empireprojekt.ru diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 29eb866..bc6571c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,6 +7,7 @@ driver-mariadb = "3.5.6" driver-mysql = "8.0.33" exposed = "0.61.0" forgegradle = "[6.0,6.2)" +neoforgegradle = "7.1.4" gradle-buildconfig = "5.7.0" gradle-ftp = "0.1.2" gradle-shadow = "9.2.2" @@ -14,7 +15,7 @@ gson = "2.13.2" guava = "33.5.0-jre" jda = "6.0.0-preview" jda-webhook = "0.8.4" -klibs-gradleplugin = "1.11.1" +klibs-gradleplugin = "1.13.2" klibs-kdi = "1.4.8" klibs-kstorage = "4.2.3" klibs-mikro = "1.16.0" @@ -49,6 +50,7 @@ minecraft-towny = "0.101.2.1" minecraft-vault = "1.7.1" minecraft-velocity = "4.0.0-SNAPSHOT" minecraft-forgeversion = "47.2.20" +minecraft-neoforgeversion = "21.1.129" shadow = "8.1.8" telegrambots = "9.1.0" tests-junit-bom = "6.0.0" @@ -126,6 +128,7 @@ minecraft-spigot-core = { module = "org.spigotmc:spigot", version.ref = "minecra minecraft-towny = { module = "com.palmergames.bukkit.towny:towny", version.ref = "minecraft-towny" } minecraft-vaultapi = { module = "com.github.MilkBowl:VaultAPI", version.ref = "minecraft-vault" } minecraft-velocity-api = { module = "com.velocitypowered:velocity-api", version.ref = "minecraft-velocity" } +minecraft-neoforgeversion = { module = "net.neoforged:neoforge", version.ref = "minecraft-neoforgeversion" } telegrambots-client = { module = "org.telegram:telegrambots-client", version.ref = "telegrambots" } telegrambots-extensions = { module = "org.telegram:telegrambots-extensions", version.ref = "telegrambots" } telegrambots-longpolling = { module = "org.telegram:telegrambots-longpolling", version.ref = "telegrambots" } @@ -141,6 +144,7 @@ turbine = { module = "app.cash.turbine:turbine", version.ref = "turbine" } [plugins] fabric-loom = { id = "fabric-loom", version.ref = "minecraft-fabric-loom" } forgegradle = { id = "net.minecraftforge.gradle", version.ref = "forgegradle" } +neoforgegradle = { id = "net.neoforged.gradle.userdev", version.ref = "neoforgegradle" } gradle-buildconfig = { id = "com.github.gmazzo.buildconfig", version.ref = "gradle-buildconfig" } gradle-ftp = { id = "ru.astrainteractive.ftpplugin.gradleftp", version.ref = "gradle-ftp" } gradle-shadow = { id = "com.gradleup.shadow", version.ref = "gradle-shadow" } @@ -148,7 +152,7 @@ klibs-gradle-detekt = { id = "ru.astrainteractive.gradleplugin.detekt", version. klibs-gradle-detekt-compose = { id = "ru.astrainteractive.gradleplugin.detekt.compose", version.ref = "klibs-gradleplugin" } klibs-gradle-dokka-module = { id = "ru.astrainteractive.gradleplugin.dokka.module", version.ref = "klibs-gradleplugin" } klibs-gradle-dokka-root = { id = "ru.astrainteractive.gradleplugin.dokka.root", version.ref = "klibs-gradleplugin" } -klibs-gradle-java-core = { id = "ru.astrainteractive.gradleplugin.java.core", version.ref = "klibs-gradleplugin" } +klibs-gradle-java-version = { id = "ru.astrainteractive.gradleplugin.java.version", version.ref = "klibs-gradleplugin" } klibs-gradle-minecraft-empty = { id = "ru.astrainteractive.gradleplugin.minecraft.empty", version.ref = "klibs-gradleplugin" } klibs-gradle-minecraft-multiplatform = { id = "ru.astrainteractive.gradleplugin.minecraft.multiplatform", version.ref = "klibs-gradleplugin" } klibs-gradle-publication = { id = "ru.astrainteractive.gradleplugin.publication", version.ref = "klibs-gradleplugin" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927..f8e1ee3 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1158199..bad7c24 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 index 1b6c787..adff685 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +82,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -114,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -133,22 +132,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -165,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -193,18 +198,27 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..c4bdd3a 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,10 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +27,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,32 +59,33 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/settings.gradle.kts b/settings.gradle.kts index 5982d76..f20c739 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -12,6 +12,7 @@ pluginManagement { maven("https://oss.sonatype.org/content/groups/public/") maven("https://repo.essentialsx.net/snapshots/") maven("https://repo.maven.apache.org/maven2/") + maven("https://maven.neoforged.net/releases") maven("https://maven.enginehub.org/repo/") maven("https://maven.minecraftforge.net") maven("https://repo1.maven.org/maven2/") @@ -19,6 +20,7 @@ pluginManagement { maven("https://jitpack.io") } } + dependencyResolutionManagement { repositories { mavenLocal() @@ -39,11 +41,14 @@ dependencyResolutionManagement { maven("https://jitpack.io") } } + enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") + rootProject.name = "AstraLibs" + include(":core") include(":core-bukkit") -include(":core-forge") +include(":core-neoforge") include(":menu-bukkit") include(":command") include(":command-bukkit")