diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3922ff0..a54bbf9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,8 +17,9 @@ jobs: - uses: MineInAbyss/publish-action@master with: maven-metadata-url: https://repo.mineinabyss.com/releases/com/mineinabyss/looty/maven-metadata.xml - pages-path: build/dokka/htmlMultiModule/ - dokka: dokkaHtmlMultiModule + maven-snapshot-metadata-url: https://repo.mineinabyss.com/snapshots/com/mineinabyss/looty/maven-metadata.xml +# pages-path: build/dokka/htmlMultiModule/ +# dokka: dokkaHtmlMultiModule maven-username: ${{ secrets.MAVEN_PUBLISH_USERNAME }} maven-password: ${{ secrets.MAVEN_PUBLISH_PASSWORD }} release-files: | diff --git a/build.gradle.kts b/build.gradle.kts index 430a967..031fbf1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,39 +1,35 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -val idofrontVersion: String by project -val gearyVersion: String by project - @Suppress("DSL_SCOPE_VIOLATION") plugins { - alias(libs.plugins.kotlinx.serialization) - id("com.mineinabyss.conventions.kotlin.jvm") - id("com.mineinabyss.conventions.papermc") - id("com.mineinabyss.conventions.nms") - id("com.mineinabyss.conventions.copyjar") - id("com.mineinabyss.conventions.publication") - id("com.mineinabyss.conventions.autoversion") + alias(idofrontLibs.plugins.mia.kotlin.jvm) + alias(idofrontLibs.plugins.mia.papermc) + alias(idofrontLibs.plugins.mia.nms) + alias(idofrontLibs.plugins.mia.copyjar) + alias(idofrontLibs.plugins.mia.publication) + alias(idofrontLibs.plugins.mia.autoversion) + alias(idofrontLibs.plugins.kotlinx.serialization) } repositories { maven("https://repo.mineinabyss.com/snapshots") maven("https://jitpack.io") + maven("https://repo.dmulloy2.net/repository/public/") mavenLocal() } dependencies { // Other plugins - compileOnly(myLibs.geary.papermc) + compileOnly(libs.geary.papermc) // From Geary - compileOnly(libs.kotlinx.serialization.json) - compileOnly(libs.kotlinx.serialization.kaml) - compileOnly(libs.kotlinx.coroutines) - compileOnly(libs.minecraft.mccoroutine) - - // Shaded - implementation(libs.bundles.idofront.core) - implementation(libs.idofront.nms) + compileOnly(idofrontLibs.kotlinx.serialization.json) + compileOnly(idofrontLibs.kotlinx.serialization.kaml) + compileOnly(idofrontLibs.kotlinx.coroutines) + compileOnly(idofrontLibs.minecraft.mccoroutine) + compileOnly(idofrontLibs.bundles.idofront.core) + compileOnly(idofrontLibs.idofront.nms) } tasks { diff --git a/gradle.properties b/gradle.properties index 8bfc70c..14af0d9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group=com.mineinabyss -version=0.12 -idofrontVersion=0.21.5 +version=0.13 +idofrontVersion=0.22.3 diff --git a/gradle/myLibs.versions.toml b/gradle/libs.versions.toml similarity index 79% rename from gradle/myLibs.versions.toml rename to gradle/libs.versions.toml index 3f003fb..47eb2ca 100644 --- a/gradle/myLibs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -gearyPaper = "0.29.0" +gearyPaper = "0.29.12-dev.3" [libraries] geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "gearyPaper" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 366b8c3..2e7ad31 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,14 +7,6 @@ pluginManagement { maven("https://repo.papermc.io/repository/maven-public/") mavenLocal() } - - val idofrontVersion: String by settings - resolutionStrategy { - eachPlugin { - if (requested.id.id.startsWith("com.mineinabyss.conventions")) - useVersion(idofrontVersion) - } - } } dependencyResolutionManagement { @@ -26,8 +18,7 @@ dependencyResolutionManagement { } versionCatalogs { - create("libs").from("com.mineinabyss:catalog:$idofrontVersion") - create("myLibs").from(files("gradle/myLibs.versions.toml")) + create("idofrontLibs").from("com.mineinabyss:catalog:$idofrontVersion") } } diff --git a/src/main/kotlin/com/mineinabyss/looty/LootyPlugin.kt b/src/main/kotlin/com/mineinabyss/looty/LootyPlugin.kt index e1e436b..74829da 100644 --- a/src/main/kotlin/com/mineinabyss/looty/LootyPlugin.kt +++ b/src/main/kotlin/com/mineinabyss/looty/LootyPlugin.kt @@ -5,15 +5,13 @@ import com.mineinabyss.geary.autoscan.autoscan import com.mineinabyss.geary.modules.geary import com.mineinabyss.idofront.di.DI import com.mineinabyss.idofront.plugin.listeners -import com.mineinabyss.idofront.plugin.service -import com.mineinabyss.idofront.serialization.SerializablePrefabItemService import com.mineinabyss.looty.config.LootyModule import com.mineinabyss.looty.features.backpack.BackpackListener import com.mineinabyss.looty.features.food.FoodConsumptionListener import com.mineinabyss.looty.features.holdsentity.SpawnHeldPrefabSystem -import com.mineinabyss.looty.features.nointeraction.DisableItemInteractionsSystem +import com.mineinabyss.looty.features.nointeraction.DisableItemInteractionsBukkitListener import com.mineinabyss.looty.features.recipes.ItemRecipes -import com.mineinabyss.looty.features.recipes.PotionMixRecipeSystem +import com.mineinabyss.looty.features.recipes.createPotionMixRecipeSystem import com.mineinabyss.looty.features.wearables.WearableItemSystem import org.bukkit.plugin.java.JavaPlugin @@ -26,11 +24,10 @@ class LootyPlugin : JavaPlugin() { all() } install(ItemRecipes) + } - geary.pipeline.addSystems( - DisableItemInteractionsSystem(), - PotionMixRecipeSystem(), - ) + geary.run { + createPotionMixRecipeSystem() } } @@ -42,6 +39,7 @@ class LootyPlugin : JavaPlugin() { BackpackListener(), FoodConsumptionListener(), SpawnHeldPrefabSystem(), + DisableItemInteractionsBukkitListener() ) } diff --git a/src/main/kotlin/com/mineinabyss/looty/features/consumable/ConsumeItemFromInventory.kt b/src/main/kotlin/com/mineinabyss/looty/features/consumable/ConsumeItemFromInventory.kt index e86b46a..a7bbb50 100644 --- a/src/main/kotlin/com/mineinabyss/looty/features/consumable/ConsumeItemFromInventory.kt +++ b/src/main/kotlin/com/mineinabyss/looty/features/consumable/ConsumeItemFromInventory.kt @@ -1,8 +1,9 @@ package com.mineinabyss.looty.features.consumable import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.serialization.SerializableItemStack import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -16,12 +17,13 @@ class ConsumeItemFromInventory( ) @AutoScan -class ConsumeItemAction : GearyListener() { - val Pointers.player by get().on(target) - val Pointers.action by get().on(source) - - override fun Pointers.handle() { - val matchedItem = player.inventory.firstOrNull { action.type.matches(it) } ?: return - matchedItem.amount -= action.amount +fun GearyModule.createConsumeItemAction() = listener( + object : ListenerQuery() { + val player by get() + val action by source.get() } +).exec { + val matchedItem = player.inventory.firstOrNull { action.type.matches(it) } ?: return@exec + matchedItem.amount -= action.amount } + diff --git a/src/main/kotlin/com/mineinabyss/looty/features/consumable/RequiresConsumable.kt b/src/main/kotlin/com/mineinabyss/looty/features/consumable/RequiresConsumable.kt index b78fbfb..d8fa136 100644 --- a/src/main/kotlin/com/mineinabyss/looty/features/consumable/RequiresConsumable.kt +++ b/src/main/kotlin/com/mineinabyss/looty/features/consumable/RequiresConsumable.kt @@ -1,8 +1,9 @@ package com.mineinabyss.looty.features.consumable import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.events.CheckingListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.serialization.SerializableItemStack import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -16,11 +17,13 @@ class RequiresConsumable( ) @AutoScan -class RequiresConsumableCondition : CheckingListener() { - val Pointers.player by get().on(target) - val Pointers.condition by get().on(source) - override fun Pointers.check(): Boolean { - val matchedItem = player.inventory.firstOrNull { condition.type.matches(it) } ?: return false - return matchedItem.amount >= condition.minAmount +fun GearyModule.createRequiresConsumableCondition() = listener( + object : ListenerQuery() { + val player by get() + val condition by source.get() } +).check { + val matchedItem = player.inventory.firstOrNull { condition.type.matches(it) } ?: return@check false + matchedItem.amount >= condition.minAmount } + diff --git a/src/main/kotlin/com/mineinabyss/looty/features/nointeraction/DisableItemInteractionsSystem.kt b/src/main/kotlin/com/mineinabyss/looty/features/nointeraction/DisableItemInteractionsSystem.kt index 1cd0b84..986198a 100644 --- a/src/main/kotlin/com/mineinabyss/looty/features/nointeraction/DisableItemInteractionsSystem.kt +++ b/src/main/kotlin/com/mineinabyss/looty/features/nointeraction/DisableItemInteractionsSystem.kt @@ -1,20 +1,36 @@ package com.mineinabyss.looty.features.nointeraction -import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.datatypes.family.family -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.papermc.tracking.items.inventory.toGeary +import org.bukkit.entity.Player import org.bukkit.event.Cancellable -import org.bukkit.event.Event +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerInteractEntityEvent +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.event.player.PlayerItemConsumeEvent +import org.bukkit.inventory.EquipmentSlot -@AutoScan -class DisableItemInteractionsSystem : GearyListener() { - private val Pointers.bukkit by get().map { (it as? Cancellable) }.on(event) -// private val Pointers.interacted by family { has() }.on(event) - private val Pointers.noVanilla by family { has() }.on(target) +class DisableItemInteractionsBukkitListener : Listener { + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + fun PlayerInteractEvent.onClick() { + disableIfNeeded(player, hand) + } - override fun Pointers.handle() { - bukkit?.isCancelled = true + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + fun PlayerInteractEntityEvent.onClick() { + disableIfNeeded(player, hand) + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + fun PlayerItemConsumeEvent.onConsume() { + disableIfNeeded(player, hand) } -} + fun Cancellable.disableIfNeeded(player: Player, hand: EquipmentSlot?) { + val heldItem = player.inventory.toGeary()?.get(hand ?: return) ?: return + if (heldItem.has()) + isCancelled = true + } + +} diff --git a/src/main/kotlin/com/mineinabyss/looty/features/recipes/ItemRecipeQuery.kt b/src/main/kotlin/com/mineinabyss/looty/features/recipes/ItemRecipeQuery.kt index 8b3eb7d..414e1c4 100644 --- a/src/main/kotlin/com/mineinabyss/looty/features/recipes/ItemRecipeQuery.kt +++ b/src/main/kotlin/com/mineinabyss/looty/features/recipes/ItemRecipeQuery.kt @@ -2,48 +2,49 @@ package com.mineinabyss.looty.features.recipes import com.mineinabyss.geary.papermc.tracking.items.gearyItems import com.mineinabyss.geary.prefabs.PrefabKey -import com.mineinabyss.geary.systems.accessors.Pointer +import com.mineinabyss.geary.systems.query.CachedQueryRunner import com.mineinabyss.geary.systems.query.GearyQuery import com.mineinabyss.idofront.recipes.register -import com.mineinabyss.idofront.serialization.recipes.SerializableRecipeIngredients import com.mineinabyss.looty.config.looty import org.bukkit.Bukkit import org.bukkit.NamespacedKey import org.bukkit.inventory.ItemStack class ItemRecipeQuery : GearyQuery() { - val Pointer.recipes by get() - val Pointer.prefabKey by get() + val recipes by get() + val prefabKey by get() +} - fun registerRecipes(): Set { - val discoveredRecipes = mutableSetOf() +fun CachedQueryRunner.registerRecipes(): Set { + val discoveredRecipes = mutableSetOf() - forEach { pointer -> - val result: ItemStack? = runCatching { pointer.recipes.result?.toItemStackOrNull() ?: gearyItems.createItem(pointer.prefabKey) } - .getOrNull() + forEach { + val result: ItemStack? = runCatching { + recipes.result?.toItemStackOrNull() ?: gearyItems.createItem(prefabKey) + } + .getOrNull() - if (result == null) { - looty.plugin.logger.warning("Recipe ${pointer.prefabKey.key} is missing result item") - return@forEach - } + if (result == null) { + looty.plugin.logger.warning("Recipe ${prefabKey.key} is missing result item") + return@forEach + } - pointer.recipes.removeRecipes.forEach { - runCatching { - Bukkit.removeRecipe(NamespacedKey.fromString(it)!!) - }.onFailure { it.printStackTrace() } - } + recipes.removeRecipes.forEach { + runCatching { + Bukkit.removeRecipe(NamespacedKey.fromString(it)!!) + }.onFailure { it.printStackTrace() } + } - pointer.recipes.recipes.forEachIndexed { i, recipe -> - runCatching { - val key = NamespacedKey(pointer.prefabKey.namespace, "${pointer.prefabKey.key}$i") - // Register recipe only if not present - Bukkit.getRecipe(key) ?: recipe.toRecipe(key, result, pointer.recipes.group).register() - if (pointer.recipes.discoverRecipes) discoveredRecipes += key - }.onFailure { - looty.plugin.logger.warning("Failed to register recipe ${pointer.prefabKey.key} #$i, ${it.message}") - } + recipes.recipes.forEachIndexed { i, recipe -> + runCatching { + val key = NamespacedKey(prefabKey.namespace, "${prefabKey.key}$i") + // Register recipe only if not present + Bukkit.getRecipe(key) ?: recipe.toRecipe(key, result, recipes.group).register() + if (recipes.discoverRecipes) discoveredRecipes += key + }.onFailure { + looty.plugin.logger.warning("Failed to register recipe ${prefabKey.key} #$i, ${it.message}") } } - return discoveredRecipes } + return discoveredRecipes } diff --git a/src/main/kotlin/com/mineinabyss/looty/features/recipes/ItemRecipes.kt b/src/main/kotlin/com/mineinabyss/looty/features/recipes/ItemRecipes.kt index ad47b26..3c5cb53 100644 --- a/src/main/kotlin/com/mineinabyss/looty/features/recipes/ItemRecipes.kt +++ b/src/main/kotlin/com/mineinabyss/looty/features/recipes/ItemRecipes.kt @@ -4,16 +4,18 @@ import com.mineinabyss.geary.addons.GearyPhase import com.mineinabyss.geary.addons.dsl.GearyAddonWithDefault import com.mineinabyss.geary.modules.geary import com.mineinabyss.geary.papermc.gearyPaper +import com.mineinabyss.geary.systems.builders.cachedQuery +import com.mineinabyss.geary.systems.query.CachedQueryRunner import com.mineinabyss.idofront.plugin.listeners interface ItemRecipes { - val query: ItemRecipeQuery + val query: CachedQueryRunner companion object : GearyAddonWithDefault { val recipes by lazy { default().query.registerRecipes() } override fun default() = object : ItemRecipes { - override val query = ItemRecipeQuery() + override val query = geary.cachedQuery(ItemRecipeQuery()) } override fun ItemRecipes.install() { diff --git a/src/main/kotlin/com/mineinabyss/looty/features/recipes/PotionMixRecipeSystem.kt b/src/main/kotlin/com/mineinabyss/looty/features/recipes/PotionMixRecipeSystem.kt index dd30cd8..eeafacf 100644 --- a/src/main/kotlin/com/mineinabyss/looty/features/recipes/PotionMixRecipeSystem.kt +++ b/src/main/kotlin/com/mineinabyss/looty/features/recipes/PotionMixRecipeSystem.kt @@ -1,28 +1,32 @@ package com.mineinabyss.looty.features.recipes +import com.mineinabyss.geary.autoscan.AutoScan +import com.mineinabyss.geary.modules.GearyModule import com.mineinabyss.geary.papermc.tracking.items.gearyItems import com.mineinabyss.geary.prefabs.PrefabKey -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.looty.config.looty import org.bukkit.NamespacedKey /** * This system is implemented separate from idofront recipes since they are handled differently by Minecraft. */ -class PotionMixRecipeSystem : GearyListener() { - private val Pointers.prefabKey by get().whenSetOnTarget() - private val Pointers.potionmixes by get().whenSetOnTarget() - - override fun Pointers.handle() { - val result = potionmixes.result?.toItemStackOrNull() ?: gearyItems.createItem(prefabKey) - - if (result != null) { - potionmixes.potionmixes.forEachIndexed { i, potionmix -> - val key = NamespacedKey(prefabKey.namespace, "${prefabKey.key}$i") - looty.plugin.server.potionBrewer.removePotionMix(key) - looty.plugin.server.potionBrewer.addPotionMix(potionmix.toPotionMix(key, result)) - } - } else looty.plugin.logger.warning("PotionMix $prefabKey is missing result item") +@AutoScan +fun GearyModule.createPotionMixRecipeSystem() = listener( + object : ListenerQuery() { + val prefabKey by get() + val potionMixes by get() + override fun ensure() = event.anySet(::potionMixes, ::prefabKey) } +).exec { + val result = potionMixes.result?.toItemStackOrNull() ?: gearyItems.createItem(prefabKey) + + if (result != null) { + potionMixes.potionmixes.forEachIndexed { i, potionmix -> + val key = NamespacedKey(prefabKey.namespace, "${prefabKey.key}$i") + looty.plugin.server.potionBrewer.removePotionMix(key) + looty.plugin.server.potionBrewer.addPotionMix(potionmix.toPotionMix(key, result)) + } + } else looty.plugin.logger.warning("PotionMix $prefabKey is missing result item") }