Skip to content

Commit

Permalink
Merge pull request #32 from AtriusX/fix/get-key-console
Browse files Browse the repository at this point in the history
Update command to handle /waystones getkey from console.
  • Loading branch information
AtriusX authored Jun 29, 2021
2 parents c25b89c + cc83e5c commit a7687af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/main/kotlin/xyz/atrius/waystones/commands/GetKeyCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import xyz.atrius.waystones.utility.message

object GetKeyCommand : SimpleCommand("getkey", "gk", "key", "k") {
// Calculate Player and Amount Values
private fun getPlayerAndAmount(default: Player, first: String?, second: String?): Pair<Player, Int> {
private fun getPlayerAndAmount(default: Player?, first: String?, second: String?): Pair<Player?, Int> {
val player = if (first != null)
Bukkit.getPlayer(first) ?: default else default
val amount = second?.toIntOrNull() ?: first?.toIntOrNull() ?: 1
Expand All @@ -19,18 +19,17 @@ object GetKeyCommand : SimpleCommand("getkey", "gk", "key", "k") {
override fun execute(sender: CommandSender, args: Array<String>) {
// Set Amount and Player to give WarpKeys to
val (player, amount) = getPlayerAndAmount(
sender as Player,
sender as? Player,
args.getOrNull(0),
args.getOrNull(1)
)
// Return if selected player does not exist
player ?: return sender.message(localization["command-bad-sender", "console"])
// Check Permissions
if (!sender.hasPermission("waystones.getkey.self")
|| !sender.hasPermission("waystones.getkey.all")
&& sender != player
) {
sender.message(localization["command-no-permission"])
return
}
) return sender.message(localization["command-no-permission"])
// Add WarpKey(s) to Player inventory
player.inventory.addItem(defaultWarpKey(amount))
// Inform Player of given WarpKey
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locale-en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ warp-wait: "&2&lWarping to {0} in {1} {1,choice,1#second|1<seconds}"
key-name: "&6Waystone Key"
key-lore: "&5Waystone: [&kUNKNOWN&5]"
world-jump-disabled: "&cDimensional interference has blocked your path..."
command-bad-sender: "&cCannot run this command through {0}."

0 comments on commit a7687af

Please sign in to comment.