Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin split #124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ plugins {

dependencies {
compileOnlyApi(libs.luckperms)
api(libs.anvil.velocity)
compileOnlyApi(platform(libs.adventure.bom))
compileOnlyApi("net.kyori:adventure-text-serializer-legacy")
compileOnlyApi("net.kyori:adventure-text-serializer-plain")
compileOnlyApi("net.kyori:adventure-text-minimessage")
api(libs.anvil.core)
api(libs.kotlinx.serialization)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package org.anvilpowered.catalyst.api.chat

import com.velocitypowered.api.proxy.Player
import org.anvilpowered.anvil.core.user.Player
import org.anvilpowered.catalyst.api.config.ChatChannel
import java.util.UUID

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

package org.anvilpowered.catalyst.api.user

import com.velocitypowered.api.proxy.Player
import org.anvilpowered.anvil.core.db.Creates
import org.anvilpowered.anvil.core.db.DomainEntity
import org.anvilpowered.anvil.core.user.Player
import java.util.UUID

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

package org.anvilpowered.catalyst.api.user

import com.velocitypowered.api.proxy.Player
import org.anvilpowered.anvil.core.db.MutableRepository
import org.anvilpowered.anvil.core.db.SizedIterable
import org.anvilpowered.anvil.core.user.Player
import java.util.UUID

interface MinecraftUserRepository : MutableRepository<MinecraftUser, MinecraftUser.CreateDto> {
Expand All @@ -37,5 +37,5 @@ interface MinecraftUserRepository : MutableRepository<MinecraftUser, MinecraftUs
}

suspend fun MinecraftUserRepository.getOnlineUser(player: Player): MinecraftUser.Online =
findById(player.uniqueId)?.let { MinecraftUser.Online(it, player) }
?: throw IllegalStateException("User ${player.username} with id ${player.uniqueId} is not in the database!")
findById(player.id)?.let { MinecraftUser.Online(it, player) }
?: throw IllegalStateException("User ${player.username} with id ${player.id} is not in the database!")
3 changes: 3 additions & 0 deletions app/breeze/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Catalyst Breeze

Catalyst Breeze is the deployment meant for a single velocity proxy with many backend servers behind it.
Empty file.
3 changes: 3 additions & 0 deletions app/breeze/core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
api(project(":catalyst-core"))
}
12 changes: 12 additions & 0 deletions app/breeze/proxy/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
kotlin("kapt")
}

