Skip to content

Commit

Permalink
Convert commands to Brigadier commands
Browse files Browse the repository at this point in the history
  • Loading branch information
andyksaw committed Nov 29, 2024
1 parent 2c9d48e commit 1daf491
Show file tree
Hide file tree
Showing 48 changed files with 591 additions and 801 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.projectcitybuild.pcbridge.paper.core.libs.permissions.Permissions
import com.projectcitybuild.pcbridge.paper.core.libs.permissions.adapters.LuckPermsPermissions
import com.projectcitybuild.pcbridge.paper.core.libs.remoteconfig.commands.ConfigCommand
import com.projectcitybuild.pcbridge.paper.core.libs.remoteconfig.services.RemoteConfig
import com.projectcitybuild.pcbridge.paper.core.libs.store.Store
import com.projectcitybuild.pcbridge.paper.architecture.store.Store
import com.projectcitybuild.pcbridge.paper.core.libs.localconfig.LocalConfigKeyValues
import com.projectcitybuild.pcbridge.paper.features.announcements.actions.StartAnnouncementTimer
import com.projectcitybuild.pcbridge.paper.features.announcements.listeners.AnnouncementConfigListener
Expand All @@ -38,15 +38,15 @@ import com.projectcitybuild.pcbridge.paper.features.joinmessages.listeners.Annou
import com.projectcitybuild.pcbridge.paper.features.joinmessages.listeners.AnnounceQuitListener
import com.projectcitybuild.pcbridge.paper.features.joinmessages.listeners.FirstTimeJoinListener
import com.projectcitybuild.pcbridge.paper.features.joinmessages.listeners.ServerOverviewJoinListener
import com.projectcitybuild.pcbridge.paper.features.nightvision.commands.NightVisionCommand
import com.projectcitybuild.pcbridge.paper.features.architecture.listeners.PlayerStateListener
import com.projectcitybuild.pcbridge.paper.features.building.commands.NightVisionCommand
import com.projectcitybuild.pcbridge.paper.architecture.listeners.PlayerStateListener
import com.projectcitybuild.pcbridge.paper.features.register.commands.CodeCommand
import com.projectcitybuild.pcbridge.paper.features.register.commands.RegisterCommand
import com.projectcitybuild.pcbridge.paper.features.staffchat.commands.StaffChatCommand
import com.projectcitybuild.pcbridge.paper.features.groups.actions.SyncPlayerGroups
import com.projectcitybuild.pcbridge.paper.features.groups.commands.SyncCommand
import com.projectcitybuild.pcbridge.paper.features.groups.listener.SyncRankListener
import com.projectcitybuild.pcbridge.paper.features.architecture.listeners.PlayerSyncRequestListener
import com.projectcitybuild.pcbridge.paper.architecture.listeners.PlayerSyncRequestListener
import com.projectcitybuild.pcbridge.paper.features.telemetry.listeners.TelemetryPlayerConnectListener
import com.projectcitybuild.pcbridge.paper.features.telemetry.repositories.TelemetryRepository
import com.projectcitybuild.pcbridge.paper.features.warps.commands.WarpCommand
Expand All @@ -62,7 +62,7 @@ import com.projectcitybuild.pcbridge.paper.features.builds.commands.builds.Build
import com.projectcitybuild.pcbridge.paper.features.builds.commands.builds.BuildVoteCommand
import com.projectcitybuild.pcbridge.paper.features.builds.repositories.BuildRepository
import com.projectcitybuild.pcbridge.paper.features.watchdog.listeners.ItemTextListener
import com.projectcitybuild.pcbridge.paper.features.watchdog.listeners.commands.ItemNameCommand
import com.projectcitybuild.pcbridge.paper.features.building.commands.ItemNameCommand
import com.projectcitybuild.pcbridge.paper.integrations.DynmapIntegration
import com.projectcitybuild.pcbridge.paper.integrations.EssentialsIntegration
import com.projectcitybuild.pcbridge.paper.integrations.LuckPermsIntegration
Expand All @@ -71,7 +71,7 @@ import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotEventBroadc
import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotListenerRegistry
import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotNamespace
import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotTimer
import com.projectcitybuild.pcbridge.paper.features.architecture.listeners.ExceptionListener
import com.projectcitybuild.pcbridge.paper.architecture.listeners.ExceptionListener
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
Expand Down Expand Up @@ -101,12 +101,12 @@ fun pluginModule(_plugin: JavaPlugin) =
announcements()
architecture()
bans()
building()
builds()
chat()
groups()
joinMessages()
invisFrames()
nightVision()
register()
staffChat()
telemetry()
Expand Down Expand Up @@ -223,6 +223,7 @@ private fun Module.core() {

factory {
ConfigCommand(
plugin = get(),
remoteConfig = get(),
)
}
Expand Down Expand Up @@ -380,6 +381,21 @@ private fun Module.builds() {
}
}

