Skip to content

Commit

Permalink
/item give completions and formatting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
trainb0y committed Jun 21, 2022
1 parent 80f1010 commit f43cee2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main/kotlin/io/github/hydrazinemc/hydrazine/Hydrazine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class Hydrazine : JavaPlugin() {
StarshipDebugCommands(),
CustomItemCommands()
).forEach { commandManager.registerCommand(it) }
commandManager.commandCompletions.registerCompletion("customitems"
) { CustomItems.all.keys }

// Reload the config
saveDefaultConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ object CustomItems {
*/
operator fun get(name: String?): CustomItem? = items[name]

/**
* The registered custom items
*/ // id rather not expose items itself
val all: Map<String, CustomItem>
get() = items.toMap()


/**
* Load custom items from the config file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package io.github.hydrazinemc.hydrazine.customitems.commands

import co.aikar.commands.BaseCommand
import co.aikar.commands.annotation.CommandAlias
import co.aikar.commands.annotation.CommandCompletion
import co.aikar.commands.annotation.CommandPermission
import co.aikar.commands.annotation.Default
import co.aikar.commands.annotation.Description
import co.aikar.commands.annotation.Optional
import co.aikar.commands.annotation.Subcommand
import io.github.hydrazinemc.hydrazine.customitems.CustomItems
import io.github.hydrazinemc.hydrazine.customitems.customItem
Expand All @@ -23,13 +26,18 @@ class CustomItemCommands : BaseCommand() {
@Subcommand("give")
@Description("Get a custom item")
@CommandPermission("hydrazine.customitems.give")
fun onGive(sender: Player, id: String, count: Int = 1, target: Player = sender) {
@CommandCompletion("@customitems")
fun onGive(
sender: Player,
id: String,
@Default("1") count: Int,
@Optional target: Player = sender) {
val item = CustomItems[id] ?: run {
sender.sendRichMessage("<red>No custom item with the id '$id' found.")
return
}
target.inventory.addItem(item.getItem(count))
sender.sendRichMessage("Gave <b>$count</b> of ${item.name} to ${target.name}.")
sender.sendRichMessage("Gave <b>$count</b> of ${item.name}<reset> to ${target.name}.")
}

/**
Expand Down

0 comments on commit f43cee2

Please sign in to comment.