mirror of
https://github.com/Auxilor/EcoJobs.git
synced 2025-12-21 16:09:18 +00:00
added "all" args
Within reset command, you can now use "all" as player or job. Added new lang messages accordingly.
This commit is contained in:
@@ -10,6 +10,7 @@ import com.willfp.ecojobs.api.resetJob
|
|||||||
import com.willfp.ecojobs.jobs.Jobs
|
import com.willfp.ecojobs.jobs.Jobs
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
|
import org.bukkit.util.StringUtil
|
||||||
|
|
||||||
class CommandReset(plugin: EcoPlugin) : Subcommand(plugin, "reset", "ecojobs.command.reset", false) {
|
class CommandReset(plugin: EcoPlugin) : Subcommand(plugin, "reset", "ecojobs.command.reset", false) {
|
||||||
override fun onExecute(sender: CommandSender, args: List<String>) {
|
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||||
@@ -24,16 +25,68 @@ class CommandReset(plugin: EcoPlugin) : Subcommand(plugin, "reset", "ecojobs.com
|
|||||||
}
|
}
|
||||||
|
|
||||||
val playerName = args[0]
|
val playerName = args[0]
|
||||||
|
val jobName = args[1]
|
||||||
|
|
||||||
|
// Reset all jobs for all players
|
||||||
|
if (playerName.equals("all", ignoreCase = true) && jobName.equals("all", ignoreCase = true)) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach { player ->
|
||||||
|
Jobs.values().forEach { job ->
|
||||||
|
if (player.hasJob(job)) {
|
||||||
|
player.forceLeaveJob(job)
|
||||||
|
player.resetJob(job)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sender.sendMessage(plugin.langYml.getMessage("reset-all-players-all-jobs"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset a specific job for all players
|
||||||
|
if (playerName.equals("all", ignoreCase = true)) {
|
||||||
|
val job = Jobs.getByID(jobName)
|
||||||
|
if (job == null) {
|
||||||
|
sender.sendMessage(plugin.langYml.getMessage("invalid-job"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Bukkit.getOnlinePlayers().forEach { player ->
|
||||||
|
if (player.hasJob(job)) {
|
||||||
|
player.forceLeaveJob(job)
|
||||||
|
player.resetJob(job)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(
|
||||||
|
plugin.langYml.getMessage("reset-all-players")
|
||||||
|
.replace("%job%", job.name)
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset all jobs for a specific player
|
||||||
val player = Bukkit.getPlayer(playerName)
|
val player = Bukkit.getPlayer(playerName)
|
||||||
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("invalid-player"))
|
sender.sendMessage(plugin.langYml.getMessage("invalid-player"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val job = Jobs.getByID(args[1])
|
if (jobName.equals("all", ignoreCase = true)) {
|
||||||
|
Jobs.values().forEach { job ->
|
||||||
|
if (player.hasJob(job)) {
|
||||||
|
player.forceLeaveJob(job)
|
||||||
|
player.resetJob(job)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(
|
||||||
|
plugin.langYml.getMessage("reset-all-jobs")
|
||||||
|
.replace("%player%", player.savedDisplayName)
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset a specific job for a specific player
|
||||||
|
val job = Jobs.getByID(jobName)
|
||||||
if (job == null) {
|
if (job == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("invalid-job"))
|
sender.sendMessage(plugin.langYml.getMessage("invalid-job"))
|
||||||
return
|
return
|
||||||
@@ -55,12 +108,23 @@ class CommandReset(plugin: EcoPlugin) : Subcommand(plugin, "reset", "ecojobs.com
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun tabComplete(sender: CommandSender, args: List<String>): List<String> {
|
override fun tabComplete(sender: CommandSender, args: List<String>): List<String> {
|
||||||
|
val completions = mutableListOf<String>()
|
||||||
if (args.size == 1) {
|
if (args.size == 1) {
|
||||||
return Bukkit.getOnlinePlayers().map { it.name }
|
StringUtil.copyPartialMatches(
|
||||||
|
args[0],
|
||||||
|
listOf("all") union Bukkit.getOnlinePlayers().map { player -> player.name },
|
||||||
|
completions
|
||||||
|
)
|
||||||
|
return completions
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 2) {
|
if (args.size == 2) {
|
||||||
return Jobs.values().map { it.id }
|
StringUtil.copyPartialMatches(
|
||||||
|
args[1],
|
||||||
|
listOf("all") union Jobs.values().map { it.id },
|
||||||
|
completions
|
||||||
|
)
|
||||||
|
return completions
|
||||||
}
|
}
|
||||||
|
|
||||||
return emptyList()
|
return emptyList()
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ messages:
|
|||||||
needs-player: "&cYou must specify a player!"
|
needs-player: "&cYou must specify a player!"
|
||||||
gave-xp: "&fYou have given &a%xp% &fXP to %player%&f's %job%&f!"
|
gave-xp: "&fYou have given &a%xp% &fXP to %player%&f's %job%&f!"
|
||||||
reset-xp: "&fYou have reset %player%&f's %job%&f XP!"
|
reset-xp: "&fYou have reset %player%&f's %job%&f XP!"
|
||||||
|
reset-all-players: "&fYou have reset all players' %job%&f XP!"
|
||||||
|
reset-all-jobs: "&fYou have reset %player%&f's XP for all jobs!"
|
||||||
|
reset-all-players-all-jobs: "&fYou have reset all players' XP for all jobs!"
|
||||||
needs-job: "&cYou must specify a job!"
|
needs-job: "&cYou must specify a job!"
|
||||||
need-amount: "&cYou must specify a amount!"
|
need-amount: "&cYou must specify a amount!"
|
||||||
invalid-player: "&cInvalid player!"
|
invalid-player: "&cInvalid player!"
|
||||||
|
|||||||
Reference in New Issue
Block a user