private fun Module.building() {
factory {
NightVisionCommand(
plugin = get(),
)
}

factory {
ItemNameCommand(
plugin = get(),
eventBroadcaster = get(),
)
}
}

private fun Module.warps() {
single {
WarpRepository(
Expand Down Expand Up @@ -411,12 +427,6 @@ private fun Module.watchdog() {
time = get(),
)
}

factory {
ItemNameCommand(
eventBroadcaster = get(),
)
}
}

private fun Module.joinMessages() {
Expand Down Expand Up @@ -504,12 +514,6 @@ private fun Module.bans() {
}
}

private fun Module.nightVision() {
factory {
NightVisionCommand()
}
}

private fun Module.invisFrames() {
factory {
InvisFrameCommand(
Expand Down Expand Up @@ -622,6 +626,7 @@ private fun Module.telemetry() {
private fun Module.staffChat() {
factory {
StaffChatCommand(
plugin = get(),
server = get(),
remoteConfig = get(),
)
Expand All @@ -643,7 +648,7 @@ private fun Module.groups() {

factory {
SyncCommand(
server = get(),
plugin = get(),
eventBroadcaster = get(),
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
package com.projectcitybuild.pcbridge.paper

enum class PermissionNode(val node: String) {
BUILD_TELEPORT("pcbridge.builds.teleport"),
BUILD_MANAGE("pcbridge.builds.manage"),
BUILD_VOTE("pcbridge.builds.vote"),
// Can teleport to a build
BUILDS_TELEPORT("pcbridge.builds.teleport"),

// Can create, edit or delete a build
BUILDS_MANAGE("pcbridge.builds.manage"),

// Can vote for a build
BUILDS_VOTE("pcbridge.builds.vote"),

// Can toggle nightvision mode
BUILD_NIGHT_VISION("pcbridge.build.nightvision"),

// Can rename an item via a command
BUILD_ITEM_RENAME("pcbridge.items.rename"),

// Can get an invisible item frame via a command
BUILD_INVIS_FRAME("pcbridge.build.invisframe"),

// Can send and receive staff messages
STAFF_CHANNEL("pcbridge.chat.staff_channel"),

// Can force sync another player (in addition to yourself)
PLAYER_SYNC_OTHER("pcbridge.sync.other"),

// Can force reload the remote config
REMOTE_CONFIG_RELOAD("pcbridge.config.reload"),

// Can teleport to a warp
WARP_TELEPORT("pcbridge.warp.teleport"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ import com.projectcitybuild.pcbridge.paper.features.joinmessages.listeners.Annou
import com.projectcitybuild.pcbridge.paper.features.joinmessages.listeners.AnnounceQuitListener
import com.projectcitybuild.pcbridge.paper.features.joinmessages.listeners.FirstTimeJoinListener
import com.projectcitybuild.pcbridge.paper.features.joinmessages.listeners.ServerOverviewJoinListener
import com.projectcitybuild.pcbridge.paper.features.nightvision.commands.NightVisionCommand
import com.projectcitybuild.pcbridge.paper.features.architecture.listeners.PlayerStateListener
import com.projectcitybuild.pcbridge.paper.features.building.commands.NightVisionCommand
import com.projectcitybuild.pcbridge.paper.architecture.listeners.PlayerStateListener
import com.projectcitybuild.pcbridge.paper.features.register.commands.CodeCommand
import com.projectcitybuild.pcbridge.paper.features.register.commands.RegisterCommand
import com.projectcitybuild.pcbridge.paper.features.staffchat.commands.StaffChatCommand
import com.projectcitybuild.pcbridge.paper.features.groups.listener.SyncRankListener
import com.projectcitybuild.pcbridge.paper.features.architecture.listeners.PlayerSyncRequestListener
import com.projectcitybuild.pcbridge.paper.architecture.listeners.PlayerSyncRequestListener
import com.projectcitybuild.pcbridge.paper.features.telemetry.listeners.TelemetryPlayerConnectListener
import com.projectcitybuild.pcbridge.paper.features.warps.commands.WarpCommand
import com.projectcitybuild.pcbridge.paper.features.warps.commands.WarpsCommand
import com.projectcitybuild.pcbridge.paper.features.watchdog.listeners.ItemTextListener
import com.projectcitybuild.pcbridge.paper.features.watchdog.listeners.commands.ItemNameCommand
import com.projectcitybuild.pcbridge.paper.features.building.commands.ItemNameCommand
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.SpigotListenerRegistry
import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotTimer
import com.projectcitybuild.pcbridge.paper.features.architecture.listeners.ExceptionListener
import com.projectcitybuild.pcbridge.paper.architecture.listeners.ExceptionListener
import com.projectcitybuild.pcbridge.paper.core.support.brigadier.extensions.register
import com.projectcitybuild.pcbridge.webserver.HttpServer
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents
import net.kyori.adventure.platform.bukkit.BukkitAudiences
Expand Down Expand Up @@ -88,7 +88,6 @@ class Plugin : SuspendingJavaPlugin() {
private class Lifecycle : KoinComponent {
private val audiences: BukkitAudiences = get()
private val sentry: SentryReporter by inject()
private val commandRegistry: SpigotCommandRegistry by inject()
private val listenerRegistry: SpigotListenerRegistry by inject()
private val httpServer: HttpServer by inject()
private val remoteConfig: RemoteConfig by inject()
Expand All @@ -99,48 +98,27 @@ private class Lifecycle : KoinComponent {

remoteConfig.fetch()

commandRegistry.apply {
register(
handler = get<WarpCommand>(),
argsParser = WarpCommand.Args.Parser(),
)
register(
handler = get<WarpsCommand>(),
argsParser = WarpsCommand.Args.Parser(),
)
register(
handler = get<StaffChatCommand>(),
argsParser = StaffChatCommand.Args.Parser(),
)
register(
handler = get<NightVisionCommand>(),
argsParser = NightVisionCommand.Args.Parser(),
)
register(
handler = get<InvisFrameCommand>(),
argsParser = InvisFrameCommand.Args.Parser(),
)
register(
handler = get<RegisterCommand>(),
argsParser = RegisterCommand.Args.Parser(),
)
register(
handler = get<CodeCommand>(),
argsParser = CodeCommand.Args.Parser(),
)
register(
handler = get<SyncCommand>(),
argsParser = SyncCommand.Args.Parser(),
)
register(
handler = get<ConfigCommand>(),
argsParser = ConfigCommand.Args.Parser(),
)
register(
handler = get<ItemNameCommand>(),
argsParser = ItemNameCommand.Args.Parser(),
)
}
@Suppress("UnstableApiUsage")
// TODO: inject lifecycle manager instead
get<JavaPlugin>()
.lifecycleManager
.registerEventHandler(LifecycleEvents.COMMANDS) { event ->
event.registrar().register(
get<BuildsCommand>(),
get<BuildCommand>(),
get<WarpCommand>(),
get<WarpsCommand>(),
get<StaffChatCommand>(),
get<NightVisionCommand>(),
get<InvisFrameCommand>(),
get<RegisterCommand>(),
get<CodeCommand>(),
get<SyncCommand>(),
get<ConfigCommand>(),
get<ItemNameCommand>(),
)
}

listenerRegistry.register(
get<AnnounceJoinListener>(),
get<AnnounceQuitListener>(),
Expand All @@ -165,16 +143,6 @@ private class Lifecycle : KoinComponent {
get<UUIDBanRequestListener>(),
)

@Suppress("UnstableApiUsage")
get<JavaPlugin>()
.lifecycleManager
.registerEventHandler(LifecycleEvents.COMMANDS) { event ->
event.registrar().apply {
register(get<BuildsCommand>().buildLiteral())
register(get<BuildCommand>().buildLiteral())
}
}

get<DynmapIntegration>().enable()
get<EssentialsIntegration>().enable()
get<LuckPermsIntegration>().enable()
Expand All @@ -195,7 +163,6 @@ private class Lifecycle : KoinComponent {
get<DiscordSend>().stopProcessing()

listenerRegistry.unregisterAll()
commandRegistry.unregisterAll()
audiences.close()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.projectcitybuild.pcbridge.paper.features.architecture.events
package com.projectcitybuild.pcbridge.paper.architecture.events

import com.projectcitybuild.pcbridge.paper.core.libs.store.PlayerState
import com.projectcitybuild.pcbridge.paper.architecture.store.PlayerState
import org.bukkit.event.Event
import org.bukkit.event.HandlerList
import java.util.UUID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.projectcitybuild.pcbridge.paper.features.architecture.events
package com.projectcitybuild.pcbridge.paper.architecture.events

import com.projectcitybuild.pcbridge.paper.core.libs.store.PlayerState
import com.projectcitybuild.pcbridge.paper.architecture.store.PlayerState
import org.bukkit.event.Event
import org.bukkit.event.HandlerList
import java.util.UUID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.paper.features.architecture.listeners
package com.projectcitybuild.pcbridge.paper.architecture.listeners

import com.github.shynixn.mccoroutine.bukkit.MCCoroutineExceptionEvent
import com.projectcitybuild.pcbridge.paper.core.libs.errors.SentryReporter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.projectcitybuild.pcbridge.paper.features.architecture.listeners
package com.projectcitybuild.pcbridge.paper.architecture.listeners

import com.projectcitybuild.pcbridge.paper.core.libs.datetime.services.LocalizedTime
import com.projectcitybuild.pcbridge.paper.core.libs.logger.log
import com.projectcitybuild.pcbridge.paper.core.libs.store.PlayerState
import com.projectcitybuild.pcbridge.paper.core.libs.store.Store
import com.projectcitybuild.pcbridge.paper.architecture.store.PlayerState
import com.projectcitybuild.pcbridge.paper.architecture.store.Store
import com.projectcitybuild.pcbridge.paper.features.bans.events.ConnectionPermittedEvent
import com.projectcitybuild.pcbridge.paper.features.architecture.events.PlayerStateUpdatedEvent
import com.projectcitybuild.pcbridge.paper.features.architecture.events.PlayerStateDestroyedEvent
import com.projectcitybuild.pcbridge.paper.architecture.events.PlayerStateUpdatedEvent
import com.projectcitybuild.pcbridge.paper.architecture.events.PlayerStateDestroyedEvent
import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotEventBroadcaster
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.projectcitybuild.pcbridge.paper.features.architecture.listeners
package com.projectcitybuild.pcbridge.paper.architecture.listeners

import com.projectcitybuild.pcbridge.paper.core.libs.datetime.services.LocalizedTime
import com.projectcitybuild.pcbridge.paper.core.libs.logger.log
import com.projectcitybuild.pcbridge.paper.core.libs.store.PlayerState
import com.projectcitybuild.pcbridge.paper.core.libs.store.Store
import com.projectcitybuild.pcbridge.paper.architecture.store.PlayerState
import com.projectcitybuild.pcbridge.paper.architecture.store.Store
import com.projectcitybuild.pcbridge.paper.features.bans.repositories.PlayerRepository
import com.projectcitybuild.pcbridge.paper.features.architecture.events.PlayerStateUpdatedEvent
import com.projectcitybuild.pcbridge.paper.architecture.events.PlayerStateUpdatedEvent
import com.projectcitybuild.pcbridge.paper.features.groups.events.PlayerSyncRequestedEvent
import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotEventBroadcaster
import net.kyori.adventure.text.minimessage.MiniMessage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.paper.core.libs.store
package com.projectcitybuild.pcbridge.paper.architecture.store

import com.projectcitybuild.pcbridge.http.models.pcb.Account
import com.projectcitybuild.pcbridge.http.models.pcb.Badge
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.paper.core.libs.store
package com.projectcitybuild.pcbridge.paper.architecture.store

import com.projectcitybuild.pcbridge.paper.core.libs.logger.log
import kotlinx.coroutines.Dispatchers
Expand Down
Loading

0 comments on commit 1daf491

Please sign in to comment.