This repository has been archived by the owner on May 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/mineinabyss/looty/features/consumable/ConsumeItemFromInventory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/com/mineinabyss/looty/features/consumable/RequiresConsumable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |