@@ -23,9 +23,14 @@ import dev.jorel.commandapi.CommandAPICommand
2323import dev.jorel.commandapi.arguments.ArgumentSuggestions
2424import dev.jorel.commandapi.executors.CommandExecutor
2525import dev.jorel.commandapi.kotlindsl.*
26+ import net.kyori.adventure.text.format.NamedTextColor
2627import org.bukkit.entity.Player
2728import ru.endlesscode.mimic.impl.mimic.MimicItemsRegistry
29+ import ru.endlesscode.mimic.internal.append
30+ import ru.endlesscode.mimic.internal.appendLine
31+ import ru.endlesscode.mimic.internal.text
2832import ru.endlesscode.mimic.items.BukkitItemsRegistry
33+ import ru.endlesscode.mimic.items.unwrap
2934
3035/* *
3136 * Commands to deal with items registries
@@ -59,15 +64,15 @@ internal fun CommandAPICommand.itemsSubcommand(itemsRegistry: BukkitItemsRegistr
5964 playerExecutor { sender, args ->
6065 val item: String by args
6166 val isSame = itemsRegistry.isSameItem(sender.inventory.itemInMainHand, item)
62- sender.send( " &6Item in hand and '$item ' %s same." .format(if (isSame) " are" else " aren't" ))
67+ sender.sendMessage(successText( " Item in hand and '$item ' %s same." .format(if (isSame) " are" else " aren't" ) ))
6368 }
6469 }
6570
6671 subcommand(" id" ) {
6772 withShortDescription(" Prints ID of item in hand" )
6873 playerExecutor { sender, _ ->
6974 val id = itemsRegistry.getItemId(sender.inventory.itemInMainHand)
70- sender.send( " &6Id of item in hand is '$id '" )
75+ sender.sendMessage(successText( " Id of item in hand is '$id '" ) )
7176 }
7277 }
7378
@@ -77,48 +82,51 @@ internal fun CommandAPICommand.itemsSubcommand(itemsRegistry: BukkitItemsRegistr
7782 anyExecutor { sender, args ->
7883 val item: String by args
7984 val itemExists = itemsRegistry.isItemExists(item)
80- sender.send( " &6Item with id '$item '%s exists" .format(if (itemExists) " " else " isn't" ))
85+ sender.sendMessage(successText( " Item with id '$item '%s exists" .format(if (itemExists) " " else " isn't" ) ))
8186 }
8287 }
8388}
8489
8590// We can use only greedy string if we need to allow colons because it requires quoting in non-greedy strings.
8691// https://github.com/Mojang/brigadier/blob/cf754c4ef654160dca946889c11941634c5db3d5/src/main/java/com/mojang/brigadier/StringReader.java#L169
87- private fun CommandAPICommand.itemArgument (itemsRegistry : BukkitItemsRegistry ) = greedyStringArgument(ITEM ) {
88- replaceSuggestions(ArgumentSuggestions .stringCollection { itemsRegistry .knownIds })
92+ private fun CommandAPICommand.itemArgument (itemRegistry : BukkitItemsRegistry ) = greedyStringArgument(ITEM ) {
93+ replaceSuggestions(ArgumentSuggestions .stringCollection { itemRegistry .knownIds })
8994}
9095
91- private fun infoExecutor (itemsRegistry : BukkitItemsRegistry ) = CommandExecutor { sender, _ ->
92- val registries = (itemsRegistry as ? MimicItemsRegistry )?.providers
93- .orEmpty()
94- .map { it.provider }
95- .map { " &f${it.id} : &7${it.knownIds.size} " }
96+ private fun infoExecutor (itemRegistry : BukkitItemsRegistry ) = CommandExecutor { sender, _ ->
97+ val providers = (itemRegistry.unwrap() as ? MimicItemsRegistry )?.providers.orEmpty().map { it.provider }
9698
97- sender.send(
98- " &3Items Service: &7${itemsRegistry.id} " ,
99- " &3Known IDs amount: &7${itemsRegistry.knownIds.size} "
100- )
101- sender.send(registries)
99+ val message = text {
100+ appendStats(
101+ " Item Registry" to itemRegistry.id,
102+ " Known IDs amount" to itemRegistry.knownIds.size.toString(),
103+ )
104+
105+ for (provider in providers) {
106+ append(" ${provider.id} : " , NamedTextColor .WHITE )
107+ appendLine(provider.knownIds.size.toString(), NamedTextColor .GRAY )
108+ }
109+ }
110+ sender.sendMessage(message)
102111}
103112
104- private fun giveExecutor (itemsRegistry : BukkitItemsRegistry ) = CommandExecutor { sender, args ->
113+ private fun giveExecutor (itemRegistry : BukkitItemsRegistry ) = CommandExecutor { sender, args ->
105114 val target: Player by args
106115 val amount = args.getOrDefaultUnchecked(AMOUNT , 1 )
107116 // We can use only one greedy string at the end, so we read item and its payload from the same argument
108117 val itemParts = args.getRaw(ITEM ).orEmpty().split(" " , limit = 2 )
109118 val item = itemParts.first()
110119 val payload = itemParts.getOrNull(1 )
111120
112- val itemStack = itemsRegistry .getItem(item, payload, amount)
121+ val itemStack = itemRegistry .getItem(item, payload, amount)
113122 if (itemStack != null ) {
114123 target.inventory.addItem(itemStack)
115- sender.send( " &6Gave ${itemStack.amount} [$item ] to ${target.name} ." )
124+ sender.sendMessage(successText( " Gave ${itemStack.amount} [$item ] to ${target.name} ." ) )
116125 } else {
117- sender.send( " &cUnknown item '$item '. " )
126+ sender.sendMessage(errorText( " Unknown item '$item '" ) )
118127 }
119128}
120129
121130private const val TARGET = " target"
122131private const val ITEM = " item"
123132private const val AMOUNT = " amount"
124- private const val PAYLOAD = " payload"
0 commit comments