generated from MineInAbyss/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite to avoid many async ChannelData writes, try to clean up overa…
…ll structure to encourage this goal
- Loading branch information
Showing
13 changed files
with
341 additions
and
294 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyChannel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.mineinabyss.chatty | ||
|
||
import com.mineinabyss.chatty.components.ChannelType | ||
import com.mineinabyss.chatty.components.SpyOnChannels | ||
import com.mineinabyss.chatty.queries.SpyingPlayers | ||
import com.mineinabyss.geary.papermc.tracking.entities.toGeary | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import net.kyori.adventure.audience.Audience | ||
import net.kyori.adventure.text.format.NamedTextColor | ||
import net.kyori.adventure.text.format.TextColor | ||
import org.bukkit.Bukkit | ||
import org.bukkit.entity.Player | ||
|
||
@Serializable | ||
data class ChattyChannel( | ||
val channelType: ChannelType, | ||
val permission: String = "", | ||
val logToConsole: Boolean = true, | ||
val simpleConsoleMessages: Boolean = false, | ||
val proxy: Boolean = false, | ||
val discordsrv: Boolean = true, | ||
val isDefaultChannel: Boolean = false, | ||
val isStaffChannel: Boolean = false, | ||
val format: String = "", | ||
@SerialName("messageColor") val _messageColor: String = "white", | ||
val channelRadius: Int = 0, | ||
val channelAliases: List<String> = listOf(), | ||
) { | ||
val key by lazy { chatty.config.channels.entries.first { it.value == this }.key } | ||
val messageColor: TextColor | ||
get() = TextColor.fromHexString(_messageColor) ?: NamedTextColor.NAMES.value(_messageColor) | ||
?: NamedTextColor.WHITE | ||
|
||
|
||
fun getAudience(player: Player): Collection<Audience> { | ||
val onlinePlayers by lazy { Bukkit.getOnlinePlayers() } | ||
val audiences = mutableSetOf<Audience>() | ||
|
||
when (channelType) { | ||
ChannelType.GLOBAL -> audiences.addAll(onlinePlayers) | ||
ChannelType.RADIUS -> { | ||
if (channelRadius <= 0) audiences.addAll(onlinePlayers) | ||
else audiences.addAll(player.world.players.filter { p -> | ||
player.location.distanceSquared(p.location) <= (channelRadius * channelRadius) | ||
}) | ||
} | ||
|
||
ChannelType.PERMISSION -> audiences.addAll(onlinePlayers.filter { p -> p.hasPermission(permission) }) | ||
// Intended for Guilds etc., want to consider finding a non-permission way for this | ||
ChannelType.PRIVATE -> audiences.add(player) | ||
} | ||
|
||
// Add spying players | ||
val spies = SpyingPlayers().run { | ||
toList { query -> query.player.takeIf { query.spying.channels.contains(key) } }.filterNotNull() | ||
} | ||
audiences.addAll(spies) | ||
|
||
return audiences | ||
} | ||
} |
247 changes: 122 additions & 125 deletions
247
chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyCommands.kt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 16 additions & 5 deletions
21
chatty-paper/src/main/kotlin/com/mineinabyss/chatty/components/ChannelData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.