Skip to content

Commit a2e299c

Browse files
committed
Add shared economy sync and slot unlocks
1 parent f57490f commit a2e299c

12 files changed

Lines changed: 466 additions & 94 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- 玩家邮箱
66
- 个人仓库
7+
- 仓库/邮箱格子解锁
78
- 位置型实体仓库
89
- MatrixShop 外部仓库投递对接
910
- CraftEngine / ItemsAdder / Nexo 自定义方块与家具接入
@@ -16,3 +17,9 @@
1617

1718
当前代码库默认支持 `sqlite / mysql / redis / yaml` 四种后端,并接入统一的 Matrix 文档站。
1819

20+
当前新增重点:
21+
22+
- 共享货币定义来自 `MatrixLib`
23+
- `MatrixLib / MatrixShop / MatrixStorage` 三端同步 `Economy/currency.yml`
24+
- 仓库与邮箱支持多条件、多价格、多货币解锁格子
25+
- 玩家总览页可直接执行容量扩容

gradle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
group=com.y54895.matrixstorage
22
version=1.0.0
3-
matrixlibApiVersion=1.0.1
3+
matrixlibApiVersion=1.1.0
44
kotlin.incremental=true
55
kotlin.incremental.java=true
66
kotlin.caching.enabled=true
77
kotlin.parallel.tasks.in.project=true
8-

src/main/kotlin/com/y54895/matrixstorage/MatrixStorage.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.y54895.matrixstorage.command.MatrixStorageCommands
77
import com.y54895.matrixstorage.integration.ExternalPlacementSupport
88
import com.y54895.matrixstorage.service.BlockWarehouseService
99
import com.y54895.matrixstorage.service.MailboxService
10+
import com.y54895.matrixstorage.service.SlotUnlockConfig
1011
import com.y54895.matrixstorage.service.StorageConfig
1112
import com.y54895.matrixstorage.service.StoragePersistenceService
1213
import com.y54895.matrixstorage.service.StorageStateService
@@ -31,6 +32,7 @@ object MatrixStorage : Plugin() {
3132
override fun onEnable() {
3233
try {
3334
StorageConfig.reload()
35+
SlotUnlockConfig.reload()
3436
StoragePersistenceService.reload()
3537
StorageStateService.pruneInvalidBlockWarehouses()
3638
BlockWarehouseService.reload()
@@ -69,4 +71,3 @@ object MatrixStorage : Plugin() {
6971
)
7072
}
7173
}
72-

src/main/kotlin/com/y54895/matrixstorage/command/MatrixStorageCommands.kt

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.y54895.matrixstorage.command
22

3+
import com.y54895.matrixlib.api.economy.MatrixEconomy
34
import com.y54895.matrixstorage.MatrixStorageMessages
45
import com.y54895.matrixstorage.MatrixStoragePlatform
6+
import com.y54895.matrixstorage.model.UnlockTarget
57
import com.y54895.matrixstorage.service.BlockWarehouseService
68
import com.y54895.matrixstorage.service.MailboxService
9+
import com.y54895.matrixstorage.service.SlotUnlockConfig
10+
import com.y54895.matrixstorage.service.SlotUnlockService
711
import com.y54895.matrixstorage.service.StorageConfig
812
import com.y54895.matrixstorage.service.StoragePersistenceService
913
import com.y54895.matrixstorage.service.StorageStateService
@@ -44,6 +48,7 @@ object MatrixStorageCommands {
4448
private fun handleMain(sender: CommandSender, args: Array<out String>): Boolean {
4549
if (args.isNotEmpty() && args[0].equals("reload", true) && sender.hasPermission("matrixstorage.admin")) {
4650
StorageConfig.reload()
51+
SlotUnlockConfig.reload()
4752
StoragePersistenceService.reload()
4853
MatrixStorageMessages.send(sender, "general.reloaded")
4954
return true
@@ -68,6 +73,7 @@ object MatrixStorageCommands {
6873
when (args[0].lowercase(Locale.ROOT)) {
6974
"reload" -> {
7075
StorageConfig.reload()
76+
SlotUnlockConfig.reload()
7177
StoragePersistenceService.reload()
7278
MatrixStorageMessages.send(sender, "general.reloaded")
7379
}
@@ -137,7 +143,10 @@ object MatrixStorageCommands {
137143
MatrixStorageMessages.send(player, "general.unknown-player")
138144
return true
139145
}
140-
MailboxService.sendText(player, target, text)
146+
if (!MailboxService.sendText(player, target, text)) {
147+
MatrixStorageMessages.send(player, "mailbox.full")
148+
return true
149+
}
141150
MatrixStorageMessages.send(player, "mailbox.sent", mapOf("target" to target.name))
142151
}
143152
"senditem" -> {
@@ -148,7 +157,7 @@ object MatrixStorageCommands {
148157
return true
149158
}
150159
if (!MailboxService.sendItem(player, target, text)) {
151-
MatrixStorageMessages.send(player, "mailbox.empty-hand")
160+
MatrixStorageMessages.send(player, if (player.inventory.itemInMainHand.type == org.bukkit.Material.AIR) "mailbox.empty-hand" else "mailbox.full")
152161
return true
153162
}
154163
MatrixStorageMessages.send(player, "mailbox.sent", mapOf("target" to target.name))
@@ -165,12 +174,28 @@ object MatrixStorageCommands {
165174
MatrixStorageMessages.send(player, "general.invalid-number")
166175
return true
167176
}
177+
if (!SlotUnlockService.canReceivePlayerMail(target.uniqueId, target.name)) {
178+
MatrixStorageMessages.send(player, "mailbox.full")
179+
return true
180+
}
181+
if (!MatrixEconomy.isAvailable("vault")) {
182+
MatrixStorageMessages.send(player, "mailbox.vault-missing")
183+
return true
184+
}
185+
if (!MatrixEconomy.has(player, "vault", amount)) {
186+
val shortage = MatrixEconomy.shortage(player, "vault", amount, mapOf("target" to target.name))
187+
if (!shortage.denyHandled) {
188+
MatrixStorageMessages.send(player, "mailbox.not-enough-money")
189+
}
190+
return true
191+
}
168192
if (!MailboxService.sendMoney(player, target, amount, text)) {
169193
MatrixStorageMessages.send(player, "mailbox.vault-missing")
170194
return true
171195
}
172196
MatrixStorageMessages.send(player, "mailbox.sent", mapOf("target" to target.name))
173197
}
198+
"unlock" -> StorageMenus.openUnlockMenu(player, UnlockTarget.MAILBOX)
174199
else -> StorageMenus.openMailbox(player)
175200
}
176201
return true
@@ -188,6 +213,7 @@ object MatrixStorageCommands {
188213
when (args[0].lowercase(Locale.ROOT)) {
189214
"personal" -> StorageMenus.openWarehouseInventory(player, player.uniqueId, player.name, pending = false)
190215
"pending" -> StorageMenus.openWarehouseInventory(player, player.uniqueId, player.name, pending = true)
216+
"unlock" -> StorageMenus.openUnlockMenu(player, UnlockTarget.WAREHOUSE)
191217
"open" -> {
192218
val record = BlockWarehouseService.block(args.getOrNull(1).orEmpty())
193219
if (record == null) {
@@ -273,6 +299,7 @@ internal object BukkitCommandRegistrar {
273299

274300
fun register(command: Command) {
275301
commandMap()?.register(command.name.lowercase(), command)
302+
syncCommands()
276303
}
277304

278305
private fun commandMap(): CommandMap? {
@@ -295,6 +322,15 @@ internal object BukkitCommandRegistrar {
295322
}
296323
throw NoSuchFieldException("commandMap")
297324
}
325+
326+
private fun syncCommands() {
327+
runCatching {
328+
val method = Bukkit.getServer().javaClass.methods.firstOrNull {
329+
it.name == "syncCommands" && it.parameterCount == 0
330+
} ?: return
331+
method.invoke(Bukkit.getServer())
332+
}
333+
}
298334
}
299335

300336
internal class MatrixRoutingCommand(
@@ -320,4 +356,3 @@ internal class MatrixRoutingCommand(
320356
return tabHandler(sender, alias, args).toMutableList()
321357
}
322358
}
323-

src/main/kotlin/com/y54895/matrixstorage/model/StorageModels.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import java.io.ByteArrayOutputStream
1212
import java.io.IOException
1313
import java.util.Base64
1414
import java.util.UUID
15+
import com.y54895.matrixlib.api.economy.MatrixCurrencyPrice
1516

1617
enum class PlacementSource {
1718
MINECRAFT,
@@ -80,7 +81,22 @@ data class PlayerWarehouseProfile(
8081
val ownerId: UUID,
8182
var ownerName: String,
8283
var warehouseContents: Array<ItemStack?>,
83-
var pendingContents: Array<ItemStack?>
84+
var pendingContents: Array<ItemStack?>,
85+
var unlockedWarehouseSlots: Int = 0,
86+
var unlockedMailboxSlots: Int = 0
87+
)
88+
89+
enum class UnlockTarget {
90+
WAREHOUSE,
91+
MAILBOX
92+
}
93+
94+
data class SlotUnlockRule(
95+
val id: String,
96+
val target: UnlockTarget,
97+
val slots: Int,
98+
val conditions: List<String> = emptyList(),
99+
val prices: List<MatrixCurrencyPrice> = emptyList()
84100
)
85101

86102
data class BlockWarehouseRecord(
@@ -153,7 +169,9 @@ data class SnapshotWarehouseProfile(
153169
val ownerId: String,
154170
val ownerName: String,
155171
val warehouseContents: String,
156-
val pendingContents: String
172+
val pendingContents: String,
173+
val unlockedWarehouseSlots: Int = 0,
174+
val unlockedMailboxSlots: Int = 0
157175
)
158176

159177
data class SnapshotBlockWarehouse(
@@ -179,7 +197,7 @@ data class SnapshotBlockWarehouse(
179197
)
180198

181199
data class StorageSnapshot(
182-
val version: Int = 1,
200+
val version: Int = 2,
183201
val mailbox: List<SnapshotMailboxMessage> = emptyList(),
184202
val warehouseProfiles: List<SnapshotWarehouseProfile> = emptyList(),
185203
val blockWarehouses: List<SnapshotBlockWarehouse> = emptyList()
@@ -234,4 +252,3 @@ object InventoryCodec {
234252
}
235253
}
236254
}
237-

0 commit comments

Comments
 (0)