Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Update idofront, geary 0.26
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Mar 14, 2024
1 parent 4b8d17b commit ce92b34
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 118 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
34 changes: 15 additions & 19 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=com.mineinabyss
version=0.12
idofrontVersion=0.21.5
version=0.13
idofrontVersion=0.22.3
2 changes: 1 addition & 1 deletion gradle/myLibs.versions.toml → gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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" }
11 changes: 1 addition & 10 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}
}

14 changes: 6 additions & 8 deletions src/main/kotlin/com/mineinabyss/looty/LootyPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -26,11 +24,10 @@ class LootyPlugin : JavaPlugin() {
all()
}
install(ItemRecipes)
}

geary.pipeline.addSystems(
DisableItemInteractionsSystem(),
PotionMixRecipeSystem(),
)
geary.run {
createPotionMixRecipeSystem()
}
}

Expand All @@ -42,6 +39,7 @@ class LootyPlugin : JavaPlugin() {
BackpackListener(),
FoodConsumptionListener(),
SpawnHeldPrefabSystem(),
DisableItemInteractionsBukkitListener()
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,12 +17,13 @@ class ConsumeItemFromInventory(
)

@AutoScan
class ConsumeItemAction : GearyListener() {
val Pointers.player by get<Player>().on(target)
val Pointers.action by get<ConsumeItemFromInventory>().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<Player>()
val action by source.get<ConsumeItemFromInventory>()
}
).exec {
val matchedItem = player.inventory.firstOrNull { action.type.matches(it) } ?: return@exec
matchedItem.amount -= action.amount
}

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,11 +17,13 @@ class RequiresConsumable(
)

@AutoScan
class RequiresConsumableCondition : CheckingListener() {
val Pointers.player by get<Player>().on(target)
val Pointers.condition by get<RequiresConsumable>().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<Player>()
val condition by source.get<RequiresConsumable>()
}
).check {
val matchedItem = player.inventory.firstOrNull { condition.type.matches(it) } ?: return@check false
matchedItem.amount >= condition.minAmount
}

Original file line number Diff line number Diff line change
@@ -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<Event>().map { (it as? Cancellable) }.on(event)
// private val Pointers.interacted by family { has<Interacted>() }.on(event)
private val Pointers.noVanilla by family { has<DisableItemInteractions>() }.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<DisableItemInteractions>())
isCancelled = true
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<SetRecipes>()
val Pointer.prefabKey by get<PrefabKey>()
val recipes by get<SetRecipes>()
val prefabKey by get<PrefabKey>()
}

fun registerRecipes(): Set<NamespacedKey> {
val discoveredRecipes = mutableSetOf<NamespacedKey>()
fun CachedQueryRunner<ItemRecipeQuery>.registerRecipes(): Set<NamespacedKey> {
val discoveredRecipes = mutableSetOf<NamespacedKey>()

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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemRecipeQuery>

companion object : GearyAddonWithDefault<ItemRecipes> {
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() {
Expand Down
Loading

0 comments on commit ce92b34

Please sign in to comment.