dependencies {
api(project(":catalyst-app-breeze-core"))
api(project(":catalyst-velocity"))
api(project(":catalyst-core"))
api(project(":catalyst-core-chat"))
api(project(":catalyst-core-command"))
kapt(libs.velocity)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.anvilpowered.catalyst.proxy
package org.anvilpowered.catalyst.breeze.proxy

import org.anvilpowered.anvil.core.AnvilApi
import org.anvilpowered.anvil.core.config.KeyNamespace
import org.anvilpowered.anvil.core.config.Registry
import org.anvilpowered.anvil.core.config.configureDefaults
import org.anvilpowered.catalyst.api.chat.ChannelMessage
import org.anvilpowered.catalyst.api.chat.ChannelService
import org.anvilpowered.catalyst.api.chat.LuckpermsService
import org.anvilpowered.catalyst.api.chat.placeholder.BackendFormat
import org.anvilpowered.catalyst.api.chat.placeholder.ChannelMessageFormat
Expand All @@ -36,38 +34,15 @@ import org.anvilpowered.catalyst.api.chat.placeholder.PrivateMessageFormat
import org.anvilpowered.catalyst.api.chat.placeholder.ProxyFormat
import org.anvilpowered.catalyst.api.chat.placeholder.register
import org.anvilpowered.catalyst.api.config.CatalystKeys
import org.anvilpowered.catalyst.api.config.ChatChannel
import org.anvilpowered.catalyst.api.user.MinecraftUserRepository
import org.anvilpowered.catalyst.api.user.UserRepository
import org.anvilpowered.catalyst.proxy.chat.ChannelServiceImpl
import org.anvilpowered.catalyst.proxy.chat.ChannelSwitchFrontend
import org.anvilpowered.catalyst.proxy.chat.ChatFilter
import org.anvilpowered.catalyst.proxy.chat.ChatService
import org.anvilpowered.catalyst.proxy.chat.ChatServiceImpl
import org.anvilpowered.catalyst.proxy.chat.PrivateMessageService
import org.anvilpowered.catalyst.proxy.chat.StaffListService
import org.anvilpowered.catalyst.proxy.chat.builder.ChannelMessageBuilderImpl
import org.anvilpowered.catalyst.proxy.chat.builder.ChatChannelBuilderImpl
import org.anvilpowered.catalyst.proxy.command.CatalystCommandFactory
import org.anvilpowered.catalyst.proxy.command.broadcast.BroadcastCommandFactory
import org.anvilpowered.catalyst.proxy.command.channel.ChannelAliasCommandRegistrar
import org.anvilpowered.catalyst.proxy.command.channel.ChannelCommandFactory
import org.anvilpowered.catalyst.proxy.command.message.MessageCommandFactory
import org.anvilpowered.catalyst.proxy.command.message.ReplyCommandFactory
import org.anvilpowered.catalyst.proxy.command.nickname.NicknameCommandFactory
import org.anvilpowered.catalyst.proxy.db.user.MinecraftUserRepositoryImpl
import org.anvilpowered.catalyst.proxy.db.user.UserRepositoryImpl
import org.anvilpowered.catalyst.proxy.discord.JDAService
import org.anvilpowered.catalyst.proxy.discord.WebhookSender
import org.anvilpowered.catalyst.proxy.listener.ChatListener
import org.anvilpowered.catalyst.proxy.listener.CommandListener
import org.anvilpowered.catalyst.proxy.listener.DiscordListener
import org.anvilpowered.catalyst.proxy.listener.JoinListener
import org.anvilpowered.catalyst.proxy.listener.LeaveListener
import org.anvilpowered.catalyst.core.Registrar
import org.anvilpowered.catalyst.core.chat.bridge.discord.JDAService
import org.anvilpowered.catalyst.core.chat.bridge.discord.WebhookSender
import org.anvilpowered.catalyst.core.command.channel.ChannelAliasCommandRegistrar
import org.anvilpowered.catalyst.core.db.user.MinecraftUserRepositoryImpl
import org.anvilpowered.catalyst.core.db.user.UserRepositoryImpl
import org.anvilpowered.catalyst.proxy.registrar.CommandRegistrar
import org.anvilpowered.catalyst.proxy.registrar.ListenerRegistrar
import org.anvilpowered.catalyst.proxy.registrar.Registrar
import org.anvilpowered.catalyst.proxy.tab.GlobalTab
import org.koin.core.module.Module
import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.createdAtStart
Expand Down Expand Up @@ -99,23 +74,12 @@ fun CatalystApi.Companion.create(anvilApi: AnvilApi): CatalystApi {
Registry.configureDefaults(anvilApi, serializers)
singleOf(::LuckpermsService)
singleOf(::WebhookSender)
singleOf(::ChatFilter)
singleOf(ChatChannelBuilderImpl::Factory) { bind<ChatChannel.Builder.Factory>() }
singleOf(ChannelMessageBuilderImpl::Factory) { bind<ChannelMessage.Builder.Factory>() }
singleOf(::ChannelServiceImpl) { bind<ChannelService>() }
singleOf(::ChannelSwitchFrontend)
singleOf(::ChatServiceImpl) { bind<ChatService>() }
singleOf(::PrivateMessageService)
singleOf(::ChatListener)

singleOf(::CatalystKeys).withOptions {
bind<KeyNamespace>()
}
singleOf(::CommandListener)
singleOf(::JoinListener)
singleOf(::LeaveListener)
singleOf(::DiscordListener)

singleOf(::JDAService)
singleOf(::StaffListService)
singleOf(::MinecraftUserRepositoryImpl) { bind<MinecraftUserRepository>() }
singleOf(::UserRepositoryImpl) { bind<UserRepository>() }

Expand All @@ -132,13 +96,6 @@ fun CatalystApi.Companion.create(anvilApi: AnvilApi): CatalystApi {
createdAtStart()
}

singleOf(::BroadcastCommandFactory)
singleOf(::CatalystCommandFactory)
singleOf(::ChannelCommandFactory)
singleOf(::MessageCommandFactory)
singleOf(::NicknameCommandFactory)
singleOf(::ReplyCommandFactory)

singleOf(::CommandRegistrar) { bind<Registrar>() }
singleOf(::ListenerRegistrar) { bind<Registrar>() }
singleOf(::ChannelAliasCommandRegistrar) { bind<Registrar>() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.anvilpowered.catalyst.proxy
package org.anvilpowered.catalyst.breeze.proxy

import com.google.inject.Inject
import com.google.inject.Injector
Expand All @@ -26,19 +26,20 @@ import com.velocitypowered.api.plugin.Dependency
import com.velocitypowered.api.plugin.Plugin
import org.anvilpowered.anvil.core.AnvilApi
import org.anvilpowered.anvil.velocity.createVelocity
import org.anvilpowered.catalyst.core.CatalystPlugin
import org.koin.dsl.koinApplication
import org.koin.dsl.module

@Plugin(
id = "catalyst",
name = "Catalyst",
id = "catalyst-breeze",
name = "Catalyst Breeze",
version = "0.4.0-SNAPSHOT",
authors = ["AnvilPowered"],
dependencies = [Dependency(id = "luckperms")],
)
class CatalystVelocityBootstrap @Inject constructor(private val injector: Injector) {

private lateinit var plugin: CatalystVelocityPlugin
private lateinit var plugin: CatalystPlugin

@Subscribe
fun onInit(event: ProxyInitializeEvent) {
Expand All @@ -47,7 +48,7 @@ class CatalystVelocityBootstrap @Inject constructor(private val injector: Inject
modules(
anvilApi.module,
CatalystApi.create(anvilApi).module,
module { single { CatalystVelocityPlugin(get(), get(), get(), getAll()) } },
module { single { CatalystPlugin(get(), get(), get(), getAll()) } },
)
}.koin.get()
plugin.initialize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.anvilpowered.catalyst.proxy.tab
package org.anvilpowered.catalyst.breeze.proxy

import com.velocitypowered.api.plugin.PluginContainer
import com.velocitypowered.api.proxy.ProxyServer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.anvilpowered.catalyst.proxy.registrar
package org.anvilpowered.catalyst.breeze.proxy

import com.velocitypowered.api.plugin.PluginContainer
import com.velocitypowered.api.proxy.ProxyServer
import org.anvilpowered.catalyst.core.Registrar
import org.anvilpowered.catalyst.proxy.listener.ChatListener
import org.anvilpowered.catalyst.proxy.listener.CommandListener
import org.anvilpowered.catalyst.proxy.listener.DiscordListener
Expand Down
3 changes: 3 additions & 0 deletions app/cyclone/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Catalyst Cyclone

Catalyst Cyclone is a deployment meant for large networks and supports redundancy and high availability.
4 changes: 4 additions & 0 deletions app/droplet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Catalyst Droplet

Catalyst Droplet is the deployment meant for single backend servers without a proxy.
It is the simplest Catalyst deployment and does not support redundancy.
5 changes: 5 additions & 0 deletions app/droplet/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// for uber jar
dependencies {
runtimeOnly(project(":catalyst-app-droplet-paper"))
runtimeOnly(project(":catalyst-app-droplet-sponge"))
}
2 changes: 2 additions & 0 deletions app/droplet/core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dependencies {
}
6 changes: 0 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,8 @@ allprojects {
}
}

// for uber jar
dependencies {
runtimeOnly(project(":catalyst-proxy"))
}

tasks {
shadowJar {
archiveFileName = "catalyst-${project.version}.jar"

mergeServiceFiles()

Expand Down
5 changes: 5 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ dependencies {
exclude(group = "org.slf4j")
}
runtimeOnly(libs.driver.postgresql)

api(platform(libs.exposed.bom))
api(libs.bundles.exposed) {
exclude(group = "org.slf4j")
}
}
9 changes: 9 additions & 0 deletions core/chat/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies {
api(project(":catalyst-core"))
implementation(libs.discord.jda) {
exclude(group = "org.slf4j")
}
implementation(libs.discord.webhooks) {
exclude(group = "org.slf4j")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.anvilpowered.catalyst.proxy.chat
package org.anvilpowered.catalyst.core.chat

import com.velocitypowered.api.permission.Tristate
import com.velocitypowered.api.proxy.Player
import com.velocitypowered.api.proxy.ProxyServer
import org.anvilpowered.anvil.core.config.Registry
import org.anvilpowered.anvil.core.user.Player
import org.anvilpowered.anvil.core.user.PlayerService
import org.anvilpowered.catalyst.api.chat.ChannelService
import org.anvilpowered.catalyst.api.config.CatalystKeys
import org.anvilpowered.catalyst.api.config.ChatChannel
import java.util.UUID

class ChannelServiceImpl(
private val registry: Registry,
private val proxyServer: ProxyServer,
private val playerService: PlayerService,
private val catalystKeys: CatalystKeys,
) : ChannelService {

Expand Down Expand Up @@ -62,17 +61,17 @@ class ChannelServiceImpl(
override fun getReceivers(channelId: String): Sequence<Player> {
// TODO: Optimize by not recalculating on each chat message
val channel = checkNotNull(get(channelId)) { "Channel $channelId does not exist" }
return proxyServer.allPlayers.asSequence()
.filter { getForPlayer(it.uniqueId).id == channelId || (it.canAccess(channel) && channel.alwaysVisible) }
return playerService.getAll()
.filter { getForPlayer(it.id).id == channelId || (it.canAccess(channel) && channel.alwaysVisible) }
}

override fun switch(userUUID: UUID, channelId: String) {
playerChannelMapping[userUUID] = channelId
}

private fun Player.canAccess(channel: ChatChannel): Boolean {
val permissionValue = getPermissionValue("${registry[catalystKeys.PERMISSION_CHANNEL_PREFIX]}.${channel.id}")
return permissionValue == Tristate.TRUE ||
(channel.availableByDefault && permissionValue != Tristate.FALSE)
val permissionValue = hasPermission("${registry[catalystKeys.PERMISSION_CHANNEL_PREFIX]}.${channel.id}")
return permissionValue == true ||
(channel.availableByDefault && permissionValue != false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.anvilpowered.catalyst.proxy.chat
package org.anvilpowered.catalyst.core.chat

import net.kyori.adventure.text.Component
import org.anvilpowered.anvil.core.config.Registry
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Catalyst - AnvilPowered.org
* Copyright (C) 2019-2024 Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.anvilpowered.catalyst.core.chat

import org.anvilpowered.catalyst.api.chat.ChannelMessage
import org.anvilpowered.catalyst.api.chat.ChannelService
import org.anvilpowered.catalyst.api.config.ChatChannel
import org.anvilpowered.catalyst.core.chat.builder.ChannelMessageBuilderImpl
import org.anvilpowered.catalyst.core.chat.builder.ChatChannelBuilderImpl
import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module

val ChatModule = module {
singleOf(::ChatFilter)
singleOf(ChannelMessageBuilderImpl::Factory) { bind<ChannelMessage.Builder.Factory>() }
singleOf(ChatChannelBuilderImpl::Factory) { bind<ChatChannel.Builder.Factory>() }
singleOf(::ChannelServiceImpl) { bind<ChannelService>() }
singleOf(::ChatServiceImpl) { bind<ChatService>() }
singleOf(::PrivateMessageService)
singleOf(::StaffListService)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.anvilpowered.catalyst.proxy.chat
package org.anvilpowered.catalyst.core.chat

import com.velocitypowered.api.proxy.Player
import net.kyori.adventure.text.Component
import org.anvilpowered.anvil.core.user.Player
import org.anvilpowered.catalyst.api.chat.ChannelMessage
import java.util.UUID

Expand Down
Loading