From 88d118cdd76dfd8f7efbf6456f0c1f56f214b7a0 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 21 Nov 2022 11:41:46 +0000 Subject: [PATCH] Added /jobs --- build.gradle | 2 +- .../willfp/ecojobs/commands/CommandJobs.kt | 41 +++++++++++++++++-- .../willfp/ecojobs/commands/CommandJoin.kt | 1 - 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 318518c..0b398a6 100644 --- a/build.gradle +++ b/build.gradle @@ -47,7 +47,7 @@ allprojects { } dependencies { - compileOnly 'com.willfp:eco:6.45.0' + compileOnly 'com.willfp:eco:6.46.0' implementation 'com.willfp:libreforge:3.120.0' implementation 'com.willfp:ecomponent:1.0.0' implementation 'org.joml:joml:1.10.4' diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/commands/CommandJobs.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/commands/CommandJobs.kt index 9d9c815..3504f9b 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/commands/CommandJobs.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/commands/CommandJobs.kt @@ -2,9 +2,11 @@ package com.willfp.ecojobs.commands import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.command.impl.PluginCommand +import com.willfp.ecojobs.jobs.Jobs import com.willfp.ecojobs.jobs.JobsGUI -import org.bukkit.command.CommandSender +import com.willfp.ecojobs.jobs.hasJob import org.bukkit.entity.Player +import org.bukkit.util.StringUtil class CommandJobs(plugin: EcoPlugin) : PluginCommand(plugin, "jobs", "ecojobs.command.jobs", true) { init { @@ -12,8 +14,39 @@ class CommandJobs(plugin: EcoPlugin) : PluginCommand(plugin, "jobs", "ecojobs.co .addSubcommand(CommandLeave(plugin)) } - override fun onExecute(player: CommandSender, args: List) { - player as Player - JobsGUI.open(player) + override fun onExecute(player: Player, args: List) { + if (args.isEmpty()) { + JobsGUI.open(player) + return + } + + val id = args[0].lowercase() + val job = Jobs.getByID(id) + + if (job == null) { + player.sendMessage(plugin.langYml.getMessage("invalid-job")) + return + } + + job.levelGUI.open(player) + } + + override fun tabComplete(player: Player, args: List): List { + val completions = mutableListOf() + + if (args.isEmpty()) { + return Jobs.values().filter { player.hasJob(it) }.map { it.id } + } + + if (args.size == 1) { + StringUtil.copyPartialMatches( + args[0], + Jobs.values().filter { player.hasJob(it) }.map { it.id }, + completions + ) + return completions + } + + return emptyList() } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/commands/CommandJoin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/commands/CommandJoin.kt index 4bb1992..4806df2 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/commands/CommandJoin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/commands/CommandJoin.kt @@ -52,7 +52,6 @@ class CommandJoin(plugin: EcoPlugin) : Subcommand(plugin, "join", "ecojobs.comma val completions = mutableListOf() if (args.isEmpty()) { - // Currently, this case is not ever reached return Jobs.values().filter { sender.hasJob(it) }.map { it.id } }