Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update command to handle /waystones getkey from console. #32

Merged
merged 1 commit into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}."