Skip to content

Commit

Permalink
chore: bump idofront & geary (#60)
Browse files Browse the repository at this point in the history
* feat: bump ido & geary

* chore: bump idofront

* chore: bump geary
  • Loading branch information
Boy0000 authored Oct 31, 2024
1 parent bbf42ca commit 4b89f95
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 130 deletions.
11 changes: 5 additions & 6 deletions chatty-paper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ dependencies {
compileOnly(libs.placeholderapi)
compileOnly(libs.discordsrv)

// Shaded
implementation(libs.imageloader)

}

configurations {
Expand All @@ -40,10 +37,12 @@ configurations {
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf(
kotlin {
compilerOptions {
freeCompilerArgs.addAll(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
"-opt-in=kotlin.ExperimentalUnsignedTypes",
"-Xcontext-receivers"
)
}
}
27 changes: 15 additions & 12 deletions chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ package com.mineinabyss.chatty

import com.github.shynixn.mccoroutine.bukkit.launch
import com.mineinabyss.chatty.commands.ChattyBrigadierCommands
import com.mineinabyss.chatty.components.ChannelData
import com.mineinabyss.chatty.components.ChattyNickname
import com.mineinabyss.chatty.helpers.DiscordEmoteFixer
import com.mineinabyss.chatty.listeners.ChatListener
import com.mineinabyss.chatty.listeners.ChattyProxyListener
import com.mineinabyss.chatty.listeners.DiscordListener
import com.mineinabyss.chatty.listeners.PlayerListener
import com.mineinabyss.chatty.placeholders.PlaceholderAPIHook
import com.mineinabyss.chatty.queries.SpyingPlayersQuery
import com.mineinabyss.geary.addons.dsl.createAddon
import com.mineinabyss.geary.autoscan.autoscan
import com.mineinabyss.geary.helpers.componentId
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.geary.systems.builders.cache
import com.mineinabyss.geary.papermc.configure
import com.mineinabyss.geary.papermc.gearyPaper
import com.mineinabyss.idofront.config.config
import com.mineinabyss.idofront.di.DI
import com.mineinabyss.idofront.plugin.Plugins
Expand All @@ -33,16 +31,21 @@ import net.kyori.adventure.chat.SignedMessage
import org.bukkit.plugin.java.JavaPlugin

class ChattyPlugin : JavaPlugin() {

private val ChattyAddon = createAddon("Chatty", configuration = {
autoscan(classLoader, "com.mineinabyss.chatty") {
all()
}
})

override fun onLoad() {
geary {
autoscan(classLoader, "com.mineinabyss.chatty") {
all()
}
gearyPaper.configure {
install(ChattyAddon)
}

// register components we'll use async now since they'll error otherwise
componentId<ChattyNickname>()
componentId<ChannelData>()
//componentId<ChattyNickname>()
//componentId<ChannelData>()
}

override fun onEnable() {
Expand Down Expand Up @@ -74,7 +77,7 @@ class ChattyPlugin : JavaPlugin() {
override val emotefixer: DiscordEmoteFixer by config("emotefixer", dataFolder.toPath(), DiscordEmoteFixer())
override val isPlaceholderApiLoaded: Boolean get() = Plugins.isEnabled("PlaceholderAPI")
override val isDiscordSRVLoaded: Boolean get() = Plugins.isEnabled("DiscordSRV")
override val spyingPlayers = geary.cache(SpyingPlayersQuery())
override val spyingPlayers = gearyPaper.worldManager.global.cache(::SpyingPlayersQuery)
}

DI.add<ChattyContext>(chattyContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.mineinabyss.geary.serialization.getOrSetPersisting
import com.mineinabyss.geary.serialization.setPersisting
import com.mineinabyss.idofront.commands.brigadier.IdoRootCommand
import com.mineinabyss.idofront.commands.brigadier.commands
import com.mineinabyss.idofront.commands.brigadier.playerExecutes
import com.mineinabyss.idofront.entities.toPlayer
import com.mineinabyss.idofront.events.call
import com.mineinabyss.idofront.messaging.error
Expand Down Expand Up @@ -71,46 +72,40 @@ object ChattyBrigadierCommands {
}
}
"sound" {
playerExecutes {
player.error("Missing sound-argument...")
}
val soundName by StringArgumentType.word().suggests {
playerExecutes(StringArgumentType.word().suggests {
suggest(
chatty.config.ping.alternativePingSounds
.takeUnless { "all" in it } ?: Sound.entries.map { it.key.asString() }
.takeUnless { "all" in it } ?: Sound.entries.map { it.key().asString() }
)
}
playerExecutes {
}.named("sound")) { sound ->
val gearyPlayer = player.toGeary()
val oldData = gearyPlayer.get<ChannelData>() ?: return@playerExecutes
if (soundName() in alternativePingSounds) {
gearyPlayer.setPersisting(oldData.copy(pingSound = soundName()))
if (sound in alternativePingSounds) {
gearyPlayer.setPersisting(oldData.copy(pingSound = sound))
player.sendFormattedMessage(chatty.messages.ping.changedPingSound)
} else player.sendFormattedMessage(chatty.messages.ping.invalidPingSound)
}
}
}
"channels" {
requiresPermission("")
executes {
(sender as? Player)?.sendFormattedMessage(chatty.messages.channels.availableChannels)
?: sender.sendRichMessage(chatty.messages.channels.availableChannels)
}
}
"channel" {
playerExecutes {
player.error("Missing channel-argument...")
}
val channel by ChattyChannelArgument().suggests {
requiresPermission("")
playerExecutes(ChattyChannelArgument().suggests {
suggest(chatty.config.channels.entries.asSequence()
.filter { it.value.channelType != ChannelType.CUSTOM }
.filter { it.value.permission.isEmpty() || context.source.sender.hasPermission(it.value.permission) }
.sortedBy {
it.key in setOf(defaultChannel().key, radiusChannel()?.key, adminChannel()?.key).filterNotNull()
}.map { it.key }.toList()
)
}
playerExecutes {
if (channel()?.channelType != ChannelType.CUSTOM) swapChannel(player, channel())
}.named("channel")) { channel ->
if (channel.channelType != ChannelType.CUSTOM) swapChannel(player, channel)
}
}
"commandspy" {
Expand All @@ -126,23 +121,15 @@ object ChattyBrigadierCommands {
}
}
"spy" {
playerExecutes {
player.error("Missing channel-argument...")
}
val channel by ChattyChannelArgument().suggests {
suggest(chatty.config.channels.entries
.filter {
it.value.permission.isEmpty() || context.source.sender.hasPermission(it.value.permission)
}.sortedBy {
playerExecutes(ChattyChannelArgument().suggests {
suggest(chatty.config.channels.entries.asSequence()
.filter { it.value.channelType != ChannelType.CUSTOM }
.filter { it.value.permission.isEmpty() || context.source.sender.hasPermission(it.value.permission) }
.sortedBy {
it.key in setOf(defaultChannel().key, radiusChannel()?.key, adminChannel()?.key).filterNotNull()
}.map { it.key }
}.map { it.key }.toList()
)
}
playerExecutes {
val channel = channel() ?: run {
player.sendFormattedMessage(chatty.messages.channels.noChannelWithName)
return@playerExecutes
}
}.named("channel")) { channel ->
val spy = player.toGeary().getOrSetPersisting<SpyOnChannels> { SpyOnChannels() }

when {
Expand All @@ -166,16 +153,6 @@ object ChattyBrigadierCommands {
}
"nickname" {
val nickMessage = chatty.messages.nicknames
playerExecutes {
player.chattyNickname = null
sender.sendFormattedMessage(nickMessage.selfEmpty)
}

val nickname by StringArgumentType.greedyString().suggests {
(context.source.executor as? Player)?.chattyNickname?.let {
suggestFiltering(it)
}
}

fun String.nicknameTooLong(): Boolean {
return when (chatty.config.nicknames.countTagsInLength) {
Expand All @@ -184,44 +161,61 @@ object ChattyBrigadierCommands {
}
}

fun handleNickname(player: Player, applyTo: Player, nick: String) {
playerExecutes(
StringArgumentType.string().suggests {
(context.source.executor as? Player)?.chattyNickname?.let {
suggestFiltering(it)
}
}.named("nickname").default { "" },
ArgumentTypes.player().resolve().map { it.single() }.named("player").default { executor as Player },
) { nickname, applyTo ->
when {
!player.hasPermission(ChattyPermissions.NICKNAME) ->
player.sendFormattedMessage(nickMessage.selfDenied)

player == applyTo && nickname.isEmpty() -> {
applyTo.chattyNickname = null
applyTo.sendFormattedMessage(nickMessage.selfEmpty)
}
player.uniqueId != applyTo.uniqueId && !player.hasPermission(ChattyPermissions.NICKNAME_OTHERS) ->
player.sendFormattedMessage(nickMessage.otherDenied, applyTo)

player.uniqueId != applyTo.uniqueId && nick.isEmpty() -> {
player.uniqueId != applyTo.uniqueId && nickname.isEmpty() -> {
applyTo.chattyNickname = null
applyTo.sendFormattedMessage(nickMessage.selfEmpty)
player.sendFormattedMessage(nickMessage.otherEmpty, applyTo)
}

!player.hasPermission(ChattyPermissions.BYPASS_TAG_PERM) && nick.nicknameTooLong() ->
!player.hasPermission(ChattyPermissions.BYPASS_TAG_PERM) && nickname.nicknameTooLong() ->
player.sendFormattedMessage(nickMessage.tooLong)

nick.isNotEmpty() -> {
applyTo.chattyNickname = nick
nickname.isNotEmpty() -> {
applyTo.chattyNickname = nickname
if (player.uniqueId != applyTo.uniqueId) player.sendFormattedMessage(nickMessage.otherSuccess, player)
else player.sendFormattedMessage(nickMessage.selfSuccess)
}
}
}

playerExecutes {
val nickname = nickname() ?: return@playerExecutes
val applyTo = nickname.substringBefore(" ").toPlayer()?.takeIf { it.uniqueId != player.uniqueId } ?: player
handleNickname(player, applyTo, nickname.removePrefix(applyTo.name.takeIf { applyTo.uniqueId != player.uniqueId } ?: ""))
}
}
}

("global" / "g") { handleShortCutChannel(globalChannel()) }
("local" / "l") { handleShortCutChannel(radiusChannel()) }
("admin" / "a") { handleShortCutChannel(adminChannel()) }
("message" / "msg") { handleMessage() }
("reply" / "r") { handleReply() }
("global" / "g") {
requiresPermission("")
handleShortCutChannel(globalChannel())
}
("local" / "l") {
requiresPermission("")
handleShortCutChannel(radiusChannel())
}
("admin" / "a") {
requiresPermission("chatty.channel.admin")
handleShortCutChannel(adminChannel())
}
("message" / "msg") {
requiresPermission("")
handleMessage()
}
("reply" / "r") {
requiresPermission("")
handleReply()
}
}
}

Expand All @@ -244,50 +238,19 @@ object ChattyBrigadierCommands {
}

private fun IdoRootCommand.handleMessage() {
playerExecutes {
player.error("Missing player-argument...")
}
val sendTo by ArgumentTypes.player()
playerExecutes {
player.error("Missing message-argument...")
}
if (chatty.config.chat.disableChatSigning) {
val message by StringArgumentType.greedyString()
playerExecutes {
player.handleSendingPrivateMessage(sendTo().first(), null, message(), false)
}
} else {
val message by ArgumentTypes.signedMessage()
playerExecutes {
chatty.plugin.launch {
val signedMessage = message().resolveSignedMessage("message", context).await()
player.handleSendingPrivateMessage(sendTo().first(), signedMessage, null, false)
}
}
playerExecutes(
ArgumentTypes.player().resolve().map { it.single() }.named("sendTo"),
StringArgumentType.greedyString().named("message")
) { sendTo, message ->
player.handleSendingPrivateMessage(sendTo, null, message, false)
}
}

private fun IdoRootCommand.handleReply() {
playerExecutes {
player.error("Missing message-argument...")
}
if (chatty.config.chat.disableChatSigning) {
val message by StringArgumentType.greedyString()
playerExecutes {
player.toGeary().get<ChannelData>()?.lastMessager?.toPlayer()
?.let { player.handleSendingPrivateMessage(it, null, message(), true) }
?: player.sendFormattedMessage(chatty.messages.privateMessages.emptyReply)
}
} else {
val message by ArgumentTypes.signedMessage()
playerExecutes {
chatty.plugin.launch {
val signedMessage = message().resolveSignedMessage("message", context).await()
player.toGeary().get<ChannelData>()?.lastMessager?.toPlayer()
?.let { player.handleSendingPrivateMessage(it, signedMessage, null, true) }
?: player.sendFormattedMessage(chatty.messages.privateMessages.emptyReply)
}
}
playerExecutes(StringArgumentType.greedyString().named("message")) { message ->
player.toGeary().get<ChannelData>()?.lastMessager?.toPlayer()
?.let { player.handleSendingPrivateMessage(it, null, message, true) }
?: player.sendFormattedMessage(chatty.messages.privateMessages.emptyReply)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import java.util.regex.Pattern

val alternativePingSounds: List<String> =
chatty.config.ping.let { ping -> if ("*" in ping.alternativePingSounds || "all" in ping.alternativePingSounds)
Sound.entries.map { it.key.toString() }.toList() else ping.alternativePingSounds }
Sound.entries.map { it.key().toString() }.toList() else ping.alternativePingSounds }

val pingEnabledChannels: List<String> =
chatty.config.ping.let { ping -> if ("*" in ping.enabledChannels || "all" in ping.enabledChannels) channelNames() else ping.enabledChannels }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import net.kyori.adventure.text.minimessage.tag.standard.StandardTags
import org.bukkit.permissions.Permission

object ChattyPermissions {
const val NICKNAME = "chatty.nickname"
const val NICKNAME_OTHERS = "chatty.nickname.others"
const val BYPASS_TAG_PERM = "chatty.tags.bypass"
const val BYPASS_CHAT_FILTERS_PERM = "chatty.chat.filters.bypass"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import com.mineinabyss.chatty.components.ChannelData
import com.mineinabyss.chatty.components.CommandSpy
import com.mineinabyss.chatty.events.ChattyPlayerChatEvent
import com.mineinabyss.chatty.helpers.*
import com.mineinabyss.geary.modules.Geary
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.geary.papermc.gearyPaper
import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull
import com.mineinabyss.geary.systems.builders.cache
import com.mineinabyss.geary.systems.query.GearyQuery
import com.mineinabyss.idofront.textcomponents.serialize
import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent
Expand All @@ -28,10 +29,9 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent

@Suppress("UnstableApiUsage")
class ChatListener : Listener {
val plainText = PlainTextComponentSerializer.plainText()
val commandSpyQuery = geary.cache(CommandSpyQuery())
val commandSpyQuery = gearyPaper.worldManager.global.cache(::CommandSpyQuery)

class CommandSpyQuery : GearyQuery() {
class CommandSpyQuery(world: Geary) : GearyQuery(world) {
val player by get<Player>()
override fun ensure() = this { has<CommandSpy>() }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.mineinabyss.chatty.queries

import com.mineinabyss.chatty.components.SpyOnChannels
import com.mineinabyss.geary.modules.Geary
import com.mineinabyss.geary.systems.query.GearyQuery
import org.bukkit.entity.Player

class SpyingPlayersQuery : GearyQuery() {
class SpyingPlayersQuery(world: Geary) : GearyQuery(world) {
val player by get<Player>()
val spying by get<SpyOnChannels>()
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=com.mineinabyss
version=0.8
idofrontVersion=0.24.21
idofrontVersion=0.25.17
Loading

0 comments on commit 4b89f95

Please sign in to comment.