-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: swap to Brigadier command-logic
- Loading branch information
Showing
2 changed files
with
29 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,51 @@ | ||
package com.mineinabyss.packy | ||
|
||
import com.github.shynixn.mccoroutine.bukkit.asyncDispatcher | ||
import com.github.shynixn.mccoroutine.bukkit.launch | ||
import com.mineinabyss.guiy.inventory.guiy | ||
import com.mineinabyss.idofront.commands.arguments.genericArg | ||
import com.mineinabyss.idofront.commands.arguments.optionArg | ||
import com.mineinabyss.idofront.commands.execution.IdofrontCommandExecutor | ||
import com.mineinabyss.idofront.commands.extensions.actions.ensureSenderIsPlayer | ||
import com.mineinabyss.idofront.commands.extensions.actions.playerAction | ||
import com.mineinabyss.idofront.commands.brigadier.commands | ||
import com.mineinabyss.idofront.messaging.error | ||
import com.mineinabyss.idofront.messaging.info | ||
import com.mineinabyss.idofront.messaging.success | ||
import com.mineinabyss.packy.components.packyData | ||
import com.mineinabyss.packy.config.PackyTemplate | ||
import com.mineinabyss.packy.config.packy | ||
import com.mineinabyss.packy.menus.picker.PackyMainMenu | ||
import org.bukkit.command.Command | ||
import org.bukkit.command.CommandSender | ||
import org.bukkit.command.TabCompleter | ||
import org.bukkit.entity.Player | ||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes | ||
|
||
class PackyCommands : IdofrontCommandExecutor(), TabCompleter { | ||
override val commands = commands(packy.plugin) { | ||
"packy" { | ||
"github" { | ||
"fetch" { | ||
val template: PackyTemplate by genericArg(parseFunction = { passed -> | ||
packy.templates.filter { it.value.githubDownload != null }[passed]!! | ||
}) | ||
action { | ||
packy.plugin.launch(packy.plugin.asyncDispatcher) { | ||
val templates = packy.templates.filter { it.value.githubDownload?.key() == template.githubDownload!!.key() }.values.sortedBy { it.id }.toTypedArray() | ||
sender.info("Downloading template ${template.id}...") | ||
PackyDownloader.updateGithubTemplate(*templates) | ||
sender.success("Downloaded template ${template.id}!") | ||
} | ||
object PackyCommands { | ||
fun registerCommands() { | ||
packy.plugin.commands { | ||
"packy" { | ||
"reload" { | ||
executes { | ||
packy.plugin.createPackyContext() | ||
sender.success("Packy has been reloaded!") | ||
} | ||
} | ||
} | ||
"reload" { | ||
action { | ||
packy.plugin.createPackyContext() | ||
sender.success("Packy has been reloaded!") | ||
} | ||
} | ||
"send" { | ||
playerAction { | ||
packy.plugin.launch { | ||
PackyServer.sendPack(player) | ||
sender.success("Sent pack to ${player.name}") | ||
"menu" { | ||
playerExecutes { | ||
guiy { PackyMainMenu(player) } | ||
} | ||
} | ||
} | ||
"gui" { | ||
playerAction { | ||
guiy { PackyMainMenu(player) } | ||
} | ||
} | ||
"server" { | ||
val state: String by optionArg(listOf("start", "stop")) | ||
action { | ||
when { | ||
state == "start" && PackyServer.packServer != null -> { | ||
PackyServer.startServer() | ||
sender.success("PackyServer started on ${packy.config.server.ip}:${packy.config.server.port}...") | ||
} | ||
else -> { | ||
PackyServer.stopServer() | ||
sender.error("PackyServer stopped...") | ||
"send" { | ||
val players by ArgumentTypes.players() | ||
executes { | ||
packy.plugin.launch { | ||
players().forEach { | ||
PackyServer.sendPack(it) | ||
sender.success("Sent pack to ${it.name}") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
"bypass" { | ||
ensureSenderIsPlayer() | ||
action { | ||
val player = sender as Player | ||
player.packyData.bypassForced = !player.packyData.bypassForced | ||
when (player.packyData.bypassForced) { | ||
true -> sender.success("Bypassing forced pack") | ||
else -> sender.error("No longer bypassing forced pack") | ||
"bypass" { | ||
playerExecutes { | ||
player.packyData.bypassForced = !player.packyData.bypassForced | ||
when (player.packyData.bypassForced) { | ||
true -> sender.success("Bypassing forced pack") | ||
else -> sender.error("No longer bypassing forced pack") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun onTabComplete( | ||
sender: CommandSender, | ||
command: Command, | ||
alias: String, | ||
args: Array<out String> | ||
): List<String> { | ||
return if (command.name == "packy") { | ||
when (args.size) { | ||
1 -> listOf("reload", "gui", "server", "send", "github").filter { it.startsWith(args[0]) } | ||
2 -> when(args[0]) { | ||
"server" -> listOf("start", "stop") | ||
"send", "gui", "bypass" -> packy.plugin.server.onlinePlayers.map { it.name } | ||
"github" -> listOf("fetch") | ||
else -> listOf() | ||
}.filter { it.startsWith(args[1]) } | ||
3 -> when(args[0]) { | ||
"github" -> packy.templates.entries.filter { it.value.githubDownload != null }.map { it.key } | ||
else -> listOf() | ||
}.filter { it.startsWith(args[2]) } | ||
else -> listOf() | ||
} | ||
} else listOf() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters