Skip to content

Commit 825cb48

Browse files
committed
Store MatrixShop overflow items in mailbox
1 parent a2e299c commit 825cb48

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/main/kotlin/com/y54895/matrixstorage/bridge/MatrixShopBridge.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,14 @@ object MatrixShopBridge {
9090
val item = getter(request, "getItem") as? org.bukkit.inventory.ItemStack
9191
val money = (getter(request, "getMoney") as? Number)?.toDouble() ?: 0.0
9292
val currencyKey = getter(request, "getCurrencyKey")?.toString() ?: "vault"
93+
val metadata = getter(request, "getMetadata") as? Map<*, *>
94+
val target = metadata?.get("delivery-target")?.toString()?.lowercase()
9395
if (item != null && item.type != org.bukkit.Material.AIR && item.amount > 0) {
94-
WarehouseService.pushPendingItems(ownerId, ownerName, item.clone())
96+
if (target == "mailbox") {
97+
MailboxService.createSystemItemMessage(ownerId, ownerName, sourceModule, sourceId, item.clone(), "来自 $sourceModule 的物品投递: $reason")
98+
} else {
99+
WarehouseService.pushPendingItems(ownerId, ownerName, item.clone())
100+
}
95101
}
96102
if (money > 0.0) {
97103
MailboxService.createSystemMoneyMessage(ownerId, ownerName, sourceModule, sourceId, money, currencyKey, "来自 $sourceModule 的仓库投递: $reason")

src/main/kotlin/com/y54895/matrixstorage/service/StorageServices.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,31 @@ object MailboxService {
494494
)
495495
}
496496

497+
fun createSystemItemMessage(ownerId: UUID, ownerName: String, sourceModule: String, sourceId: String, item: ItemStack, text: String) {
498+
if (item.type == Material.AIR || item.amount <= 0) {
499+
return
500+
}
501+
if (!SlotUnlockService.canReceivePlayerMail(ownerId, ownerName)) {
502+
WarehouseService.pushPendingItems(ownerId, ownerName, item.clone())
503+
return
504+
}
505+
StorageStateService.addMailboxMessage(
506+
MailboxMessage(
507+
id = UUID.randomUUID().toString(),
508+
ownerId = ownerId,
509+
ownerName = ownerName,
510+
senderId = null,
511+
senderName = "System",
512+
sourceModule = sourceModule,
513+
sourceId = sourceId,
514+
text = text,
515+
attachedItem = item.clone(),
516+
money = 0.0,
517+
currencyKey = "vault"
518+
)
519+
)
520+
}
521+
497522
fun claim(player: Player, messageId: String): Boolean {
498523
val message = StorageStateService.mailboxMessage(messageId) ?: return false
499524
if (message.ownerId != player.uniqueId || message.claimed) {

0 commit comments

Comments
 (0)