diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 8cf5202f..59a12f4d 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -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) } diff --git a/api/src/main/kotlin/org/anvilpowered/catalyst/api/chat/ChannelService.kt b/api/src/main/kotlin/org/anvilpowered/catalyst/api/chat/ChannelService.kt index 83253802..cc52cb77 100644 --- a/api/src/main/kotlin/org/anvilpowered/catalyst/api/chat/ChannelService.kt +++ b/api/src/main/kotlin/org/anvilpowered/catalyst/api/chat/ChannelService.kt @@ -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 diff --git a/api/src/main/kotlin/org/anvilpowered/catalyst/api/user/MinecraftUser.kt b/api/src/main/kotlin/org/anvilpowered/catalyst/api/user/MinecraftUser.kt index ef37e24c..591db811 100644 --- a/api/src/main/kotlin/org/anvilpowered/catalyst/api/user/MinecraftUser.kt +++ b/api/src/main/kotlin/org/anvilpowered/catalyst/api/user/MinecraftUser.kt @@ -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 /** diff --git a/api/src/main/kotlin/org/anvilpowered/catalyst/api/user/MinecraftUserRepository.kt b/api/src/main/kotlin/org/anvilpowered/catalyst/api/user/MinecraftUserRepository.kt index 95c362dc..7aaca196 100644 --- a/api/src/main/kotlin/org/anvilpowered/catalyst/api/user/MinecraftUserRepository.kt +++ b/api/src/main/kotlin/org/anvilpowered/catalyst/api/user/MinecraftUserRepository.kt @@ -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 { @@ -37,5 +37,5 @@ interface MinecraftUserRepository : MutableRepository. */ -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 @@ -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 @@ -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() } - singleOf(ChannelMessageBuilderImpl::Factory) { bind() } - singleOf(::ChannelServiceImpl) { bind() } - singleOf(::ChannelSwitchFrontend) - singleOf(::ChatServiceImpl) { bind() } - singleOf(::PrivateMessageService) - singleOf(::ChatListener) + singleOf(::CatalystKeys).withOptions { bind() } - singleOf(::CommandListener) - singleOf(::JoinListener) - singleOf(::LeaveListener) - singleOf(::DiscordListener) + singleOf(::JDAService) - singleOf(::StaffListService) singleOf(::MinecraftUserRepositoryImpl) { bind() } singleOf(::UserRepositoryImpl) { bind() } @@ -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() } singleOf(::ListenerRegistrar) { bind() } singleOf(::ChannelAliasCommandRegistrar) { bind() } diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/CatalystVelocityBootstrap.kt b/app/breeze/proxy/src/main/kotlin/org/anvilpowered/catalyst/breeze/proxy/CatalystVelocityBootstrap.kt similarity index 85% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/CatalystVelocityBootstrap.kt rename to app/breeze/proxy/src/main/kotlin/org/anvilpowered/catalyst/breeze/proxy/CatalystVelocityBootstrap.kt index 99473f46..631e16cc 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/CatalystVelocityBootstrap.kt +++ b/app/breeze/proxy/src/main/kotlin/org/anvilpowered/catalyst/breeze/proxy/CatalystVelocityBootstrap.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy +package org.anvilpowered.catalyst.breeze.proxy import com.google.inject.Inject import com.google.inject.Injector @@ -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) { @@ -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() diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/tab/GlobalTab.kt b/app/breeze/proxy/src/main/kotlin/org/anvilpowered/catalyst/breeze/proxy/GlobalTab.kt similarity index 98% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/tab/GlobalTab.kt rename to app/breeze/proxy/src/main/kotlin/org/anvilpowered/catalyst/breeze/proxy/GlobalTab.kt index 9f2f16ef..3def6782 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/tab/GlobalTab.kt +++ b/app/breeze/proxy/src/main/kotlin/org/anvilpowered/catalyst/breeze/proxy/GlobalTab.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.tab +package org.anvilpowered.catalyst.breeze.proxy import com.velocitypowered.api.plugin.PluginContainer import com.velocitypowered.api.proxy.ProxyServer diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/registrar/ListenerRegistrar.kt b/app/breeze/proxy/src/main/kotlin/org/anvilpowered/catalyst/breeze/proxy/ListenerRegistrar.kt similarity index 95% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/registrar/ListenerRegistrar.kt rename to app/breeze/proxy/src/main/kotlin/org/anvilpowered/catalyst/breeze/proxy/ListenerRegistrar.kt index dbea8af9..b7ba00e3 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/registrar/ListenerRegistrar.kt +++ b/app/breeze/proxy/src/main/kotlin/org/anvilpowered/catalyst/breeze/proxy/ListenerRegistrar.kt @@ -16,10 +16,11 @@ * along with this program. If not, see . */ -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 diff --git a/app/cyclone/README.md b/app/cyclone/README.md new file mode 100644 index 00000000..635418d2 --- /dev/null +++ b/app/cyclone/README.md @@ -0,0 +1,3 @@ +# Catalyst Cyclone + +Catalyst Cyclone is a deployment meant for large networks and supports redundancy and high availability. diff --git a/app/droplet/README.md b/app/droplet/README.md new file mode 100644 index 00000000..82ba9de1 --- /dev/null +++ b/app/droplet/README.md @@ -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. diff --git a/app/droplet/build.gradle.kts b/app/droplet/build.gradle.kts new file mode 100644 index 00000000..c4dcb35b --- /dev/null +++ b/app/droplet/build.gradle.kts @@ -0,0 +1,5 @@ +// for uber jar +dependencies { + runtimeOnly(project(":catalyst-app-droplet-paper")) + runtimeOnly(project(":catalyst-app-droplet-sponge")) +} diff --git a/app/droplet/core/build.gradle.kts b/app/droplet/core/build.gradle.kts new file mode 100644 index 00000000..7d82dc72 --- /dev/null +++ b/app/droplet/core/build.gradle.kts @@ -0,0 +1,2 @@ +dependencies { +} diff --git a/build.gradle.kts b/build.gradle.kts index 6c7c5958..6b2f4f4c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -51,14 +51,8 @@ allprojects { } } -// for uber jar -dependencies { - runtimeOnly(project(":catalyst-proxy")) -} - tasks { shadowJar { - archiveFileName = "catalyst-${project.version}.jar" mergeServiceFiles() diff --git a/core/build.gradle.kts b/core/build.gradle.kts index df908bdc..039bc787 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -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") + } } diff --git a/core/chat/build.gradle.kts b/core/chat/build.gradle.kts new file mode 100644 index 00000000..c22e9bc1 --- /dev/null +++ b/core/chat/build.gradle.kts @@ -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") + } +} diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChannelServiceImpl.kt b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChannelServiceImpl.kt similarity index 80% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChannelServiceImpl.kt rename to core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChannelServiceImpl.kt index 633232f0..9bf01fc8 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChannelServiceImpl.kt +++ b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChannelServiceImpl.kt @@ -16,12 +16,11 @@ * along with this program. If not, see . */ -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 @@ -29,7 +28,7 @@ import java.util.UUID class ChannelServiceImpl( private val registry: Registry, - private val proxyServer: ProxyServer, + private val playerService: PlayerService, private val catalystKeys: CatalystKeys, ) : ChannelService { @@ -62,8 +61,8 @@ class ChannelServiceImpl( override fun getReceivers(channelId: String): Sequence { // 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) { @@ -71,8 +70,8 @@ class ChannelServiceImpl( } 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) } } diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChatFilter.kt b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChatFilter.kt similarity index 98% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChatFilter.kt rename to core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChatFilter.kt index 63e8ae04..963db8bf 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChatFilter.kt +++ b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChatFilter.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -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 diff --git a/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChatModule.kt b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChatModule.kt new file mode 100644 index 00000000..959b5044 --- /dev/null +++ b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChatModule.kt @@ -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 . + */ + +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() } + singleOf(ChatChannelBuilderImpl::Factory) { bind() } + singleOf(::ChannelServiceImpl) { bind() } + singleOf(::ChatServiceImpl) { bind() } + singleOf(::PrivateMessageService) + singleOf(::StaffListService) +} diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChatService.kt b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChatService.kt similarity index 93% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChatService.kt rename to core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChatService.kt index 68272b5f..a602d8d3 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChatService.kt +++ b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChatService.kt @@ -16,10 +16,10 @@ * along with this program. If not, see . */ -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 diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChatServiceImpl.kt b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChatServiceImpl.kt similarity index 77% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChatServiceImpl.kt rename to core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChatServiceImpl.kt index 30394425..f7b21948 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChatServiceImpl.kt +++ b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/ChatServiceImpl.kt @@ -16,25 +16,22 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.chat +package org.anvilpowered.catalyst.core.chat -import com.velocitypowered.api.proxy.Player -import com.velocitypowered.api.proxy.ProxyServer import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.NamedTextColor import org.anvilpowered.anvil.core.config.Registry +import org.anvilpowered.anvil.core.user.Player +import org.anvilpowered.anvil.core.user.PlayerService +import org.anvilpowered.anvil.core.user.hasPermissionSet 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.PlayerFormat import org.anvilpowered.catalyst.api.config.CatalystKeys -import org.apache.logging.log4j.Logger import java.util.UUID class ChatServiceImpl( - private val proxyServer: ProxyServer, - private val logger: Logger, - private val luckpermsService: LuckpermsService, + private val playerService: PlayerService, private val registry: Registry, private val catalystKeys: CatalystKeys, private val channelService: ChannelService, @@ -44,17 +41,18 @@ class ChatServiceImpl( private var disabledList = mutableListOf() override suspend fun sendMessage(message: ChannelMessage.Resolved) { - proxyServer.consoleCommandSource.sendMessage(message.formatted.format) // won't resolve 'recipient.*' placeholders + // TODO: Log to each console? +// playerService.consoleCommandSource.sendMessage(message.formatted.format) // won't resolve 'recipient.*' placeholders val channelId = message.backing.channel.id - val sourceUserId = message.backing.source.player.uniqueId + val sourceUserId = message.backing.source.player.id - val spyAllPlayers = proxyServer.allPlayers - .filter { it.hasPermission(registry[catalystKeys.PERMISSION_CHANNEL_SPYALL]) } + val spyAllPlayers = playerService.getAll() + .filter { it.hasPermissionSet(registry[catalystKeys.PERMISSION_CHANNEL_SPYALL]) } .toMutableList() channelService.getReceivers(channelId) - .filterNot { isIgnored(it.uniqueId, sourceUserId) } + .filterNot { isIgnored(it.id, sourceUserId) } .onEach { spyAllPlayers.remove(it) } .forEach { player -> player.sendMessage(playerFormatResolver.resolve(message.formatted, player)) } @@ -69,7 +67,7 @@ class ChatServiceImpl( } override fun ignore(playerUUID: UUID, targetPlayerUUID: UUID): Component { - val targetPlayer = proxyServer.getPlayer(targetPlayerUUID).orElse(null) ?: return Component.text("That user does not exist!") + val targetPlayer = playerService[targetPlayerUUID] ?: return Component.text("That user does not exist!") .color(NamedTextColor.RED) var uuidList: MutableList = ArrayList() if (ignoreMap[playerUUID] == null) { @@ -94,7 +92,7 @@ class ChatServiceImpl( } // TODO: What if the player leaves after being ignored? return Component.text("You are no longer ignoring").append( - Component.text(proxyServer.getPlayer(targetPlayerUUID).map { it.username }.orElse(targetPlayerUUID.toString())) + Component.text(playerService[targetPlayerUUID]?.username ?: targetPlayerUUID.toString()) .color(NamedTextColor.GREEN), ) } @@ -105,7 +103,7 @@ class ChatServiceImpl( } override fun highlightPlayerNames(sender: Player, message: Component): Component { - return proxyServer.allPlayers.map { it.username }.fold(message) { msg, username -> + return playerService.getAll().map { it.username }.fold(message) { msg, username -> msg.replaceText { it.match(username) it.replacement(Component.text("@$username").color(NamedTextColor.AQUA)) @@ -115,14 +113,14 @@ class ChatServiceImpl( } override fun toggleChatForPlayer(player: Player) { - if (!disabledList.contains(player.uniqueId)) { - disabledList.add(player.uniqueId) + if (!disabledList.contains(player.id)) { + disabledList.add(player.id) return } - disabledList.remove(player.uniqueId) + disabledList.remove(player.id) } override fun isDisabledForPlayer(player: Player): Boolean { - return disabledList.contains(player.uniqueId) + return disabledList.contains(player.id) } } diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/PrivateMessageService.kt b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/PrivateMessageService.kt similarity index 78% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/PrivateMessageService.kt rename to core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/PrivateMessageService.kt index 8aafd3f3..8a296b60 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/PrivateMessageService.kt +++ b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/PrivateMessageService.kt @@ -16,13 +16,14 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.chat +package org.anvilpowered.catalyst.core.chat -import com.velocitypowered.api.proxy.Player -import com.velocitypowered.api.proxy.ProxyServer import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.NamedTextColor import org.anvilpowered.anvil.core.config.Registry +import org.anvilpowered.anvil.core.user.Player +import org.anvilpowered.anvil.core.user.PlayerService +import org.anvilpowered.anvil.core.user.hasPermissionSet import org.anvilpowered.catalyst.api.chat.LuckpermsService import org.anvilpowered.catalyst.api.chat.PrivateMessage import org.anvilpowered.catalyst.api.chat.placeholder.PrivateMessageFormat @@ -33,10 +34,10 @@ import org.apache.logging.log4j.Logger import java.util.UUID class PrivateMessageService( - private val proxyServer: ProxyServer, private val registry: Registry, private val catalystKeys: CatalystKeys, private val logger: Logger, + private val playerService: PlayerService, private val luckpermsService: LuckpermsService, private val minecraftUserRepository: MinecraftUserRepository, private val privateMessageFormatResolver: PrivateMessageFormat.Resolver, @@ -44,29 +45,29 @@ class PrivateMessageService( private var replyMap = mutableMapOf() suspend fun sendMessage(source: Player, recipient: Player, content: Component) { - val sourceUser = minecraftUserRepository.findById(source.uniqueId)?.let { MinecraftUser.Online(it, source) } - ?: throw IllegalStateException("User ${source.username} with id ${source.uniqueId} is not in the database!") + val sourceUser = minecraftUserRepository.findById(source.id)?.let { MinecraftUser.Online(it, source) } + ?: throw IllegalStateException("User ${source.username} with id ${source.id} is not in the database!") - val recipientUser = minecraftUserRepository.findById(recipient.uniqueId)?.let { MinecraftUser.Online(it, recipient) } - ?: throw IllegalStateException("User ${recipient.username} with id ${recipient.uniqueId} is not in the database!") + val recipientUser = minecraftUserRepository.findById(recipient.id)?.let { MinecraftUser.Online(it, recipient) } + ?: throw IllegalStateException("User ${recipient.username} with id ${recipient.id} is not in the database!") val message = PrivateMessage(sourceUser, recipientUser, content) source.sendMessage(privateMessageFormatResolver.resolve(registry[catalystKeys.CHAT_DM_FORMAT_SOURCE], message)) recipient.sendMessage(privateMessageFormatResolver.resolve(registry[catalystKeys.CHAT_DM_FORMAT_RECIPIENT], message)) - replyMap[recipient.uniqueId] = source.uniqueId - replyMap[source.uniqueId] = recipient.uniqueId + replyMap[recipient.id] = source.id + replyMap[source.id] = recipient.id socialSpy(message) } suspend fun reply(source: Player, content: Component) { - val recipientId = replyMap[source.uniqueId] + val recipientId = replyMap[source.id] if (recipientId == null) { source.sendMessage(Component.text("No person to reply to.").color(NamedTextColor.RED)) return } - val recipient = proxyServer.getPlayer(recipientId).orElse(null) + val recipient = playerService[recipientId] if (recipient == null) { source.sendMessage(Component.text("The person you last replied to is offline.").color(NamedTextColor.RED)) return @@ -79,9 +80,9 @@ class PrivateMessageService( private suspend fun socialSpy(message: PrivateMessage) { val socialSpyMessage = privateMessageFormatResolver.resolve(registry[catalystKeys.CHAT_DM_FORMAT_SOCIALSPY], message) - proxyServer.allPlayers - .filter { it.hasPermission(registry[catalystKeys.PERMISSION_SOCIALSPY_BASE]) } - .filter { it.uniqueId != message.source.player.uniqueId && it.uniqueId != message.recipient.player.uniqueId } + playerService.getAll() + .filter { it.hasPermissionSet(registry[catalystKeys.PERMISSION_SOCIALSPY_BASE]) } + .filter { it.id != message.source.player.id && it.id != message.recipient.player.id } .forEach { it.sendMessage(socialSpyMessage) } } } diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/StaffListService.kt b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/StaffListService.kt similarity index 80% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/StaffListService.kt rename to core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/StaffListService.kt index dac23a8d..adbe66c0 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/StaffListService.kt +++ b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/StaffListService.kt @@ -16,19 +16,20 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.chat +package org.anvilpowered.catalyst.core.chat -import com.velocitypowered.api.proxy.ProxyServer import net.kyori.adventure.text.Component import org.anvilpowered.anvil.core.config.Registry +import org.anvilpowered.anvil.core.user.PlayerService +import org.anvilpowered.anvil.core.user.hasPermissionSet import org.anvilpowered.catalyst.api.config.CatalystKeys import java.util.concurrent.Executors import java.util.concurrent.TimeUnit class StaffListService( - private val proxyServer: ProxyServer, private val registry: Registry, private val catalystKeys: CatalystKeys, + private val playerService: PlayerService, ) { init { @@ -57,12 +58,13 @@ class StaffListService( } private fun update() { - for (player in proxyServer.allPlayers) { + // TODO: Revise and make sure no duplicates occur + playerService.getAll().forEach { player -> getStaffNames( player.username, - player.hasPermission(registry[catalystKeys.PERMISSION_STAFFLIST_ADMIN]), - player.hasPermission(registry[catalystKeys.PERMISSION_STAFFLIST_STAFF]), - player.hasPermission(registry[catalystKeys.PERMISSION_STAFFLIST_OWNER]), + player.hasPermissionSet(registry[catalystKeys.PERMISSION_STAFFLIST_ADMIN]), + player.hasPermissionSet(registry[catalystKeys.PERMISSION_STAFFLIST_STAFF]), + player.hasPermissionSet(registry[catalystKeys.PERMISSION_STAFFLIST_OWNER]), ) } } diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/discord/DiscordCommandSource.kt b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/bridge/discord/DiscordCommandSource.kt similarity index 84% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/discord/DiscordCommandSource.kt rename to core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/bridge/discord/DiscordCommandSource.kt index c737a9fb..e282715b 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/discord/DiscordCommandSource.kt +++ b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/bridge/discord/DiscordCommandSource.kt @@ -16,21 +16,23 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.discord +package org.anvilpowered.catalyst.core.chat.bridge.discord -import com.velocitypowered.api.command.CommandSource -import com.velocitypowered.api.permission.Tristate import net.dv8tion.jda.api.JDA import net.kyori.adventure.text.Component import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer +import org.anvilpowered.anvil.core.command.CommandSource +import org.anvilpowered.anvil.core.user.Player internal class DiscordCommandSource( private val jda: JDA, private val discordChannelId: String, ) : CommandSource { + override val platformDelegate: Any = error("No platform delegate") + override val player: Player? = null + override fun hasPermission(permission: String): Boolean = true - override fun getPermissionValue(permission: String): Tristate = Tristate.TRUE override fun sendMessage(message: Component) { val channel = jda.getTextChannelById(discordChannelId) diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/DiscordListener.kt b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/bridge/discord/DiscordListener.kt similarity index 91% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/DiscordListener.kt rename to core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/bridge/discord/DiscordListener.kt index ae56f7af..5f276178 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/DiscordListener.kt +++ b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/bridge/discord/DiscordListener.kt @@ -16,9 +16,8 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.listener +package org.anvilpowered.catalyst.core.chat.bridge.discord -import com.velocitypowered.api.proxy.ProxyServer import kotlinx.coroutines.runBlocking import net.dv8tion.jda.api.Permission import net.dv8tion.jda.api.events.message.MessageReceivedEvent @@ -29,19 +28,17 @@ import net.kyori.adventure.text.event.HoverEvent import org.anvilpowered.anvil.core.command.CommandExecutor import org.anvilpowered.anvil.core.command.withLogging import org.anvilpowered.anvil.core.config.Registry -import org.anvilpowered.anvil.velocity.command.toAnvilCommandSource +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.proxy.discord.DiscordCommandSource -import org.anvilpowered.catalyst.proxy.discord.JDAService import org.apache.logging.log4j.Logger // No DI class DiscordListener( - private val proxyServer: ProxyServer, private val registry: Registry, private val catalystKeys: CatalystKeys, private val logger: Logger, + private val playerService: PlayerService, private val channelService: ChannelService, private val jdaService: JDAService, commandExecutor: CommandExecutor, @@ -66,13 +63,13 @@ class DiscordListener( DiscordCommandSource( checkNotNull(jdaService.jda) { "JDA is not initialized" }, event.channel.id, - ).toAnvilCommandSource(), + ), command, ) } return } else if (messageRaw.startsWith("!list")) { - val onlinePlayers = proxyServer.allPlayers + val onlinePlayers = playerService.getAll().toList() val playerNames: String = if (onlinePlayers.isEmpty()) { "```There are currently no players online!```" } else { diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/discord/JDAService.kt b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/bridge/discord/JDAService.kt similarity index 93% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/discord/JDAService.kt rename to core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/bridge/discord/JDAService.kt index fcf266fe..a549a16a 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/discord/JDAService.kt +++ b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/bridge/discord/JDAService.kt @@ -15,9 +15,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.discord +package org.anvilpowered.catalyst.core.chat.bridge.discord -import com.velocitypowered.api.proxy.ProxyServer import net.dv8tion.jda.api.JDA import net.dv8tion.jda.api.JDABuilder import net.dv8tion.jda.api.entities.Activity @@ -26,19 +25,19 @@ import net.dv8tion.jda.api.utils.Compression import net.dv8tion.jda.api.utils.cache.CacheFlag import org.anvilpowered.anvil.core.command.CommandExecutor import org.anvilpowered.anvil.core.config.Registry +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.proxy.listener.DiscordListener import org.apache.logging.log4j.Logger import java.util.concurrent.Executors import java.util.concurrent.TimeUnit import javax.security.auth.login.LoginException class JDAService( - private val proxyServer: ProxyServer, private val registry: Registry, private val catalystKeys: CatalystKeys, private val logger: Logger, + private val playerService: PlayerService, private val channelService: ChannelService, private val commandExecutor: CommandExecutor, ) { @@ -71,7 +70,7 @@ class JDAService( e.printStackTrace() } val nowPlaying = registry[catalystKeys.CHAT_DISCORD_BOT_STATUS] - val playerCount = proxyServer.playerCount.let { count -> + val playerCount = playerService.getAll().count().let { count -> if (count == 0) { registry[catalystKeys.CHAT_DISCORD_TOPIC_NOPLAYERS] } else { @@ -106,7 +105,7 @@ class JDAService( return Runnable { val channel = jda!!.getTextChannelById(channelService.get(channelId)?.discordChannelId ?: "") val nowPlaying = registry[catalystKeys.CHAT_DISCORD_BOT_STATUS] - val playerCount = proxyServer.playerCount.let { count -> + val playerCount = playerService.count().let { count -> if (count == 0) { registry[catalystKeys.CHAT_DISCORD_TOPIC_NOPLAYERS] } else { @@ -129,10 +128,10 @@ class JDAService( private fun createListener(): DiscordListener { return DiscordListener( - proxyServer, registry, catalystKeys, logger, + playerService, channelService, this, commandExecutor, diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/discord/WebhookSender.kt b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/bridge/discord/WebhookSender.kt similarity index 95% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/discord/WebhookSender.kt rename to core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/bridge/discord/WebhookSender.kt index cbe13119..9aa4ea83 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/discord/WebhookSender.kt +++ b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/bridge/discord/WebhookSender.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.discord +package org.anvilpowered.catalyst.core.chat.bridge.discord import club.minnced.discord.webhook.WebhookClient import club.minnced.discord.webhook.WebhookClientBuilder @@ -39,7 +39,7 @@ class WebhookSender( suspend fun sendChannelMessage(user: MinecraftUser.Online, content: Component, discordChannelId: String) { val client = getWebhookClient(discordChannelId) val builder = WebhookMessageBuilder() - builder.setAvatarUrl(registry[catalystKeys.CHAT_DISCORD_BOT_AVATAR].replace("%uuid%", user.player.uniqueId.toString())) + builder.setAvatarUrl(registry[catalystKeys.CHAT_DISCORD_BOT_AVATAR].replace("%uuid%", user.player.id.toString())) builder.setUsername( PlainTextComponentSerializer.plainText() .serialize(onlineUserFormatResolver.resolve(registry[catalystKeys.CHAT_DISCORD_USERNAME_FORMAT], user)), @@ -56,7 +56,7 @@ class WebhookSender( ) { val client = getWebhookClient(discordChannelId) val builder = WebhookMessageBuilder() - builder.setAvatarUrl(registry[catalystKeys.CHAT_DISCORD_BOT_AVATAR].replace("%uuid%", user.player.uniqueId.toString())) + builder.setAvatarUrl(registry[catalystKeys.CHAT_DISCORD_BOT_AVATAR].replace("%uuid%", user.player.id.toString())) builder.setUsername("System") builder.setContent( PlainTextComponentSerializer.plainText() diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/builder/ChannelMessageBuilderImpl.kt b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/builder/ChannelMessageBuilderImpl.kt similarity index 85% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/builder/ChannelMessageBuilderImpl.kt rename to core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/builder/ChannelMessageBuilderImpl.kt index 19cf8477..f717eb20 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/builder/ChannelMessageBuilderImpl.kt +++ b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/builder/ChannelMessageBuilderImpl.kt @@ -16,11 +16,11 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.chat.builder +package org.anvilpowered.catalyst.core.chat.builder -import com.velocitypowered.api.proxy.Player -import com.velocitypowered.api.proxy.ProxyServer import net.kyori.adventure.text.Component +import org.anvilpowered.anvil.core.user.Player +import org.anvilpowered.anvil.core.user.PlayerService import org.anvilpowered.catalyst.api.chat.ChannelMessage import org.anvilpowered.catalyst.api.chat.ChannelService import org.anvilpowered.catalyst.api.chat.LuckpermsService @@ -33,8 +33,8 @@ import org.apache.logging.log4j.Logger import java.util.UUID internal class ChannelMessageBuilderImpl( - private val proxyServer: ProxyServer, private val logger: Logger, + private val playerService: PlayerService, private val luckpermsService: LuckpermsService, private val minecraftUserRepository: MinecraftUserRepository, private val channelService: ChannelService, @@ -48,8 +48,8 @@ internal class ChannelMessageBuilderImpl( private var rawContent: Component? = null override fun user(user: MinecraftUser): ChannelMessage.Builder { - player = proxyServer.getPlayer(user.uuid) - .orElseThrow { IllegalStateException("User ${user.username} with id ${user.uuid} is not on the server!") } + player = playerService[user.uuid] + ?: error("User ${user.username} with id ${user.uuid} is not on the server!") this.user = user return this } @@ -63,7 +63,7 @@ internal class ChannelMessageBuilderImpl( } override suspend fun channelId(channelId: String): ChannelMessage.Builder = - channel(requireNotNull(channelService.get(channelId)) { "Could not find channel with id $channelId" }) + channel(requireNotNull(channelService[channelId]) { "Could not find channel with id $channelId" }) override fun rawContent(rawContent: Component): ChannelMessage.Builder { this.rawContent = rawContent @@ -77,12 +77,12 @@ internal class ChannelMessageBuilderImpl( val rawContent = requireNotNull(rawContent) { "Content is null" } val name = onlineUserFormatResolver.resolve( - format = luckpermsService.nameFormat(player.uniqueId, channel.id) ?: channel.nameFormat, + format = luckpermsService.nameFormat(player.id, channel.id) ?: channel.nameFormat, MinecraftUser.Online(user, player), ) val content = messageContentFormatResolver.resolve( - format = luckpermsService.getMessageContentFormat(player.uniqueId, channel.id) ?: channel.contentFormat, + format = luckpermsService.getMessageContentFormat(player.id, channel.id) ?: channel.contentFormat, rawContent, ) @@ -90,8 +90,8 @@ internal class ChannelMessageBuilderImpl( } class Factory( - private val proxyServer: ProxyServer, private val logger: Logger, + private val playerService: PlayerService, private val luckpermsService: LuckpermsService, private val minecraftUserRepository: MinecraftUserRepository, private val channelService: ChannelService, @@ -99,8 +99,8 @@ internal class ChannelMessageBuilderImpl( private val messageContentFormatResolver: MessageContentFormat.Resolver, ) : ChannelMessage.Builder.Factory { override fun builder(): ChannelMessage.Builder = ChannelMessageBuilderImpl( - proxyServer, logger, + playerService, luckpermsService, minecraftUserRepository, channelService, diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/builder/ChatChannelBuilderImpl.kt b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/builder/ChatChannelBuilderImpl.kt similarity index 98% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/builder/ChatChannelBuilderImpl.kt rename to core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/builder/ChatChannelBuilderImpl.kt index a5c44251..24f7e1d6 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/builder/ChatChannelBuilderImpl.kt +++ b/core/chat/src/main/kotlin/org/anvilpowered/catalyst/core/chat/builder/ChatChannelBuilderImpl.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.chat.builder +package org.anvilpowered.catalyst.core.chat.builder import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.NamedTextColor diff --git a/core/command/build.gradle.kts b/core/command/build.gradle.kts new file mode 100644 index 00000000..6f613b80 --- /dev/null +++ b/core/command/build.gradle.kts @@ -0,0 +1,4 @@ +dependencies { + api(project(":catalyst-core")) + api(project(":catalyst-core-chat")) +} diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/CatalystCommandFactory.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/CatalystCommandFactory.kt similarity index 93% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/CatalystCommandFactory.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/CatalystCommandFactory.kt index 5147605e..2f515094 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/CatalystCommandFactory.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/CatalystCommandFactory.kt @@ -1,4 +1,4 @@ -package org.anvilpowered.catalyst.proxy.command +package org.anvilpowered.catalyst.core.command import com.velocitypowered.api.command.CommandSource import org.anvilpowered.anvil.core.command.config.ConfigCommandFactory diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/CommandDefaults.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/CommandDefaults.kt similarity index 97% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/CommandDefaults.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/CommandDefaults.kt index bf1aedc7..41578e25 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/CommandDefaults.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/CommandDefaults.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command +package org.anvilpowered.catalyst.core.command import com.velocitypowered.api.command.CommandSource import net.kyori.adventure.text.Component diff --git a/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/CommandModule.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/CommandModule.kt new file mode 100644 index 00000000..7310757d --- /dev/null +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/CommandModule.kt @@ -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 . + */ + +package org.anvilpowered.catalyst.core.command + +import org.anvilpowered.catalyst.core.command.broadcast.BroadcastCommandFactory +import org.anvilpowered.catalyst.core.command.channel.ChannelCommandFactory +import org.anvilpowered.catalyst.core.command.channel.ChannelSwitchFrontend +import org.anvilpowered.catalyst.core.command.message.MessageCommandFactory +import org.anvilpowered.catalyst.core.command.message.ReplyCommandFactory +import org.anvilpowered.catalyst.core.command.nickname.NicknameCommandFactory +import org.koin.core.module.dsl.singleOf +import org.koin.dsl.module + +val CommandModule = module { + singleOf(::ChannelSwitchFrontend) + singleOf(::BroadcastCommandFactory) + singleOf(::CatalystCommandFactory) + singleOf(::ChannelCommandFactory) + singleOf(::MessageCommandFactory) + singleOf(::NicknameCommandFactory) + singleOf(::ReplyCommandFactory) +} diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/registrar/CommandRegistrar.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/CommandRegistrar.kt similarity index 95% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/registrar/CommandRegistrar.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/CommandRegistrar.kt index 24bd2c54..b99e0b09 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/registrar/CommandRegistrar.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/CommandRegistrar.kt @@ -16,12 +16,12 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.registrar +package org.anvilpowered.catalyst.core.command import com.velocitypowered.api.command.BrigadierCommand import com.velocitypowered.api.command.CommandSource import com.velocitypowered.api.proxy.ProxyServer -import org.anvilpowered.catalyst.proxy.command.CatalystCommandFactory +import org.anvilpowered.catalyst.core.Registrar import org.anvilpowered.catalyst.proxy.command.broadcast.BroadcastCommandFactory import org.anvilpowered.catalyst.proxy.command.channel.ChannelCommandFactory import org.anvilpowered.catalyst.proxy.command.message.MessageCommandFactory diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/MinecraftUserCommand.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/MinecraftUserCommand.kt similarity index 94% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/MinecraftUserCommand.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/MinecraftUserCommand.kt index 20dd6e0c..8b83a2c8 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/MinecraftUserCommand.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/MinecraftUserCommand.kt @@ -16,12 +16,12 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command +package org.anvilpowered.catalyst.core.command -import com.velocitypowered.api.command.CommandSource import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.NamedTextColor -import org.anvilpowered.anvil.velocity.command.extractPlayerSource +import org.anvilpowered.anvil.core.command.CommandSource +import org.anvilpowered.anvil.core.command.extractPlayerSource import org.anvilpowered.catalyst.api.user.MinecraftUser import org.anvilpowered.catalyst.api.user.MinecraftUserRepository import org.anvilpowered.kbrig.argument.StringArgumentType @@ -83,7 +83,7 @@ suspend fun CommandExecutionScope.extractMinecraftUserSource( minecraftUserRepository: MinecraftUserRepository, ): MinecraftUser { val player = extractPlayerSource() - val user = minecraftUserRepository.findById(player.uniqueId) + val user = minecraftUserRepository.findById(player.id) if (user == null) { context.source.sendMessage( Component.text() diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/VelocityCommandNode.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/VelocityCommandNode.kt similarity index 97% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/VelocityCommandNode.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/VelocityCommandNode.kt index 20dbf609..18b0e5fd 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/VelocityCommandNode.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/VelocityCommandNode.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command +package org.anvilpowered.catalyst.core.command // context(Registry.Scope, ProxyServerScope) // class VelocityCommandNode : CommonCommandNode( diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/broadcast/BroadcastCommandFactory.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/broadcast/BroadcastCommandFactory.kt similarity index 70% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/broadcast/BroadcastCommandFactory.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/broadcast/BroadcastCommandFactory.kt index 160d3d48..cde9ed19 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/broadcast/BroadcastCommandFactory.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/broadcast/BroadcastCommandFactory.kt @@ -16,27 +16,23 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command.broadcast +package org.anvilpowered.catalyst.core.command.broadcast -import com.velocitypowered.api.command.CommandSource -import com.velocitypowered.api.proxy.ProxyServer -import net.kyori.adventure.text.Component -import org.anvilpowered.anvil.velocity.user.requiresPermission -import org.anvilpowered.catalyst.api.PluginMessages -import org.anvilpowered.catalyst.proxy.command.CommandDefaults +import org.anvilpowered.anvil.core.command.CommandSource +import org.anvilpowered.anvil.core.user.requiresPermission +import org.anvilpowered.catalyst.core.command.CommandDefaults import org.anvilpowered.kbrig.argument.StringArgumentType import org.anvilpowered.kbrig.builder.ArgumentBuilder import org.anvilpowered.kbrig.builder.executesSingleSuccess -import org.anvilpowered.kbrig.context.get import org.anvilpowered.kbrig.tree.LiteralCommandNode -class BroadcastCommandFactory(private val proxyServer: ProxyServer) { +class BroadcastCommandFactory() { fun create(): LiteralCommandNode = ArgumentBuilder.literal("broadcast").executes(CommandDefaults::notEnoughArgs) .requiresPermission("catalyst.chat.broadcast").then( ArgumentBuilder.required("message", StringArgumentType.GreedyPhrase) .executesSingleSuccess { context -> - proxyServer.sendMessage(PluginMessages.getBroadcast(Component.text(context.get("message")))) + TODO() // proxyServer.sendMessage(PluginMessages.getBroadcast(Component.text(context.get("message")))) }.build(), ).build() } diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/ChannelAliasCommandFactory.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelAliasCommandFactory.kt similarity index 97% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/ChannelAliasCommandFactory.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelAliasCommandFactory.kt index a95158f3..91144e51 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/ChannelAliasCommandFactory.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelAliasCommandFactory.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command.channel +package org.anvilpowered.catalyst.core.command.channel import com.velocitypowered.api.command.CommandSource import org.anvilpowered.anvil.core.config.Registry diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/ChannelAliasCommandRegistrar.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelAliasCommandRegistrar.kt similarity index 97% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/ChannelAliasCommandRegistrar.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelAliasCommandRegistrar.kt index 9d080087..75fcfdc9 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/ChannelAliasCommandRegistrar.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelAliasCommandRegistrar.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command.channel +package org.anvilpowered.catalyst.core.command.channel import com.velocitypowered.api.command.BrigadierCommand import com.velocitypowered.api.command.CommandSource diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/ChannelCommand.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelCommand.kt similarity index 98% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/ChannelCommand.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelCommand.kt index 41a5886a..ed659371 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/ChannelCommand.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelCommand.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command.channel +package org.anvilpowered.catalyst.core.command.channel import com.velocitypowered.api.command.CommandSource import com.velocitypowered.api.proxy.Player diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/ChannelCommandFactory.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelCommandFactory.kt similarity index 98% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/ChannelCommandFactory.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelCommandFactory.kt index 4549ed0f..5c6665c1 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/ChannelCommandFactory.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelCommandFactory.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command.channel +package org.anvilpowered.catalyst.core.command.channel import com.velocitypowered.api.command.CommandSource import net.kyori.adventure.text.Component diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChannelSwitchFrontend.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelSwitchFrontend.kt similarity index 87% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChannelSwitchFrontend.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelSwitchFrontend.kt index 6fec390e..17f392fb 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/chat/ChannelSwitchFrontend.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/ChannelSwitchFrontend.kt @@ -16,19 +16,19 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.chat +package org.anvilpowered.catalyst.core.command.channel -import com.velocitypowered.api.command.CommandSource -import com.velocitypowered.api.proxy.Player import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.NamedTextColor +import org.anvilpowered.anvil.core.command.CommandSource +import org.anvilpowered.anvil.core.command.extractPlayerSource +import org.anvilpowered.anvil.core.command.extractPlayerSourceOrNull import org.anvilpowered.anvil.core.config.Registry -import org.anvilpowered.anvil.velocity.command.extractPlayerSource -import org.anvilpowered.anvil.velocity.command.extractPlayerSourceOrNull +import org.anvilpowered.anvil.core.user.Player +import org.anvilpowered.anvil.core.user.hasPermissionNotSet import org.anvilpowered.catalyst.api.chat.ChannelService import org.anvilpowered.catalyst.api.config.CatalystKeys import org.anvilpowered.catalyst.api.config.ChatChannel -import org.anvilpowered.catalyst.proxy.command.channel.extractChannelArgument import org.anvilpowered.kbrig.context.CommandContextScopeDsl import org.anvilpowered.kbrig.context.CommandExecutionScope import org.anvilpowered.kbrig.context.yieldError @@ -47,9 +47,9 @@ class ChannelSwitchFrontend( ) { val targetPlayer = playerProvider() val targetChannel = channelProvider(targetPlayer) - val targetSelf = extractPlayerSourceOrNull()?.uniqueId == targetPlayer.uniqueId + val targetSelf = extractPlayerSourceOrNull()?.id == targetPlayer.id - if (channelService.getForPlayer(targetPlayer.uniqueId).id == targetChannel.id) { + if (channelService.getForPlayer(targetPlayer.id).id == targetChannel.id) { if (targetSelf) { context.source.sendMessage( Component.text() @@ -72,7 +72,7 @@ class ChannelSwitchFrontend( yieldError() } - if (!targetPlayer.hasPermission("${registry[catalystKeys.PERMISSION_CHANNEL_PREFIX]}.${targetChannel.id}")) { + if (targetPlayer.hasPermissionNotSet("${registry[catalystKeys.PERMISSION_CHANNEL_PREFIX]}.${targetChannel.id}")) { if (targetSelf) { context.source.sendMessage( Component.text() @@ -101,7 +101,7 @@ class ChannelSwitchFrontend( .append(Component.text("Switching ").color(NamedTextColor.GREEN)) .append(Component.text(targetPlayer.username).color(NamedTextColor.GOLD)) .append(Component.text(" from channel '").color(NamedTextColor.GREEN)) - .append(channelService.getForPlayer(targetPlayer.uniqueId).name) + .append(channelService.getForPlayer(targetPlayer.id).name) .append(Component.text("' -> '").color(NamedTextColor.GREEN)) .append(targetChannel.name) .append(Component.text("'.").color(NamedTextColor.GREEN)) @@ -112,14 +112,14 @@ class ChannelSwitchFrontend( targetPlayer.sendMessage( Component.text() .append(Component.text("You have switched from channel '").color(NamedTextColor.GREEN)) - .append(channelService.getForPlayer(targetPlayer.uniqueId).name) + .append(channelService.getForPlayer(targetPlayer.id).name) .append(Component.text("' -> '").color(NamedTextColor.GREEN)) .append(targetChannel.name) .append(Component.text("'.").color(NamedTextColor.GREEN)) .build(), ) - channelService.switch(targetPlayer.uniqueId, targetChannel.id) + channelService.switch(targetPlayer.id, targetChannel.id) yieldSuccess() } } diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/Switch.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/Switch.kt similarity index 96% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/Switch.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/Switch.kt index 94e98472..cfb51c8b 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/channel/Switch.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/channel/Switch.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command.channel +package org.anvilpowered.catalyst.core.command.channel import com.velocitypowered.api.command.CommandSource import org.anvilpowered.anvil.velocity.command.extractPlayerSourceOrAbort diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/common/Help.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/common/Help.kt similarity index 96% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/common/Help.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/common/Help.kt index 49f9dbdd..d28060d6 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/common/Help.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/common/Help.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command.common +package org.anvilpowered.catalyst.core.command.common import com.velocitypowered.api.command.CommandSource import net.kyori.adventure.text.Component diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/message/MessageCommandFactory.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/message/MessageCommandFactory.kt similarity index 78% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/message/MessageCommandFactory.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/message/MessageCommandFactory.kt index 77db9d69..ff161665 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/message/MessageCommandFactory.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/message/MessageCommandFactory.kt @@ -16,20 +16,20 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command.message +package org.anvilpowered.catalyst.core.command.message -import com.velocitypowered.api.command.CommandSource -import com.velocitypowered.api.proxy.ProxyServer import net.kyori.adventure.text.minimessage.MiniMessage +import org.anvilpowered.anvil.core.command.CommandSource +import org.anvilpowered.anvil.core.command.extractPlayerArgument +import org.anvilpowered.anvil.core.command.extractPlayerSource +import org.anvilpowered.anvil.core.command.requirePlayerArgumentScoped import org.anvilpowered.anvil.core.config.Registry -import org.anvilpowered.anvil.velocity.command.extractPlayerArgument -import org.anvilpowered.anvil.velocity.command.extractPlayerSource -import org.anvilpowered.anvil.velocity.command.requirePlayerArgumentScoped -import org.anvilpowered.anvil.velocity.user.requiresPermission +import org.anvilpowered.anvil.core.user.PlayerService +import org.anvilpowered.anvil.core.user.requiresPermission import org.anvilpowered.catalyst.api.PluginMessages import org.anvilpowered.catalyst.api.config.CatalystKeys -import org.anvilpowered.catalyst.proxy.chat.PrivateMessageService -import org.anvilpowered.catalyst.proxy.command.CommandDefaults +import org.anvilpowered.catalyst.core.chat.PrivateMessageService +import org.anvilpowered.catalyst.core.command.CommandDefaults import org.anvilpowered.kbrig.argument.StringArgumentType import org.anvilpowered.kbrig.builder.ArgumentBuilder import org.anvilpowered.kbrig.context.executesScoped @@ -41,7 +41,7 @@ import org.anvilpowered.kbrig.tree.LiteralCommandNode class MessageCommandFactory( private val registry: Registry, private val catalystKeys: CatalystKeys, - private val proxyServer: ProxyServer, + private val playerService: PlayerService, private val privateMessageService: PrivateMessageService, ) { @@ -49,7 +49,7 @@ class MessageCommandFactory( ArgumentBuilder.literal("msg").executes(CommandDefaults::notEnoughArgs) .requiresPermission(registry[catalystKeys.PERMISSION_MESSAGE]) .then( - ArgumentBuilder.requirePlayerArgumentScoped(proxyServer) { + ArgumentBuilder.requirePlayerArgumentScoped(playerService) { context.source.sendMessage(PluginMessages.notEnoughArgs) yieldError() }.then( @@ -57,9 +57,9 @@ class MessageCommandFactory( .executesScoped { // console messaging not supported yet val sourcePlayer = extractPlayerSource() - val targetPlayer = extractPlayerArgument(proxyServer) + val targetPlayer = extractPlayerArgument(playerService) - if (sourcePlayer.uniqueId == targetPlayer.uniqueId) { + if (sourcePlayer.id == targetPlayer.id) { context.source.sendMessage(PluginMessages.messageSelf) yieldError() } diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/message/ReplyCommandFactory.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/message/ReplyCommandFactory.kt similarity index 95% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/message/ReplyCommandFactory.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/message/ReplyCommandFactory.kt index cf33b3b7..ac0f4f28 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/message/ReplyCommandFactory.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/message/ReplyCommandFactory.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command.message +package org.anvilpowered.catalyst.core.command.message import com.velocitypowered.api.command.CommandSource import net.kyori.adventure.text.minimessage.MiniMessage @@ -24,8 +24,8 @@ import org.anvilpowered.anvil.core.config.Registry import org.anvilpowered.anvil.velocity.command.extractPlayerSource import org.anvilpowered.anvil.velocity.user.requiresPermission import org.anvilpowered.catalyst.api.config.CatalystKeys +import org.anvilpowered.catalyst.core.command.CommandDefaults import org.anvilpowered.catalyst.proxy.chat.PrivateMessageService -import org.anvilpowered.catalyst.proxy.command.CommandDefaults import org.anvilpowered.kbrig.argument.StringArgumentType import org.anvilpowered.kbrig.builder.ArgumentBuilder import org.anvilpowered.kbrig.context.executesScoped diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/nickname/Delete.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/nickname/Delete.kt similarity index 88% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/nickname/Delete.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/nickname/Delete.kt index 9b9d437c..772bee27 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/nickname/Delete.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/nickname/Delete.kt @@ -16,15 +16,16 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command.nickname +package org.anvilpowered.catalyst.core.command.nickname -import com.velocitypowered.api.command.CommandSource -import com.velocitypowered.api.proxy.Player import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.NamedTextColor +import org.anvilpowered.anvil.core.command.CommandSource +import org.anvilpowered.anvil.core.user.Player +import org.anvilpowered.anvil.core.user.hasPermissionSet import org.anvilpowered.catalyst.api.PluginMessages -import org.anvilpowered.catalyst.proxy.command.common.addHelpChild -import org.anvilpowered.catalyst.proxy.command.requireMinecraftUserArgumentScoped +import org.anvilpowered.catalyst.core.command.common.addHelpChild +import org.anvilpowered.catalyst.core.command.requireMinecraftUserArgumentScoped import org.anvilpowered.kbrig.Command import org.anvilpowered.kbrig.builder.ArgumentBuilder import org.anvilpowered.kbrig.builder.executesSuspending @@ -38,13 +39,13 @@ fun NicknameCommandFactory.createDelete(): LiteralCommandNode = .executesSuspending { context -> // without explicit target player (context.source as? Player)?.let { player -> - if (!player.hasPermission("catalyst.nickname.delete.base")) { + if (!player.hasPermissionSet("catalyst.nickname.delete.base")) { player.sendMessage( PluginMessages.pluginPrefix .append(Component.text("You don't have permission to delete your nickname!", NamedTextColor.RED)), ) 0 - } else if (minecraftUserRepository.deleteNickname(player.uniqueId)) { + } else if (minecraftUserRepository.deleteNickname(player.id)) { player.sendMessage( PluginMessages.pluginPrefix .append(Component.text("Your nickname has been deleted!", NamedTextColor.RED)), @@ -67,7 +68,7 @@ fun NicknameCommandFactory.createDelete(): LiteralCommandNode = } .then( ArgumentBuilder.requireMinecraftUserArgumentScoped(minecraftUserRepository) { minecraftUser -> - if (!context.source.hasPermission("catalyst.nickname.delete.other")) { + if (!context.source.hasPermissionSet("catalyst.nickname.delete.other")) { context.source.sendMessage( PluginMessages.pluginPrefix .append(Component.text("You don't have permission to delete other players' nicknames!", NamedTextColor.RED)), diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/nickname/NicknameCommandFactory.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/nickname/NicknameCommandFactory.kt similarity index 91% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/nickname/NicknameCommandFactory.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/nickname/NicknameCommandFactory.kt index ebbdcc43..7c9596a2 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/nickname/NicknameCommandFactory.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/nickname/NicknameCommandFactory.kt @@ -16,9 +16,9 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command.nickname +package org.anvilpowered.catalyst.core.command.nickname -import com.velocitypowered.api.command.CommandSource +import org.anvilpowered.anvil.core.command.CommandSource import org.anvilpowered.catalyst.api.user.MinecraftUserRepository import org.anvilpowered.kbrig.builder.ArgumentBuilder import org.anvilpowered.kbrig.tree.LiteralCommandNode diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/nickname/Set.kt b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/nickname/Set.kt similarity index 88% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/nickname/Set.kt rename to core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/nickname/Set.kt index 804765b7..33ba343e 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/command/nickname/Set.kt +++ b/core/command/src/main/kotlin/org/anvilpowered/catalyst/core/command/nickname/Set.kt @@ -16,16 +16,18 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.command.nickname +package org.anvilpowered.catalyst.core.command.nickname -import com.velocitypowered.api.command.CommandSource -import com.velocitypowered.api.proxy.Player import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.NamedTextColor import net.kyori.adventure.text.minimessage.MiniMessage +import org.anvilpowered.anvil.core.command.CommandSource +import org.anvilpowered.anvil.core.user.Player +import org.anvilpowered.anvil.core.user.hasPermissionNotSet import org.anvilpowered.catalyst.api.PluginMessages -import org.anvilpowered.catalyst.proxy.command.common.addHelpChild -import org.anvilpowered.catalyst.proxy.command.requireMinecraftUserArgumentScoped +import org.anvilpowered.catalyst.core.command.common.addHelpChild +import org.anvilpowered.catalyst.core.command.requireMinecraftUserArgumentScoped +import org.anvilpowered.kbrig.Command import org.anvilpowered.kbrig.argument.StringArgumentType import org.anvilpowered.kbrig.builder.ArgumentBuilder import org.anvilpowered.kbrig.builder.executesSuspending @@ -41,12 +43,12 @@ fun NicknameCommandFactory.createSet(): LiteralCommandNode = ArgumentBuilder.required("nickname", StringArgumentType.quotablePhrase()) .executesSuspending { context -> (context.source as? Player)?.let { player -> - if (!player.hasPermission("catalyst.nickname.set.base")) { + if (player.hasPermissionNotSet("catalyst.nickname.set.base")) { player.sendMessage( PluginMessages.pluginPrefix .append(Component.text("You don't have permission to set your nickname!", NamedTextColor.RED)), ) - } else if (minecraftUserRepository.updateNickname(player.uniqueId, context["nickname"])) { + } else if (minecraftUserRepository.updateNickname(player.id, context["nickname"])) { player.sendMessage( PluginMessages.pluginPrefix .append(Component.text("Your nickname has been set to '", NamedTextColor.GRAY)) @@ -66,12 +68,12 @@ fun NicknameCommandFactory.createSet(): LiteralCommandNode = ) 0 } - 1 + Command.SINGLE_SUCCESS }, ) .then( ArgumentBuilder.requireMinecraftUserArgumentScoped(minecraftUserRepository) { minecraftUser -> - if (!context.source.hasPermission("catalyst.nickname.set.other")) { + if (context.source.hasPermissionNotSet("catalyst.nickname.set.other")) { context.source.sendMessage( PluginMessages.pluginPrefix .append(Component.text("You don't have permission to set other players' nicknames!", NamedTextColor.RED)), diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/CatalystVelocityPlugin.kt b/core/src/main/kotlin/org/anvilpowered/catalyst/core/CatalystPlugin.kt similarity index 91% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/CatalystVelocityPlugin.kt rename to core/src/main/kotlin/org/anvilpowered/catalyst/core/CatalystPlugin.kt index 72598902..e65e3340 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/CatalystVelocityPlugin.kt +++ b/core/src/main/kotlin/org/anvilpowered/catalyst/core/CatalystPlugin.kt @@ -16,19 +16,18 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy +package org.anvilpowered.catalyst.core import org.anvilpowered.anvil.core.config.Registry import org.anvilpowered.catalyst.api.config.CatalystKeys -import org.anvilpowered.catalyst.proxy.db.user.MinecraftUsers -import org.anvilpowered.catalyst.proxy.db.user.Users -import org.anvilpowered.catalyst.proxy.registrar.Registrar +import org.anvilpowered.catalyst.core.db.user.MinecraftUsers +import org.anvilpowered.catalyst.core.db.user.Users import org.apache.logging.log4j.Logger import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.transactions.transaction -class CatalystVelocityPlugin( +class CatalystPlugin( private val registry: Registry, private val catalystKeys: CatalystKeys, private val logger: Logger, diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/registrar/Registrar.kt b/core/src/main/kotlin/org/anvilpowered/catalyst/core/Registrar.kt similarity index 94% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/registrar/Registrar.kt rename to core/src/main/kotlin/org/anvilpowered/catalyst/core/Registrar.kt index abdb5fe3..995999e1 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/registrar/Registrar.kt +++ b/core/src/main/kotlin/org/anvilpowered/catalyst/core/Registrar.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.registrar +package org.anvilpowered.catalyst.core interface Registrar { fun register() diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/RepositoryExtensions.kt b/core/src/main/kotlin/org/anvilpowered/catalyst/core/db/RepositoryExtensions.kt similarity index 97% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/RepositoryExtensions.kt rename to core/src/main/kotlin/org/anvilpowered/catalyst/core/db/RepositoryExtensions.kt index 7bfac1d2..b7668647 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/RepositoryExtensions.kt +++ b/core/src/main/kotlin/org/anvilpowered/catalyst/core/db/RepositoryExtensions.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.db +package org.anvilpowered.catalyst.core.db import org.anvilpowered.anvil.core.db.DomainEntity import org.jetbrains.exposed.sql.ResultRow diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/SizedIterableWrapper.kt b/core/src/main/kotlin/org/anvilpowered/catalyst/core/db/SizedIterableWrapper.kt similarity index 97% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/SizedIterableWrapper.kt rename to core/src/main/kotlin/org/anvilpowered/catalyst/core/db/SizedIterableWrapper.kt index bb5c21b2..c8ec8d04 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/SizedIterableWrapper.kt +++ b/core/src/main/kotlin/org/anvilpowered/catalyst/core/db/SizedIterableWrapper.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.db +package org.anvilpowered.catalyst.core.db import org.anvilpowered.anvil.core.db.SizedIterable as AnvilSizedIterable import org.jetbrains.exposed.sql.SizedIterable as ExposedSizedIterable diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/user/MinecraftUserRepositoryImpl.kt b/core/src/main/kotlin/org/anvilpowered/catalyst/core/db/user/MinecraftUserRepositoryImpl.kt similarity index 98% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/user/MinecraftUserRepositoryImpl.kt rename to core/src/main/kotlin/org/anvilpowered/catalyst/core/db/user/MinecraftUserRepositoryImpl.kt index 1055e769..a1177f0a 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/user/MinecraftUserRepositoryImpl.kt +++ b/core/src/main/kotlin/org/anvilpowered/catalyst/core/db/user/MinecraftUserRepositoryImpl.kt @@ -16,13 +16,13 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.db.user +package org.anvilpowered.catalyst.core.db.user import org.anvilpowered.anvil.core.db.MutableRepository import org.anvilpowered.anvil.core.db.SizedIterable import org.anvilpowered.catalyst.api.user.MinecraftUser import org.anvilpowered.catalyst.api.user.MinecraftUserRepository -import org.anvilpowered.catalyst.proxy.db.wrap +import org.anvilpowered.catalyst.core.db.wrap import org.apache.logging.log4j.Logger import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.deleteWhere diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/user/MinecraftUsers.kt b/core/src/main/kotlin/org/anvilpowered/catalyst/core/db/user/MinecraftUsers.kt similarity index 97% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/user/MinecraftUsers.kt rename to core/src/main/kotlin/org/anvilpowered/catalyst/core/db/user/MinecraftUsers.kt index 8d07c9b2..0149a076 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/user/MinecraftUsers.kt +++ b/core/src/main/kotlin/org/anvilpowered/catalyst/core/db/user/MinecraftUsers.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.db.user +package org.anvilpowered.catalyst.core.db.user import org.anvilpowered.catalyst.api.user.MinecraftUser import org.jetbrains.exposed.dao.UUIDEntity diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/user/UserRepositoryImpl.kt b/core/src/main/kotlin/org/anvilpowered/catalyst/core/db/user/UserRepositoryImpl.kt similarity index 98% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/user/UserRepositoryImpl.kt rename to core/src/main/kotlin/org/anvilpowered/catalyst/core/db/user/UserRepositoryImpl.kt index ae5feba9..c69e05b1 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/user/UserRepositoryImpl.kt +++ b/core/src/main/kotlin/org/anvilpowered/catalyst/core/db/user/UserRepositoryImpl.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.db.user +package org.anvilpowered.catalyst.core.db.user import org.anvilpowered.anvil.core.db.MutableRepository import org.anvilpowered.anvil.core.db.Pagination diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/user/Users.kt b/core/src/main/kotlin/org/anvilpowered/catalyst/core/db/user/Users.kt similarity index 97% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/user/Users.kt rename to core/src/main/kotlin/org/anvilpowered/catalyst/core/db/user/Users.kt index 2214b9fc..bdf0f741 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/db/user/Users.kt +++ b/core/src/main/kotlin/org/anvilpowered/catalyst/core/db/user/Users.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.db.user +package org.anvilpowered.catalyst.core.db.user import org.anvilpowered.catalyst.api.user.User import org.jetbrains.exposed.dao.UUIDEntity diff --git a/proxy/build.gradle.kts b/proxy/build.gradle.kts deleted file mode 100644 index d54369c2..00000000 --- a/proxy/build.gradle.kts +++ /dev/null @@ -1,27 +0,0 @@ -plugins { - alias(libs.plugins.kotlin.serialization) - kotlin("kapt") -} -dependencies { - api(libs.anvil.core) - - api(platform(libs.exposed.bom)) - api(libs.bundles.exposed) { - exclude(group = "org.slf4j") - } - - compileOnly(platform(libs.adventure.bom)) - compileOnly("net.kyori:adventure-text-serializer-legacy") - compileOnly("net.kyori:adventure-text-serializer-plain") - - implementation(project(":catalyst-api")) - implementation(project(":catalyst-core")) - implementation(libs.anvil.velocity) - kapt(libs.velocity) - implementation(libs.discord.jda) { - exclude(group = "org.slf4j") - } - implementation(libs.discord.webhooks) { - exclude(group = "org.slf4j") - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index e06050bd..b003b27f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -21,9 +21,25 @@ pluginManagement { rootProject.name = "catalyst" sequenceOf( + "app-breeze", + "app-breeze-backend", + "app-breeze-core", + "app-breeze-proxy", + "app-cyclone", + "app-cyclone-backend", + "app-cyclone-core", + "app-cyclone-proxy", + "app-cyclone-worker", + "app-droplet", + "app-droplet-core", + "app-droplet-paper", + "app-droplet-sponge", "api", "core", - "proxy", + "core-chat", + "core-command", + "velocity", + "velocity-listener", ).forEach { val project = ":catalyst-$it" include(project) diff --git a/velocity/build.gradle.kts b/velocity/build.gradle.kts new file mode 100644 index 00000000..1b49b9f0 --- /dev/null +++ b/velocity/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + alias(libs.plugins.kotlin.serialization) +} + +dependencies { + api(libs.anvil.velocity) + + compileOnly(platform(libs.adventure.bom)) + compileOnly("net.kyori:adventure-text-serializer-legacy") + compileOnly("net.kyori:adventure-text-serializer-plain") + + implementation(project(":catalyst-api")) + implementation(project(":catalyst-core")) +} diff --git a/velocity/listener/build.gradle.kts b/velocity/listener/build.gradle.kts new file mode 100644 index 00000000..3dfcf908 --- /dev/null +++ b/velocity/listener/build.gradle.kts @@ -0,0 +1,4 @@ +dependencies { + api(project(":catalyst-core-chat")) + api(libs.anvil.velocity) +} diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/ChatListener.kt b/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/ChatListener.kt similarity index 85% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/ChatListener.kt rename to velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/ChatListener.kt index c6494180..84beaf47 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/ChatListener.kt +++ b/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/ChatListener.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.listener +package org.anvilpowered.catalyst.velocity.listener import com.velocitypowered.api.event.Subscribe import com.velocitypowered.api.event.player.PlayerChatEvent @@ -25,6 +25,9 @@ import kotlinx.coroutines.runBlocking import net.kyori.adventure.text.Component import net.kyori.adventure.text.minimessage.MiniMessage import org.anvilpowered.anvil.core.config.Registry +import org.anvilpowered.anvil.core.user.hasPermissionNotSet +import org.anvilpowered.anvil.core.user.hasPermissionSet +import org.anvilpowered.anvil.velocity.user.toAnvilPlayer import org.anvilpowered.catalyst.api.chat.ChannelMessage import org.anvilpowered.catalyst.api.chat.ChannelService import org.anvilpowered.catalyst.api.chat.LuckpermsService @@ -34,9 +37,9 @@ import org.anvilpowered.catalyst.api.chat.placeholder.OnlineUserFormat import org.anvilpowered.catalyst.api.config.CatalystKeys import org.anvilpowered.catalyst.api.user.MinecraftUserRepository import org.anvilpowered.catalyst.api.user.getOnlineUser -import org.anvilpowered.catalyst.proxy.chat.ChatFilter -import org.anvilpowered.catalyst.proxy.chat.ChatService -import org.anvilpowered.catalyst.proxy.discord.WebhookSender +import org.anvilpowered.catalyst.core.chat.ChatFilter +import org.anvilpowered.catalyst.core.chat.ChatService +import org.anvilpowered.catalyst.core.chat.bridge.discord.WebhookSender import org.apache.logging.log4j.Logger class ChatListener( @@ -56,19 +59,19 @@ class ChatListener( ) { @Subscribe fun onPlayerChat(event: PlayerChatEvent) = runBlocking { - val player = event.player + val player = event.player.toAnvilPlayer() if (!registry[catalystKeys.CHAT_ENABLED] || chatService.isDisabledForPlayer(player)) { return@runBlocking } event.result = PlayerChatEvent.ChatResult.denied() - val rawMessage = if (player.hasPermission(registry[catalystKeys.PERMISSION_CHAT_COLOR])) { + val rawMessage = if (player.hasPermissionSet(registry[catalystKeys.PERMISSION_CHAT_COLOR])) { MiniMessage.miniMessage().deserialize(event.message) } else { Component.text(event.message) } // TODO: Move this to dedicated class var rawContent = chatService.highlightPlayerNames(player, rawMessage) - if (!player.hasPermission(registry[catalystKeys.PERMISSION_LANGUAGE_ADMIN]) && + if (player.hasPermissionNotSet(registry[catalystKeys.PERMISSION_LANGUAGE_ADMIN]) && registry[catalystKeys.CHAT_FILTER_ENABLED] ) { rawContent = chatFilter.replaceSwears(rawContent) @@ -80,7 +83,7 @@ class ChatListener( // Idea: %search% -> google.com/search?q=%search% val formattedRawContent = onlineUserFormatResolver.resolve(rawContent, OnlineUserFormat.Placeholders(listOf("source")), user) - val channel = channelService.getForPlayer(player.uniqueId) + val channel = channelService.getForPlayer(player.id) val channelMessage = channelMessageBuilderFactory.build { user(user.user) diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/CommandListener.kt b/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/CommandListener.kt similarity index 97% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/CommandListener.kt rename to velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/CommandListener.kt index a4933172..3f26a806 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/CommandListener.kt +++ b/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/CommandListener.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.listener +package org.anvilpowered.catalyst.velocity.listener import com.velocitypowered.api.event.Subscribe import com.velocitypowered.api.event.command.CommandExecuteEvent diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/JoinListener.kt b/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/JoinListener.kt similarity index 92% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/JoinListener.kt rename to velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/JoinListener.kt index 93f4424b..0afed6d9 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/JoinListener.kt +++ b/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/JoinListener.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.listener +package org.anvilpowered.catalyst.velocity.listener import com.velocitypowered.api.event.Subscribe import com.velocitypowered.api.event.connection.PostLoginEvent @@ -26,13 +26,14 @@ import net.kyori.adventure.text.format.NamedTextColor import net.kyori.adventure.text.format.TextDecoration import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer import org.anvilpowered.anvil.core.config.Registry +import org.anvilpowered.anvil.velocity.user.toAnvilPlayer import org.anvilpowered.catalyst.api.chat.ChannelService import org.anvilpowered.catalyst.api.chat.placeholder.OnlineUserFormat import org.anvilpowered.catalyst.api.config.CatalystKeys import org.anvilpowered.catalyst.api.user.MinecraftUser import org.anvilpowered.catalyst.api.user.MinecraftUserRepository -import org.anvilpowered.catalyst.proxy.chat.StaffListService -import org.anvilpowered.catalyst.proxy.discord.WebhookSender +import org.anvilpowered.catalyst.core.chat.StaffListService +import org.anvilpowered.catalyst.core.chat.bridge.discord.WebhookSender import org.apache.logging.log4j.Logger class JoinListener( @@ -57,7 +58,7 @@ class JoinListener( ), ) - val user = MinecraftUser.Online(result.entity, player) + val user = MinecraftUser.Online(result.entity, player.toAnvilPlayer()) if (result.created && registry[catalystKeys.JOIN_LISTENER_ENABLED]) { proxyServer.sendMessage(onlineUserFormatResolver.resolve(registry[catalystKeys.JOIN_MESSAGE_FIRST], user)) @@ -89,7 +90,7 @@ class JoinListener( .append(Component.text("!", NamedTextColor.GRAY, TextDecoration.ITALIC)) .append(Component.newline()) .append(Component.text("You are currently chatting in channel ", NamedTextColor.AQUA, TextDecoration.ITALIC)) - .append(channelService.getForPlayer(user.player.uniqueId).name) + .append(channelService.getForPlayer(user.player.id).name) .build(), ) } diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/LeaveListener.kt b/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/LeaveListener.kt similarity index 90% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/LeaveListener.kt rename to velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/LeaveListener.kt index ce866290..83c06df7 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/LeaveListener.kt +++ b/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/LeaveListener.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.listener +package org.anvilpowered.catalyst.velocity.listener import com.velocitypowered.api.event.Subscribe import com.velocitypowered.api.event.connection.DisconnectEvent @@ -23,13 +23,14 @@ import com.velocitypowered.api.proxy.ProxyServer import kotlinx.coroutines.runBlocking import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer import org.anvilpowered.anvil.core.config.Registry +import org.anvilpowered.anvil.velocity.user.toAnvilPlayer import org.anvilpowered.catalyst.api.chat.ChannelService import org.anvilpowered.catalyst.api.chat.placeholder.OnlineUserFormat import org.anvilpowered.catalyst.api.config.CatalystKeys import org.anvilpowered.catalyst.api.user.MinecraftUserRepository import org.anvilpowered.catalyst.api.user.getOnlineUser -import org.anvilpowered.catalyst.proxy.chat.StaffListService -import org.anvilpowered.catalyst.proxy.discord.WebhookSender +import org.anvilpowered.catalyst.core.chat.StaffListService +import org.anvilpowered.catalyst.core.chat.bridge.discord.WebhookSender import org.apache.logging.log4j.Logger class LeaveListener( @@ -48,7 +49,7 @@ class LeaveListener( if (event.loginStatus == DisconnectEvent.LoginStatus.PRE_SERVER_JOIN) { return@runBlocking } - val player = event.player + val player = event.player.toAnvilPlayer() val user = minecraftUserRepository.getOnlineUser(player) staffListService.removeStaffNames(player.username) val leaveMessage = onlineUserFormatResolver.resolve(registry[catalystKeys.LEAVE_MESSAGE], user) diff --git a/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/ListenerModule.kt b/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/ListenerModule.kt new file mode 100644 index 00000000..27adfa4e --- /dev/null +++ b/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/ListenerModule.kt @@ -0,0 +1,29 @@ +/* + * 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 . + */ + +package org.anvilpowered.catalyst.velocity.listener + +import org.koin.core.module.dsl.singleOf +import org.koin.dsl.module + +val ListenerModule = module { + singleOf(::ChatListener) + singleOf(::CommandListener) + singleOf(::JoinListener) + singleOf(::LeaveListener) +} diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/discord/ProxyPingListener.kt b/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/ProxyPingListener.kt similarity index 98% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/discord/ProxyPingListener.kt rename to velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/ProxyPingListener.kt index a3cd8f6b..b42f545a 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/discord/ProxyPingListener.kt +++ b/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/ProxyPingListener.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.discord +package org.anvilpowered.catalyst.velocity.listener import com.velocitypowered.api.event.Subscribe import com.velocitypowered.api.event.proxy.ProxyPingEvent diff --git a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/ServerSelectListener.kt b/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/ServerSelectListener.kt similarity index 97% rename from proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/ServerSelectListener.kt rename to velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/ServerSelectListener.kt index 87a1cf81..83d11bef 100644 --- a/proxy/src/main/kotlin/org/anvilpowered/catalyst/proxy/listener/ServerSelectListener.kt +++ b/velocity/listener/src/main/kotlin/org.anvilpowered.catalyst.velocity/listener/ServerSelectListener.kt @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.catalyst.proxy.listener +package org.anvilpowered.catalyst.velocity.listener import com.velocitypowered.api.event.Subscribe import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent