From e11ed6ee61c0490bf8cb5ffc41601166eddf846c Mon Sep 17 00:00:00 2001 From: andyksaw Date: Fri, 29 Nov 2024 23:31:39 +0900 Subject: [PATCH] Convert remaining commands --- ...kotlin-compiler-5100213468630583341.salive | 0 .../pcbridge/paper/Container.kt | 49 +++- .../pcbridge/paper/PermissionNode.kt | 9 +- .../projectcitybuild/pcbridge/paper/Plugin.kt | 1 - .../remoteconfig/commands/ConfigCommand.kt | 1 - .../support/brigadier/BrigadierCommand.kt | 1 - .../brigadier/CommandExceptionHandler.kt | 1 - .../extensions/ArgumentBuilderExtensions.kt | 4 +- .../extensions/CommandsExtensions.kt | 1 - .../building/commands/ItemNameCommand.kt | 3 +- .../building/commands/NightVisionCommand.kt | 3 +- .../features/builds/commands/BuildCommand.kt | 1 - .../features/builds/commands/BuildsCommand.kt | 1 - .../commands/builds/BuildCreateCommand.kt | 1 - .../commands/builds/BuildDeleteCommand.kt | 1 - .../commands/builds/BuildEditCommand.kt | 1 - .../commands/builds/BuildListCommand.kt | 1 - .../commands/builds/BuildMoveCommand.kt | 1 - .../builds/commands/builds/BuildSetCommand.kt | 1 - .../commands/builds/BuildUnvoteCommand.kt | 1 - .../commands/builds/BuildVoteCommand.kt | 1 - .../features/groups/commands/SyncCommand.kt | 1 - .../invisframes/commands/InvisFrameCommand.kt | 3 +- .../features/register/commands/CodeCommand.kt | 1 - .../register/commands/RegisterCommand.kt | 1 - .../staffchat/commands/StaffChatCommand.kt | 1 - .../features/warps/commands/WarpCommand.kt | 1 - .../features/warps/commands/WarpsCommand.kt | 220 ++---------------- .../warps/commands/warps/WarpCreateCommand.kt | 134 ++++------- .../warps/commands/warps/WarpDeleteCommand.kt | 74 +++--- .../warps/commands/warps/WarpListCommand.kt | 115 +++++---- .../warps/commands/warps/WarpMoveCommand.kt | 94 ++++---- .../warps/commands/warps/WarpReloadCommand.kt | 34 +++ .../warps/commands/warps/WarpRenameCommand.kt | 84 ++++--- 34 files changed, 339 insertions(+), 507 deletions(-) create mode 100644 .kotlin/sessions/kotlin-compiler-5100213468630583341.salive create mode 100644 pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpReloadCommand.kt diff --git a/.kotlin/sessions/kotlin-compiler-5100213468630583341.salive b/.kotlin/sessions/kotlin-compiler-5100213468630583341.salive new file mode 100644 index 000000000..e69de29bb diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Container.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Container.kt index e5bceaa4d..b8f8208cf 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Container.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Container.kt @@ -66,7 +66,6 @@ import com.projectcitybuild.pcbridge.paper.features.building.commands.ItemNameCo import com.projectcitybuild.pcbridge.paper.integrations.DynmapIntegration import com.projectcitybuild.pcbridge.paper.integrations.EssentialsIntegration import com.projectcitybuild.pcbridge.paper.integrations.LuckPermsIntegration -import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotCommandRegistry import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotEventBroadcaster import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotListenerRegistry import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotNamespace @@ -75,6 +74,12 @@ import com.projectcitybuild.pcbridge.paper.architecture.listeners.ExceptionListe import com.projectcitybuild.pcbridge.paper.features.builds.commands.builds.BuildEditCommand import com.projectcitybuild.pcbridge.paper.features.builds.commands.builds.BuildSetCommand import com.projectcitybuild.pcbridge.paper.features.builds.commands.builds.BuildUnvoteCommand +import com.projectcitybuild.pcbridge.paper.features.warps.commands.warps.WarpCreateCommand +import com.projectcitybuild.pcbridge.paper.features.warps.commands.warps.WarpDeleteCommand +import com.projectcitybuild.pcbridge.paper.features.warps.commands.warps.WarpListCommand +import com.projectcitybuild.pcbridge.paper.features.warps.commands.warps.WarpMoveCommand +import com.projectcitybuild.pcbridge.paper.features.warps.commands.warps.WarpReloadCommand +import com.projectcitybuild.pcbridge.paper.features.warps.commands.warps.WarpRenameCommand import com.projectcitybuild.pcbridge.webserver.HttpServer import com.projectcitybuild.pcbridge.webserver.HttpServerConfig import io.github.reactivecircus.cache4k.Cache @@ -131,13 +136,6 @@ private fun Module.spigot(plugin: JavaPlugin) { ) } - single { - SpigotCommandRegistry( - plugin = get(), - sentry = get(), - ) - } - single { SpigotListenerRegistry( plugin = get(), @@ -405,6 +403,7 @@ private fun Module.warps() { factory { WarpCommand( + plugin = get(), warpRepository = get(), server = get(), ) @@ -412,10 +411,33 @@ private fun Module.warps() { factory { WarpsCommand( - warpRepository = get(), - remoteConfig = get(), - server = get(), - time = get(), + createCommand = WarpCreateCommand( + plugin = get(), + warpRepository = get(), + server = get(), + ), + deleteCommand = WarpDeleteCommand( + plugin = get(), + warpRepository = get(), + server = get(), + ), + listCommand = WarpListCommand( + plugin = get(), + warpRepository = get(), + remoteConfig = get(), + ), + moveCommand = WarpMoveCommand( + plugin = get(), + warpRepository = get(), + ), + reloadCommand = WarpReloadCommand( + plugin = get(), + warpRepository = get(), + ), + renameCommand = WarpRenameCommand( + plugin = get(), + warpRepository = get(), + ), ) } } @@ -517,6 +539,7 @@ private fun Module.bans() { private fun Module.invisFrames() { factory { InvisFrameCommand( + plugin = get(), spigotNamespace = get(), ) } @@ -599,11 +622,13 @@ private fun Module.chat() { private fun Module.register() { factory { RegisterCommand( + plugin = get(), registerHttpService = get().register, ) } factory { CodeCommand( + plugin = get(), registerHttpService = get().register, ) } diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/PermissionNode.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/PermissionNode.kt index 4db6d855c..cf5dc3c9b 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/PermissionNode.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/PermissionNode.kt @@ -11,13 +11,13 @@ enum class PermissionNode(val node: String) { BUILDS_VOTE("pcbridge.builds.vote"), // Can toggle nightvision mode - BUILD_NIGHT_VISION("pcbridge.build.nightvision"), + BUILDING_NIGHT_VISION("pcbridge.build.nightvision"), // Can rename an item via a command - BUILD_ITEM_RENAME("pcbridge.items.rename"), + BUILDING_ITEM_RENAME("pcbridge.items.rename"), // Can get an invisible item frame via a command - BUILD_INVIS_FRAME("pcbridge.build.invisframe"), + BUILDING_INVIS_FRAME("pcbridge.build.invisframe"), // Can send and receive staff messages STAFF_CHANNEL("pcbridge.chat.staff_channel"), @@ -30,4 +30,7 @@ enum class PermissionNode(val node: String) { // Can teleport to a warp WARP_TELEPORT("pcbridge.warp.teleport"), + + // Can create, edit or delete warps + WARP_MANAGE("pcbridge.warp.manage"), } \ No newline at end of file diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Plugin.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Plugin.kt index 87c947e6f..26170cf76 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Plugin.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Plugin.kt @@ -98,7 +98,6 @@ private class Lifecycle : KoinComponent { remoteConfig.fetch() - @Suppress("UnstableApiUsage") // TODO: inject lifecycle manager instead get() .lifecycleManager diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/libs/remoteconfig/commands/ConfigCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/libs/remoteconfig/commands/ConfigCommand.kt index 5d45a77da..a1e9ca3de 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/libs/remoteconfig/commands/ConfigCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/libs/remoteconfig/commands/ConfigCommand.kt @@ -13,7 +13,6 @@ import io.papermc.paper.command.brigadier.Commands import net.kyori.adventure.text.minimessage.MiniMessage import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class ConfigCommand( private val plugin: Plugin, private val remoteConfig: RemoteConfig, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/BrigadierCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/BrigadierCommand.kt index b829a40c8..12d6dbf0c 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/BrigadierCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/BrigadierCommand.kt @@ -7,7 +7,6 @@ import io.papermc.paper.command.brigadier.CommandSourceStack * Represents either a command or subcommand that can be * registered with Brigadier */ -@Suppress("UnstableApiUsage") interface BrigadierCommand { fun buildLiteral(): LiteralCommandNode } \ No newline at end of file diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/CommandExceptionHandler.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/CommandExceptionHandler.kt index 069e2e6ad..63f9d6c03 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/CommandExceptionHandler.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/CommandExceptionHandler.kt @@ -6,7 +6,6 @@ import io.papermc.paper.command.brigadier.CommandSourceStack import net.kyori.adventure.text.minimessage.MiniMessage import org.bukkit.command.CommandSender -@Suppress("UnstableApiUsage") suspend fun traceCommand( context: CommandContext, block: suspend (CommandContext) -> Unit, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/extensions/ArgumentBuilderExtensions.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/extensions/ArgumentBuilderExtensions.kt index cc198a3fa..712b6e6ba 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/extensions/ArgumentBuilderExtensions.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/extensions/ArgumentBuilderExtensions.kt @@ -50,14 +50,12 @@ fun LiteralArgumentBuilder.executesSuspending( } } -@Suppress("UnstableApiUsage") fun LiteralArgumentBuilder.then( command: BrigadierCommand, ): LiteralArgumentBuilder { return then(command.buildLiteral()) } -@Suppress("UnstableApiUsage") fun LiteralArgumentBuilder.requiresPermission( permission: PermissionNode, ): LiteralArgumentBuilder { @@ -65,7 +63,7 @@ fun LiteralArgumentBuilder.requiresPermission( context.sender.hasPermission(permission.node) } } -@Suppress("UnstableApiUsage") + fun RequiredArgumentBuilder.requiresPermission( permission: PermissionNode, ): RequiredArgumentBuilder { diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/extensions/CommandsExtensions.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/extensions/CommandsExtensions.kt index 318c0c93c..e0a1c7c06 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/extensions/CommandsExtensions.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/extensions/CommandsExtensions.kt @@ -3,7 +3,6 @@ package com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions import com.projectcitybuild.pcbridge.paper.core.support.brigadier.BrigadierCommand import io.papermc.paper.command.brigadier.Commands -@Suppress("UnstableApiUsage") fun Commands.register(vararg commands: BrigadierCommand) = commands.forEach { register(it.buildLiteral()) } \ No newline at end of file diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/building/commands/ItemNameCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/building/commands/ItemNameCommand.kt index 394fe30ae..2af059669 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/building/commands/ItemNameCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/building/commands/ItemNameCommand.kt @@ -19,14 +19,13 @@ import org.bukkit.Material import org.bukkit.entity.Player import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class ItemNameCommand( private val plugin: Plugin, private val eventBroadcaster: SpigotEventBroadcaster, ) : BrigadierCommand { override fun buildLiteral(): LiteralCommandNode { return Commands.literal("itemname") - .requiresPermission(PermissionNode.BUILD_ITEM_RENAME) + .requiresPermission(PermissionNode.BUILDING_ITEM_RENAME) .then( Commands.argument("name", StringArgumentType.greedyString()) .executesSuspending(plugin, ::execute) diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/building/commands/NightVisionCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/building/commands/NightVisionCommand.kt index 54948128f..86f21248b 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/building/commands/NightVisionCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/building/commands/NightVisionCommand.kt @@ -18,13 +18,12 @@ import org.bukkit.plugin.Plugin import org.bukkit.potion.PotionEffect import org.bukkit.potion.PotionEffectType -@Suppress("UnstableApiUsage") class NightVisionCommand( private val plugin: Plugin, ) : BrigadierCommand { override fun buildLiteral(): LiteralCommandNode { return Commands.literal("nv") - .requiresPermission(PermissionNode.BUILD_NIGHT_VISION) + .requiresPermission(PermissionNode.BUILDING_NIGHT_VISION) .then( Commands.argument("enabled", OnOffArgument()) .executesSuspending(plugin, ::execute) diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/BuildCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/BuildCommand.kt index d8f192b83..ec9c1bdce 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/BuildCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/BuildCommand.kt @@ -24,7 +24,6 @@ import org.bukkit.entity.Player import org.bukkit.event.player.PlayerTeleportEvent import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class BuildCommand( private val plugin: Plugin, private val buildRepository: BuildRepository, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/BuildsCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/BuildsCommand.kt index c611666c5..5861e6a8c 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/BuildsCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/BuildsCommand.kt @@ -16,7 +16,6 @@ import com.projectcitybuild.pcbridge.paper.features.builds.commands.builds.Build import io.papermc.paper.command.brigadier.CommandSourceStack import io.papermc.paper.command.brigadier.Commands -@Suppress("UnstableApiUsage") class BuildsCommand( private val buildCreateCommand: BuildCreateCommand, private val buildDeleteCommand: BuildDeleteCommand, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildCreateCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildCreateCommand.kt index 1f0f28099..50e90ce77 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildCreateCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildCreateCommand.kt @@ -15,7 +15,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage import org.bukkit.entity.Player import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class BuildCreateCommand( private val plugin: Plugin, private val buildRepository: BuildRepository, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildDeleteCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildDeleteCommand.kt index 997c59df4..2223f1d7b 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildDeleteCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildDeleteCommand.kt @@ -17,7 +17,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage import org.bukkit.entity.Player import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class BuildDeleteCommand( private val plugin: Plugin, private val buildRepository: BuildRepository, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildEditCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildEditCommand.kt index ade1b2ada..f3cc82732 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildEditCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildEditCommand.kt @@ -17,7 +17,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage import org.bukkit.entity.Player import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class BuildEditCommand( private val plugin: Plugin, private val buildRepository: BuildRepository, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildListCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildListCommand.kt index 668c1c0f4..52705d101 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildListCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildListCommand.kt @@ -17,7 +17,6 @@ import org.bukkit.command.CommandSender import org.bukkit.plugin.Plugin import kotlin.math.ceil -@Suppress("UnstableApiUsage") class BuildListCommand( private val plugin: Plugin, private val buildRepository: BuildRepository, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildMoveCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildMoveCommand.kt index 600facb56..2738d445a 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildMoveCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildMoveCommand.kt @@ -17,7 +17,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage import org.bukkit.entity.Player import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class BuildMoveCommand( private val plugin: Plugin, private val buildRepository: BuildRepository, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildSetCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildSetCommand.kt index 0dc99f8ef..1888941e5 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildSetCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildSetCommand.kt @@ -18,7 +18,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage import org.bukkit.entity.Player import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class BuildSetCommand( private val plugin: Plugin, private val buildRepository: BuildRepository, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildUnvoteCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildUnvoteCommand.kt index f6b7417c4..e6f225772 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildUnvoteCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildUnvoteCommand.kt @@ -17,7 +17,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage import org.bukkit.entity.Player import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class BuildUnvoteCommand( private val plugin: Plugin, private val buildRepository: BuildRepository, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildVoteCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildVoteCommand.kt index 604a3d3e3..671d51a18 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildVoteCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/commands/builds/BuildVoteCommand.kt @@ -17,7 +17,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage import org.bukkit.entity.Player import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class BuildVoteCommand( private val plugin: Plugin, private val buildRepository: BuildRepository, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/groups/commands/SyncCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/groups/commands/SyncCommand.kt index 23209da2e..4929f1797 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/groups/commands/SyncCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/groups/commands/SyncCommand.kt @@ -16,7 +16,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage import org.bukkit.entity.Player import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class SyncCommand( private val plugin: Plugin, private val eventBroadcaster: SpigotEventBroadcaster, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/invisframes/commands/InvisFrameCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/invisframes/commands/InvisFrameCommand.kt index 7c95456d7..1558c0a43 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/invisframes/commands/InvisFrameCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/invisframes/commands/InvisFrameCommand.kt @@ -20,14 +20,13 @@ import org.bukkit.inventory.ItemStack import org.bukkit.persistence.PersistentDataType import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class InvisFrameCommand( private val plugin: Plugin, private val spigotNamespace: SpigotNamespace, ) : BrigadierCommand { override fun buildLiteral(): LiteralCommandNode { return Commands.literal("invisframe") - .requiresPermission(PermissionNode.BUILD_INVIS_FRAME) + .requiresPermission(PermissionNode.BUILDING_INVIS_FRAME) .then( Commands.literal("glowing") .executesSuspending(plugin, ::giveGlowing) diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/register/commands/CodeCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/register/commands/CodeCommand.kt index df319ea83..50e1768a2 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/register/commands/CodeCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/register/commands/CodeCommand.kt @@ -15,7 +15,6 @@ import net.kyori.adventure.text.format.NamedTextColor import org.bukkit.entity.Player import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class CodeCommand( private val plugin: Plugin, private val registerHttpService: RegisterHttpService, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/register/commands/RegisterCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/register/commands/RegisterCommand.kt index cb9ca411b..85f17a065 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/register/commands/RegisterCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/register/commands/RegisterCommand.kt @@ -16,7 +16,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage import org.bukkit.entity.Player import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class RegisterCommand( private val plugin: Plugin, private val registerHttpService: RegisterHttpService, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/staffchat/commands/StaffChatCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/staffchat/commands/StaffChatCommand.kt index 8ecae0947..2f6d38984 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/staffchat/commands/StaffChatCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/staffchat/commands/StaffChatCommand.kt @@ -18,7 +18,6 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer import org.bukkit.Server import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class StaffChatCommand( private val plugin: Plugin, private val server: Server, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/WarpCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/WarpCommand.kt index 5d51dac99..eaed4f48c 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/WarpCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/WarpCommand.kt @@ -26,7 +26,6 @@ import org.bukkit.entity.Player import org.bukkit.event.player.PlayerTeleportEvent import org.bukkit.plugin.Plugin -@Suppress("UnstableApiUsage") class WarpCommand( private val plugin: Plugin, private val warpRepository: WarpRepository, diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/WarpsCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/WarpsCommand.kt index 0e7f8a402..a4800e991 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/WarpsCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/WarpsCommand.kt @@ -1,206 +1,36 @@ package com.projectcitybuild.pcbridge.paper.features.warps.commands -import com.projectcitybuild.pcbridge.paper.core.libs.datetime.services.LocalizedTime -import com.projectcitybuild.pcbridge.paper.core.libs.remoteconfig.services.RemoteConfig +import com.mojang.brigadier.tree.LiteralCommandNode +import com.projectcitybuild.pcbridge.paper.PermissionNode import com.projectcitybuild.pcbridge.paper.features.warps.commands.warps.WarpCreateCommand import com.projectcitybuild.pcbridge.paper.features.warps.commands.warps.WarpDeleteCommand import com.projectcitybuild.pcbridge.paper.features.warps.commands.warps.WarpListCommand import com.projectcitybuild.pcbridge.paper.features.warps.commands.warps.WarpMoveCommand import com.projectcitybuild.pcbridge.paper.features.warps.commands.warps.WarpRenameCommand -import com.projectcitybuild.pcbridge.paper.features.warps.repositories.WarpRepository -import com.projectcitybuild.pcbridge.paper.core.support.messages.CommandHelpBuilder -import com.projectcitybuild.pcbridge.paper.core.support.spigot.BadCommandUsageException -import com.projectcitybuild.pcbridge.paper.core.support.spigot.CommandArgsParser -import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotCommand -import com.projectcitybuild.pcbridge.paper.core.support.spigot.UnauthorizedCommandException -import com.projectcitybuild.pcbridge.paper.core.extensions.tryValueOf -import net.kyori.adventure.text.minimessage.MiniMessage -import org.bukkit.Server -import org.bukkit.command.Command -import org.bukkit.command.CommandSender +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.BrigadierCommand +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.requiresPermission +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.then +import com.projectcitybuild.pcbridge.paper.features.warps.commands.warps.WarpReloadCommand +import io.papermc.paper.command.brigadier.CommandSourceStack +import io.papermc.paper.command.brigadier.Commands class WarpsCommand( - private val warpRepository: WarpRepository, - private val remoteConfig: RemoteConfig, - private val server: Server, - private val time: LocalizedTime, -) : SpigotCommand { - override val label = "warps" - - override val usage = - CommandHelpBuilder(usage = "/warps") - .subcommand( - label = "/warps list", - description = "shows all available warps", - permission = "pcbridge.warp.list", - ) - .subcommand( - label = "/warps create", - description = "creates a warp at the given position (or current position)", - permission = "pcbridge.warp.manage", - ) - .subcommand( - label = "/warps delete", - description = "deletes the given warp", - permission = "pcbridge.warp.manage", - ) - .subcommand( - label = "/warps move", - description = "moves an existing warp to your current location", - permission = "pcbridge.warp.manage", - ) - .subcommand( - label = "/warps rename", - description = "renames the given warp", - permission = "pcbridge.warp.manage", - ) - - override suspend fun run( - sender: CommandSender, - args: Args, - ) { - if (!sender.hasPermission("pcbridge.warp.manage") && !sender.hasPermission("pcbridge.warp.list")) { - throw UnauthorizedCommandException() - } - when (args.command) { - Args.Command.List -> - WarpListCommand( - warpRepository = warpRepository, - itemsPerPage = remoteConfig.latest.config.warps.itemsPerPage, - ).run( - sender = sender, - args = - WarpListCommand.Args.Parser() - .parse(args.remainingArgs), - ) - - Args.Command.Create -> - WarpCreateCommand( - warpRepository = warpRepository, - server = server, - time = time, - ).run( - sender = sender, - args = - WarpCreateCommand.Args.Parser() - .parse(args.remainingArgs), - ) - - Args.Command.Delete -> - WarpDeleteCommand( - warpRepository = warpRepository, - server = server, - ).run( - sender = sender, - args = - WarpDeleteCommand.Args.Parser() - .parse(args.remainingArgs), - ) - - Args.Command.Move -> - WarpMoveCommand( - warpRepository = warpRepository, - ).run( - sender = sender, - args = - WarpMoveCommand.Args.Parser() - .parse(args.remainingArgs), - ) - - Args.Command.Reload -> { - warpRepository.reload() - sender.sendMessage( - MiniMessage.miniMessage().deserialize("Warps reloaded") - ) - } - - Args.Command.Rename -> - WarpRenameCommand( - warpRepository = warpRepository, - ).run( - sender = sender, - args = - WarpRenameCommand.Args.Parser() - .parse(args.remainingArgs), - ) - } - } - - override suspend fun tabComplete( - sender: CommandSender, - command: Command, - alias: String, - args: Array, - ): List? { - if (args.isEmpty() || args.first().isEmpty()) { - return if (sender.hasPermission("pcbridge.warp.manage")) { - listOf("create", "delete", "list", "move", "reload", "rename") - } else { - listOf("list") - } - } - when (args.first()) { - "delete" -> { - if (args.size != 2) return null - val name = args[1] - if (name.isEmpty()) { - return warpRepository.all().map { it.name } - } - return warpRepository.all() - .filter { it.name.lowercase().startsWith(name.lowercase()) } - .map { it.name } - } - "move" -> { - if (args.size != 2) return null - val name = args[1] - if (name.isEmpty()) { - return warpRepository.all().map { it.name } - } - return warpRepository.all() - .filter { it.name.lowercase().startsWith(name.lowercase()) } - .map { it.name } - } - "rename" -> { - if (args.size != 2) return null - val name = args[1] - if (name.isEmpty()) { - return warpRepository.all().map { it.name } - } - return warpRepository.all() - .filter { it.name.lowercase().startsWith(name.lowercase()) } - .map { it.name } - } - - else -> return null - } - } - - data class Args( - val command: Command, - val remainingArgs: List, - ) { - enum class Command { - List, - Create, - Delete, - Move, - Reload, - Rename, - } - - class Parser : CommandArgsParser { - override fun parse(args: List): Args { - val command = if (args.isEmpty()) - Command.List - else - tryValueOf(args[0].replaceFirstChar { it.uppercase() }) - ?: throw BadCommandUsageException() - - return Args( - command = command, - remainingArgs = args.drop(1), - ) - } - } + private val createCommand: WarpCreateCommand, + private val deleteCommand: WarpDeleteCommand, + private val listCommand: WarpListCommand, + private val reloadCommand: WarpReloadCommand, + private val moveCommand: WarpMoveCommand, + private val renameCommand: WarpRenameCommand, +) : BrigadierCommand { + override fun buildLiteral(): LiteralCommandNode { + return Commands.literal("warps") + .requiresPermission(PermissionNode.WARP_TELEPORT) + .then(command = createCommand) + .then(command = deleteCommand) + .then(command = listCommand) + .then(command = moveCommand) + .then(command = reloadCommand) + .then(command = renameCommand) + .build() } } diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpCreateCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpCreateCommand.kt index 689172637..967ab6260 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpCreateCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpCreateCommand.kt @@ -1,116 +1,62 @@ package com.projectcitybuild.pcbridge.paper.features.warps.commands.warps -import com.projectcitybuild.pcbridge.paper.core.libs.datetime.services.LocalizedTime +import com.mojang.brigadier.arguments.StringArgumentType +import com.mojang.brigadier.context.CommandContext +import com.mojang.brigadier.tree.LiteralCommandNode import com.projectcitybuild.pcbridge.paper.features.warps.events.WarpCreateEvent import com.projectcitybuild.pcbridge.paper.features.warps.repositories.WarpRepository import com.projectcitybuild.pcbridge.http.models.pcb.Warp -import com.projectcitybuild.pcbridge.paper.core.support.messages.CommandHelpBuilder -import com.projectcitybuild.pcbridge.paper.core.support.spigot.BadCommandUsageException -import com.projectcitybuild.pcbridge.paper.core.support.spigot.CommandArgsParser -import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotCommand -import com.projectcitybuild.pcbridge.paper.core.support.spigot.UnauthorizedCommandException +import com.projectcitybuild.pcbridge.paper.PermissionNode +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.BrigadierCommand +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.executesSuspending +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.requiresPermission +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.traceCommand +import io.papermc.paper.command.brigadier.CommandSourceStack +import io.papermc.paper.command.brigadier.Commands import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.NamedTextColor import org.bukkit.Server -import org.bukkit.command.CommandSender import org.bukkit.entity.Player +import org.bukkit.plugin.Plugin class WarpCreateCommand( + private val plugin: Plugin, private val warpRepository: WarpRepository, private val server: Server, - private val time: LocalizedTime, -) : SpigotCommand { - override val label = "create" - - override val usage = CommandHelpBuilder(usage = "/warps create [x:] [y:] [z:] [pitch:] [yaw:] [world:]") - - override suspend fun run( - sender: CommandSender, - args: Args, - ) { - if (!sender.hasPermission("pcbridge.warp.manage")) { - throw UnauthorizedCommandException() - } - val player = sender as? Player - checkNotNull(player) { - "Only players can use this command" - } - - val world = - if (args.worldName.isNullOrEmpty()) { - player.location.world - } else { - server.getWorld(args.worldName) - } - checkNotNull(world) { - "World ${args.worldName} not found" - } - - val warp = - Warp( - id = -1, - name = args.warpName, - world = world.name, - x = args.x ?: player.location.x, - y = args.y ?: player.location.y, - z = args.z ?: player.location.z, - yaw = args.yaw ?: player.location.yaw, - pitch = args.pitch ?: player.location.pitch, +) : BrigadierCommand { + override fun buildLiteral(): LiteralCommandNode { + return Commands.literal("create") + .requiresPermission(PermissionNode.WARP_MANAGE) + .then( + Commands.argument("name", StringArgumentType.string()) + .executesSuspending(plugin, ::execute) ) + .build() + } + + private suspend fun execute(context: CommandContext) = traceCommand(context) { + val warpName = context.getArgument("name", String::class.java) + val player = context.source.executor as? Player + checkNotNull(player) { "Only players can use this command" } + + val location = player.location + val warp = Warp( + id = -1, + name = warpName, + world = location.world.name, + x = location.x, + y = location.y, + z = location.z, + yaw = location.yaw, + pitch = location.pitch, + ) warpRepository.create(warp) server.pluginManager.callEvent(WarpCreateEvent()) - sender.sendMessage( - Component.text("${args.warpName} warp created") + player.sendMessage( + Component.text("${warp.name} warp created") .color(NamedTextColor.GREEN), ) } - - data class Args( - val warpName: String, - val worldName: String?, - val x: Double?, - val y: Double?, - val z: Double?, - val yaw: Float?, - val pitch: Float?, - ) { - class Parser : CommandArgsParser { - override fun parse(args: List): Args { - if (args.isEmpty()) { - throw BadCommandUsageException() - } - val warpName = args[0] - val remainingArgs = args.drop(1) - - return Args( - warpName = warpName, - worldName = remainingArgs - .find { it.startsWith("world:") } - ?.removePrefix("world:"), - x = remainingArgs - .find { it.startsWith("x:") } - ?.removePrefix("x:") - ?.toDoubleOrNull(), - y = remainingArgs - .find { it.startsWith("y:") } - ?.removePrefix("y:") - ?.toDoubleOrNull(), - z = remainingArgs - .find { it.startsWith("z:") } - ?.removePrefix("z:") - ?.toDoubleOrNull(), - yaw = remainingArgs - .find { it.startsWith("yaw:") } - ?.removePrefix("yaw:") - ?.toFloatOrNull(), - pitch = remainingArgs - .find { it.startsWith("pitch:") } - ?.removePrefix("pitch:") - ?.toFloatOrNull(), - ) - } - } - } } diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpDeleteCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpDeleteCommand.kt index 99bc69130..366c60087 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpDeleteCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpDeleteCommand.kt @@ -1,52 +1,62 @@ package com.projectcitybuild.pcbridge.paper.features.warps.commands.warps +import com.mojang.brigadier.arguments.StringArgumentType +import com.mojang.brigadier.context.CommandContext +import com.mojang.brigadier.suggestion.SuggestionsBuilder +import com.mojang.brigadier.tree.LiteralCommandNode +import com.projectcitybuild.pcbridge.paper.PermissionNode +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.BrigadierCommand +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.executesSuspending +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.requiresPermission +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.suggestsSuspending +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.traceCommand import com.projectcitybuild.pcbridge.paper.features.warps.events.WarpDeleteEvent import com.projectcitybuild.pcbridge.paper.features.warps.repositories.WarpRepository -import com.projectcitybuild.pcbridge.paper.core.support.messages.CommandHelpBuilder -import com.projectcitybuild.pcbridge.paper.core.support.spigot.BadCommandUsageException -import com.projectcitybuild.pcbridge.paper.core.support.spigot.CommandArgsParser -import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotCommand -import com.projectcitybuild.pcbridge.paper.core.support.spigot.UnauthorizedCommandException +import io.papermc.paper.command.brigadier.CommandSourceStack +import io.papermc.paper.command.brigadier.Commands import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.NamedTextColor import org.bukkit.Server -import org.bukkit.command.CommandSender +import org.bukkit.plugin.Plugin class WarpDeleteCommand( + private val plugin: Plugin, private val warpRepository: WarpRepository, private val server: Server, -) : SpigotCommand { - override val label = "delete" - - override val usage = CommandHelpBuilder(usage = "/warps delete ") +) : BrigadierCommand { + override fun buildLiteral(): LiteralCommandNode { + return Commands.literal("delete") + .requiresPermission(PermissionNode.WARP_MANAGE) + .then( + Commands.argument("name", StringArgumentType.string()) + .suggestsSuspending(plugin, ::suggestWarp) + .executesSuspending(plugin, ::execute) + ) + .build() + } - override suspend fun run( - sender: CommandSender, - args: Args, + private suspend fun suggestWarp( + context: CommandContext, + suggestions: SuggestionsBuilder, ) { - if (!sender.hasPermission("pcbridge.warp.manage")) { - throw UnauthorizedCommandException() - } - warpRepository.delete(name = args.warpName) + val name = suggestions.remaining.lowercase() + + return warpRepository.all() + .filter { it.name.lowercase().startsWith(name) } + .map { it.name } + .forEach(suggestions::suggest) + } + + private suspend fun execute(context: CommandContext) = traceCommand(context) { + val warpName = context.getArgument("name", String::class.java) + + warpRepository.delete(name = warpName) server.pluginManager.callEvent(WarpDeleteEvent()) - sender.sendMessage( - Component.text("${args.warpName} warp deleted") + context.source.sender.sendMessage( + Component.text("$warpName warp deleted") .color(NamedTextColor.GREEN), ) } - - data class Args( - val warpName: String, - ) { - class Parser : CommandArgsParser { - override fun parse(args: List): Args { - if (args.size != 1) { - throw BadCommandUsageException() - } - return Args(warpName = args[0]) - } - } - } } diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpListCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpListCommand.kt index 323b6e04a..e10a8c010 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpListCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpListCommand.kt @@ -1,97 +1,86 @@ package com.projectcitybuild.pcbridge.paper.features.warps.commands.warps +import com.mojang.brigadier.arguments.IntegerArgumentType +import com.mojang.brigadier.context.CommandContext +import com.mojang.brigadier.tree.LiteralCommandNode import com.projectcitybuild.pcbridge.paper.core.libs.pagination.SimplePaginator import com.projectcitybuild.pcbridge.paper.features.warps.repositories.WarpRepository import com.projectcitybuild.pcbridge.http.models.pcb.Warp -import com.projectcitybuild.pcbridge.paper.core.support.messages.CommandHelpBuilder +import com.projectcitybuild.pcbridge.paper.PermissionNode +import com.projectcitybuild.pcbridge.paper.core.libs.remoteconfig.services.RemoteConfig +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.BrigadierCommand +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.executesSuspending +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.requiresPermission +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.traceCommand import com.projectcitybuild.pcbridge.paper.core.support.messages.PaginationBuilder -import com.projectcitybuild.pcbridge.paper.core.support.spigot.BadCommandUsageException -import com.projectcitybuild.pcbridge.paper.core.support.spigot.CommandArgsParser -import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotCommand -import com.projectcitybuild.pcbridge.paper.core.support.spigot.UnauthorizedCommandException +import io.papermc.paper.command.brigadier.CommandSourceStack +import io.papermc.paper.command.brigadier.Commands import net.kyori.adventure.text.Component import net.kyori.adventure.text.event.ClickEvent import net.kyori.adventure.text.event.HoverEvent import net.kyori.adventure.text.format.NamedTextColor import net.kyori.adventure.text.format.TextDecoration -import org.bukkit.command.CommandSender +import org.bukkit.plugin.Plugin class WarpListCommand( + private val plugin: Plugin, private val warpRepository: WarpRepository, - private val itemsPerPage: Int, -) : SpigotCommand { - override val label = "list" + private val remoteConfig: RemoteConfig, +) : BrigadierCommand { + override fun buildLiteral(): LiteralCommandNode { + return Commands.literal("list") + .requiresPermission(PermissionNode.WARP_TELEPORT) + .then( + Commands.argument("page", IntegerArgumentType.integer(1)) + .executesSuspending(plugin, ::execute) + ) + .executesSuspending(plugin, ::execute) + .build() + } - override val usage = CommandHelpBuilder(usage = "/warps list") + private suspend fun execute(context: CommandContext) = traceCommand(context) { + val pageNumber = runCatching { + context.getArgument("page", Int::class.java) + }.getOrElse { 1 } - override suspend fun run( - sender: CommandSender, - args: Args, - ) { - if (!sender.hasPermission("pcbridge.warp.list")) { - throw UnauthorizedCommandException() - } + val sender = context.source.sender + val itemsPerPage = remoteConfig.latest.config.warps.itemsPerPage val warps = warpRepository.all() val page = SimplePaginator().paginate( items = warps, pageSize = itemsPerPage, - page = args.page, + page = pageNumber, ) if (page.items.isEmpty()) { sender.sendMessage( Component.text("No warps available") .color(NamedTextColor.GRAY), ) - return + return@traceCommand } - val message = - PaginationBuilder() - .items { (index, warp) -> - val rawCommand = "/warp ${warp.name}" - val component = - Component.text() - .content(warp.name) - .color(NamedTextColor.AQUA) - .decorate(TextDecoration.UNDERLINED) - .clickEvent(ClickEvent.runCommand(rawCommand)) - .hoverEvent(HoverEvent.showText(Component.text(rawCommand))) + val message = PaginationBuilder() + .items { (index, warp) -> + val rawCommand = "/warp ${warp.name}" + val component = + Component.text() + .content(warp.name) + .color(NamedTextColor.AQUA) + .decorate(TextDecoration.UNDERLINED) + .clickEvent(ClickEvent.runCommand(rawCommand)) + .hoverEvent(HoverEvent.showText(Component.text(rawCommand))) - if (index < page.items.size - 1) { - component.append( - Component.text(" / ") - .color(NamedTextColor.WHITE) - .decoration(TextDecoration.UNDERLINED, false), - ) - } - component.build() + if (index < page.items.size - 1) { + component.append( + Component.text(" / ") + .color(NamedTextColor.WHITE) + .decoration(TextDecoration.UNDERLINED, false), + ) } - .build(page) + component.build() + } + .build(page) sender.sendMessage(message) } - - data class Args( - val page: Int, - ) { - class Parser : CommandArgsParser { - override fun parse(args: List): Args { - if (args.size > 1) { - throw BadCommandUsageException() - } - val page = - if (args.isEmpty()) { - 1 - } else { - args[0].toIntOrNull() - ?: error("Page must be a valid number") - } - - check(page > 0) { - "Page must be greater than 0" - } - return Args(page = page) - } - } - } } diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpMoveCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpMoveCommand.kt index 6b0c9fcb5..46c7884a5 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpMoveCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpMoveCommand.kt @@ -1,59 +1,69 @@ package com.projectcitybuild.pcbridge.paper.features.warps.commands.warps +import com.mojang.brigadier.arguments.StringArgumentType +import com.mojang.brigadier.context.CommandContext +import com.mojang.brigadier.suggestion.SuggestionsBuilder +import com.mojang.brigadier.tree.LiteralCommandNode +import com.projectcitybuild.pcbridge.paper.PermissionNode +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.BrigadierCommand +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.executesSuspending +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.requiresPermission +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.suggestsSuspending +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.traceCommand import com.projectcitybuild.pcbridge.paper.features.warps.repositories.WarpRepository -import com.projectcitybuild.pcbridge.paper.core.support.messages.CommandHelpBuilder -import com.projectcitybuild.pcbridge.paper.core.support.spigot.BadCommandUsageException -import com.projectcitybuild.pcbridge.paper.core.support.spigot.CommandArgsParser -import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotCommand -import com.projectcitybuild.pcbridge.paper.core.support.spigot.UnauthorizedCommandException +import io.papermc.paper.command.brigadier.CommandSourceStack +import io.papermc.paper.command.brigadier.Commands import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.NamedTextColor -import org.bukkit.command.CommandSender import org.bukkit.entity.Player +import org.bukkit.plugin.Plugin class WarpMoveCommand( + private val plugin: Plugin, private val warpRepository: WarpRepository, -) : SpigotCommand { - override val label = "move" - - override val usage = CommandHelpBuilder(usage = "/warps move ") +) : BrigadierCommand { + override fun buildLiteral(): LiteralCommandNode { + return Commands.literal("move") + .requiresPermission(PermissionNode.WARP_MANAGE) + .then( + Commands.argument("name", StringArgumentType.string()) + .suggestsSuspending(plugin, ::suggestWarp) + .executesSuspending(plugin, ::execute) + ) + .build() + } - override suspend fun run( - sender: CommandSender, - args: Args, + private suspend fun suggestWarp( + context: CommandContext, + suggestions: SuggestionsBuilder, ) { - if (!sender.hasPermission("pcbridge.warp.manage")) { - throw UnauthorizedCommandException() - } - val player = sender as? Player - checkNotNull(player) { - "Only players can use this command" - } + val name = suggestions.remaining.lowercase() + + return warpRepository.all() + .filter { it.name.lowercase().startsWith(name) } + .map { it.name } + .forEach(suggestions::suggest) + } + + private suspend fun execute(context: CommandContext) = traceCommand(context) { + val warpName = context.getArgument("name", String::class.java) + val player = context.source.executor as? Player + checkNotNull(player) { "Only players can use this command" } + + val location = player.location warpRepository.move( - name = args.warpName, - world = player.location.world.name, - x = player.location.x, - y = player.location.y, - z = player.location.z, - pitch = player.location.pitch, - yaw = player.location.yaw, + name = warpName, + world = location.world.name, + x = location.x, + y = location.y, + z = location.z, + pitch = location.pitch, + yaw = location.yaw, ) - sender.sendMessage( - Component.text("${args.warpName} warp moved") + + context.source.sender.sendMessage( + Component.text("$warpName warp moved") .color(NamedTextColor.GREEN), ) } - - data class Args( - val warpName: String, - ) { - class Parser : CommandArgsParser { - override fun parse(args: List): Args { - if (args.size != 1) { - throw BadCommandUsageException() - } - return Args(warpName = args[0]) - } - } - } } diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpReloadCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpReloadCommand.kt new file mode 100644 index 000000000..6a27c02a8 --- /dev/null +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpReloadCommand.kt @@ -0,0 +1,34 @@ +package com.projectcitybuild.pcbridge.paper.features.warps.commands.warps + +import com.mojang.brigadier.context.CommandContext +import com.mojang.brigadier.tree.LiteralCommandNode +import com.projectcitybuild.pcbridge.paper.PermissionNode +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.BrigadierCommand +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.executesSuspending +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.requiresPermission +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.traceCommand +import com.projectcitybuild.pcbridge.paper.features.warps.repositories.WarpRepository +import io.papermc.paper.command.brigadier.CommandSourceStack +import io.papermc.paper.command.brigadier.Commands +import net.kyori.adventure.text.minimessage.MiniMessage +import org.bukkit.plugin.Plugin + +class WarpReloadCommand( + private val plugin: Plugin, + private val warpRepository: WarpRepository, +) : BrigadierCommand { + override fun buildLiteral(): LiteralCommandNode { + return Commands.literal("reload") + .requiresPermission(PermissionNode.WARP_MANAGE) + .executesSuspending(plugin, ::execute) + .build() + } + + private suspend fun execute(context: CommandContext) = traceCommand(context) { + warpRepository.reload() + + context.source.sender.sendMessage( + MiniMessage.miniMessage().deserialize("Warps reloaded") + ) + } +} diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpRenameCommand.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpRenameCommand.kt index 04c580a25..72359fa4f 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpRenameCommand.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/warps/commands/warps/WarpRenameCommand.kt @@ -1,53 +1,63 @@ package com.projectcitybuild.pcbridge.paper.features.warps.commands.warps +import com.mojang.brigadier.arguments.StringArgumentType +import com.mojang.brigadier.context.CommandContext +import com.mojang.brigadier.suggestion.SuggestionsBuilder +import com.mojang.brigadier.tree.LiteralCommandNode +import com.projectcitybuild.pcbridge.paper.PermissionNode +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.BrigadierCommand +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.executesSuspending +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.requiresPermission +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.suggestsSuspending +import com.projectcitybuild.pcbridge.paper.core.support.brigadier.traceCommand import com.projectcitybuild.pcbridge.paper.features.warps.repositories.WarpRepository -import com.projectcitybuild.pcbridge.paper.core.support.messages.CommandHelpBuilder -import com.projectcitybuild.pcbridge.paper.core.support.spigot.BadCommandUsageException -import com.projectcitybuild.pcbridge.paper.core.support.spigot.CommandArgsParser -import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotCommand -import com.projectcitybuild.pcbridge.paper.core.support.spigot.UnauthorizedCommandException +import io.papermc.paper.command.brigadier.CommandSourceStack +import io.papermc.paper.command.brigadier.Commands import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.NamedTextColor -import org.bukkit.command.CommandSender +import org.bukkit.plugin.Plugin class WarpRenameCommand( + private val plugin: Plugin, private val warpRepository: WarpRepository, -) : SpigotCommand { - override val label = "rename" - - override val usage = CommandHelpBuilder(usage = "/warps rename ") +) : BrigadierCommand { + override fun buildLiteral(): LiteralCommandNode { + return Commands.literal("rename") + .requiresPermission(PermissionNode.WARP_MANAGE) + .then( + Commands.argument("name", StringArgumentType.string()) + .suggestsSuspending(plugin, ::suggestWarp) + .then( + Commands.argument("new name", StringArgumentType.string()) + .executesSuspending(plugin, ::execute) + ) + ) + .build() + } - override suspend fun run( - sender: CommandSender, - args: Args, + private suspend fun suggestWarp( + context: CommandContext, + suggestions: SuggestionsBuilder, ) { - if (!sender.hasPermission("pcbridge.warp.manage")) { - throw UnauthorizedCommandException() - } + val name = suggestions.remaining.lowercase() + + return warpRepository.all() + .filter { it.name.lowercase().startsWith(name) } + .map { it.name } + .forEach(suggestions::suggest) + } + + private suspend fun execute(context: CommandContext) = traceCommand(context) { + val oldName = context.getArgument("name", String::class.java) + val newName = context.getArgument("new name", String::class.java) + warpRepository.rename( - oldName = args.oldName, - newName = args.newName, + oldName = oldName, + newName = newName, ) - sender.sendMessage( - Component.text("${args.oldName} renamed to ${args.newName}") + context.source.sender.sendMessage( + Component.text("$oldName renamed to $newName") .color(NamedTextColor.GREEN), ) } - - data class Args( - val oldName: String, - val newName: String, - ) { - class Parser : CommandArgsParser { - override fun parse(args: List): Args { - if (args.size != 2) { - throw BadCommandUsageException() - } - return Args( - oldName = args[0], - newName = args[1], - ) - } - } - } }