11package com.y54895.matrixstorage.command
22
3+ import com.y54895.matrixlib.api.economy.MatrixEconomy
34import com.y54895.matrixstorage.MatrixStorageMessages
45import com.y54895.matrixstorage.MatrixStoragePlatform
6+ import com.y54895.matrixstorage.model.UnlockTarget
57import com.y54895.matrixstorage.service.BlockWarehouseService
68import com.y54895.matrixstorage.service.MailboxService
9+ import com.y54895.matrixstorage.service.SlotUnlockConfig
10+ import com.y54895.matrixstorage.service.SlotUnlockService
711import com.y54895.matrixstorage.service.StorageConfig
812import com.y54895.matrixstorage.service.StoragePersistenceService
913import 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
300336internal class MatrixRoutingCommand (
@@ -320,4 +356,3 @@ internal class MatrixRoutingCommand(
320356 return tabHandler(sender, alias, args).toMutableList()
321357 }
322358}
323-
0 commit comments