-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SavePlayerDeck): saves the player's deck to dunga dunga
remove debug logs remove debug logs use NBT data to determine if the item is a deck or a card
- Loading branch information
1 parent
c506ea8
commit a5c877a
Showing
4 changed files
with
71 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
58 changes: 58 additions & 0 deletions
58
src/main/kotlin/org/trackedout/citadel/commands/SavePlayerDeckCommand.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,58 @@ | ||
package org.trackedout.citadel.commands | ||
|
||
import co.aikar.commands.BaseCommand | ||
import co.aikar.commands.annotation.CommandAlias | ||
import co.aikar.commands.annotation.CommandPermission | ||
import co.aikar.commands.annotation.Default | ||
import co.aikar.commands.annotation.Description | ||
import net.kyori.adventure.text.TextComponent | ||
import org.bukkit.block.ShulkerBox | ||
import org.bukkit.entity.Player | ||
import org.bukkit.inventory.meta.BlockStateMeta | ||
import org.trackedout.citadel.isDeckedOutCard | ||
import org.trackedout.citadel.isDeckedOutShulker | ||
import org.trackedout.client.apis.InventoryApi | ||
import org.trackedout.data.Cards | ||
|
||
@CommandAlias("save-shulker") | ||
class SavePlayerDeckCommand( | ||
private val inventoryAPI: InventoryApi | ||
): BaseCommand() { | ||
|
||
@Default | ||
@CommandPermission("decked-out.inventory.save-player-deck") | ||
@Description("Saves the player's deck with the current cards in their shulker") | ||
fun savePlayerDeck(player: Player) { | ||
val shulkerItemStack = player.inventory.storageContents.find { item -> item?.isDeckedOutShulker() == true } | ||
if (shulkerItemStack == null) { | ||
return | ||
} | ||
if (shulkerItemStack.itemMeta !is BlockStateMeta) { | ||
return | ||
} | ||
val blockMeta = shulkerItemStack.itemMeta as BlockStateMeta | ||
if (blockMeta.blockState !is ShulkerBox) { | ||
return | ||
} | ||
val deck = blockMeta.blockState as ShulkerBox | ||
val cards = deck.inventory.storageContents | ||
.filterNotNull() | ||
.filter { item -> item.isDeckedOutCard() } | ||
.flatMap { item -> | ||
val text = item.itemMeta.displayName() as TextComponent | ||
val cardDisplayName = text.content() | ||
val card = Cards.findCard(cardDisplayName) | ||
val cards = mutableListOf<String>() | ||
repeat(item.amount) { | ||
if (card != null) { | ||
cards.add(card.key) | ||
} | ||
} | ||
cards | ||
} | ||
.map { item -> item } | ||
.toTypedArray() | ||
|
||
inventoryAPI.inventoryOverwritePlayersDeck(player = player.name, deckId = "1", cards = cards) | ||
} | ||
} |