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

Commit

Permalink
Start working on consumables
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Jan 18, 2024
1 parent ff030b3 commit 6fafd2f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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.idofront.serialization.SerializableItemStack
import org.bukkit.entity.Player

class ConsumeItemFromInventory(
val type: SerializableItemStack,
val amount: Int = 1,
)

@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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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.idofront.serialization.SerializableItemStack
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.bukkit.entity.Player

@Serializable
@SerialName("looty:requiresConsumable")
class RequiresConsumable(
val type: SerializableItemStack,
val minAmount: Int = 1,
)

@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
}
}

0 comments on commit 6fafd2f

Please sign in to comment.