Skip to content

Commit

Permalink
Convert remaining commands
Browse files Browse the repository at this point in the history
  • Loading branch information
andyksaw committed Nov 29, 2024
1 parent 1daf491 commit e11ed6e
Show file tree
Hide file tree
Showing 34 changed files with 339 additions and 507 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -131,13 +136,6 @@ private fun Module.spigot(plugin: JavaPlugin) {
)
}

single {
SpigotCommandRegistry(
plugin = get(),
sentry = get(),
)
}

single {
SpigotListenerRegistry(
plugin = get(),
Expand Down Expand Up @@ -405,17 +403,41 @@ private fun Module.warps() {

factory {
WarpCommand(
plugin = get(),
warpRepository = get(),
server = get(),
)
}

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(),
),
)
}
}
Expand Down Expand Up @@ -517,6 +539,7 @@ private fun Module.bans() {
private fun Module.invisFrames() {
factory {
InvisFrameCommand(
plugin = get(),
spigotNamespace = get(),
)
}
Expand Down Expand Up @@ -599,11 +622,13 @@ private fun Module.chat() {
private fun Module.register() {
factory {
RegisterCommand(
plugin = get(),
registerHttpService = get<PCBHttp>().register,
)
}
factory {
CodeCommand(
plugin = get(),
registerHttpService = get<PCBHttp>().register,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ private class Lifecycle : KoinComponent {

remoteConfig.fetch()

@Suppress("UnstableApiUsage")
// TODO: inject lifecycle manager instead
get<JavaPlugin>()
.lifecycleManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandSourceStack>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandSourceStack>,
block: suspend (CommandContext<CommandSourceStack>) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,20 @@ fun <S> LiteralArgumentBuilder<S>.executesSuspending(
}
}

@Suppress("UnstableApiUsage")
fun LiteralArgumentBuilder<CommandSourceStack>.then(
command: BrigadierCommand,
): LiteralArgumentBuilder<CommandSourceStack> {
return then(command.buildLiteral())
}

@Suppress("UnstableApiUsage")
fun LiteralArgumentBuilder<CommandSourceStack>.requiresPermission(
permission: PermissionNode,
): LiteralArgumentBuilder<CommandSourceStack> {
return requires { context ->
context.sender.hasPermission(permission.node)
}
}
@Suppress("UnstableApiUsage")

fun <S: CommandSourceStack, T> RequiredArgumentBuilder<S, T>.requiresPermission(
permission: PermissionNode,
): RequiredArgumentBuilder<S, T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandSourceStack> {
return Commands.literal("itemname")
.requiresPermission(PermissionNode.BUILD_ITEM_RENAME)
.requiresPermission(PermissionNode.BUILDING_ITEM_RENAME)
.then(
Commands.argument("name", StringArgumentType.greedyString())
.executesSuspending(plugin, ::execute)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandSourceStack> {
return Commands.literal("nv")
.requiresPermission(PermissionNode.BUILD_NIGHT_VISION)
.requiresPermission(PermissionNode.BUILDING_NIGHT_VISION)
.then(
Commands.argument("enabled", OnOffArgument())
.executesSuspending(plugin, ::execute)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandSourceStack> {
return Commands.literal("invisframe")
.requiresPermission(PermissionNode.BUILD_INVIS_FRAME)
.requiresPermission(PermissionNode.BUILDING_INVIS_FRAME)
.then(
Commands.literal("glowing")
.executesSuspending(plugin, ::giveGlowing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit e11ed6e

Please sign in to comment.