Skip to content

Commit

Permalink
Velocity (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 authored Jul 20, 2022
1 parent 84959b0 commit b93b8ba
Show file tree
Hide file tree
Showing 23 changed files with 355 additions and 30 deletions.
11 changes: 5 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
plugins {
kotlin("jvm")
kotlin("plugin.serialization")
id("com.mineinabyss.conventions.kotlin")
id("com.mineinabyss.conventions.papermc")
// id("com.mineinabyss.conventions.nms")
id("com.mineinabyss.conventions.copyjar")
id("com.mineinabyss.conventions.publication")
id("com.mineinabyss.conventions.testing")
kotlin("plugin.serialization")
id("org.jetbrains.compose")
id("org.jetbrains.dokka")
}

repositories {
Expand All @@ -24,13 +22,14 @@ dependencies {

// Other plugins
compileOnly(chattyLibs.geary.papermc.core)
compileOnly(chattyLibs.guiy)
compileOnly(chattyLibs.bondrewdlikeshisemotes)

/// Third-party plugins
compileOnly(chattyLibs.placeholderapi)

// Shaded
implementation(libs.idofront.core)
//implementation(project(":velocity"))
//implementation(project(":chatty-paper"))
//implementation(libs.idofront.core)
// compileOnly(libs.idofront.nms)
}
32 changes: 32 additions & 0 deletions chatty-paper/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
plugins {
id("com.mineinabyss.conventions.kotlin")
id("com.mineinabyss.conventions.papermc")
id("com.mineinabyss.conventions.copyjar")
id("com.mineinabyss.conventions.publication")
id("com.mineinabyss.conventions.testing")
kotlin("plugin.serialization")
}

repositories {
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
}

dependencies {
// MineInAbyss platform
compileOnly(libs.kotlinx.serialization.json)
compileOnly(libs.kotlinx.serialization.kaml)
compileOnly(libs.kotlinx.coroutines)
compileOnly(libs.minecraft.mccoroutine)
compileOnly(libs.koin.core)

// Other plugins
compileOnly(chattyLibs.geary.papermc.core)
compileOnly(chattyLibs.bondrewdlikeshisemotes)

/// Third-party plugins
compileOnly(chattyLibs.placeholderapi)

// Shaded
implementation(libs.idofront.core)
// compileOnly(libs.idofront.nms)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import com.mineinabyss.idofront.commands.arguments.stringArg
import com.mineinabyss.idofront.commands.execution.IdofrontCommandExecutor
import com.mineinabyss.idofront.commands.extensions.actions.ensureSenderIsPlayer
import com.mineinabyss.idofront.messaging.miniMsg
import com.mineinabyss.idofront.commands.extensions.actions.playerAction
import com.mineinabyss.idofront.messaging.*
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object ChattyConfig : IdofrontConfig<ChattyConfig.Data>(chattyPlugin, Data.seria
val ping: Ping,
val join: Join,
val leave: Leave,
val proxy: Proxy,
val channels: Map<String, ChattyChannel>,
val messages: Messages,
)
Expand All @@ -32,10 +33,16 @@ object ChattyConfig : IdofrontConfig<ChattyConfig.Data>(chattyPlugin, Data.seria
val enabled: Boolean,
)

@Serializable
data class Proxy(
val enableProxySwitchMessages: Boolean = true,
)

@Serializable
data class ChattyChannel(
val channelType: ChannelType,
val permission: String = "",
val proxy: Boolean = false,
val isDefaultChannel: Boolean = false,
val format: Format,
val channelRadius: Int = 0,
Expand Down Expand Up @@ -68,15 +75,22 @@ object ChattyConfig : IdofrontConfig<ChattyConfig.Data>(chattyPlugin, Data.seria
val toggledPingSound: String = "Ping sound is now <i>%chatty_player_ping_toggle%</i>.",
val changedPingSound: String = "Ping sound set to <i>%chatty_ping_sound%</i>",
val invalidPingSound: String = "<red>You must specify a valid sound to play.",

val availableChannels: String = "<gold>Available channels are:<newline><yellow>%chatty_available_channels%",
val channelChanged: String = "<red>You have changed to channel <yellow>%chatty_channel%<red>.",
val noChannelWithName: String = "No channel by this name exists.",
val missingChannelPermission: String = "You do not have permission to join this channel.",
val emptyChannelMessage: String = "<red>There is no-one to read your message",

val firstJoinMessage: String = "<gradient:#058330:#ff9200>Welcome %player_name% to %server_name%</gradient>",
val joinMessage: String = "<green>%player_name%<white> has joined the server.",
val leaveMessage: String = "<red>%player_name%<white> has left the server.",
val nickNameChanged: String = "Nickname set to <white><i>&player_displayname%</i></white>.",
val configReloaded: String = "<green>Chatty config reloaded.",

val proxyJoin: String = "<green>+ <white>| <aqua>%player_displayname%",
val proxyLeave: String = "<red>- <white>| <aqua>%player_displayname%",
val proxySwitchToMessage: String = "<gray>↑<white> ┃ <aqua>%player_displayname% <gray>left to <aqua>%player_proxy_new_server% server.",
val proxySwitchFromMessage: String = "<gray>↑<white> ┃ <aqua>%player_displayname% <gray>left to <aqua>%player_proxy_new_server% server.",
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mineinabyss.chatty

import com.mineinabyss.chatty.listeners.ChatListener
import com.mineinabyss.chatty.listeners.ChattyProxyListener
import com.mineinabyss.chatty.listeners.PlayerListener
import com.mineinabyss.chatty.placeholderapi.PlaceholderHook
import com.mineinabyss.geary.addon.autoscan
Expand All @@ -12,6 +13,7 @@ import org.bukkit.Bukkit
import org.bukkit.plugin.java.JavaPlugin

val chattyPlugin: ChattyPlugin by lazy { JavaPlugin.getPlugin(ChattyPlugin::class.java) }
const val chattyProxyChannel = "chatty:proxy"

interface ChattyContext {
companion object : ChattyContext by getService()
Expand All @@ -38,6 +40,10 @@ class ChattyPlugin : JavaPlugin() {
PlayerListener()
)

// Register the proxy listener
server.messenger.registerIncomingPluginChannel(this, chattyProxyChannel, ChattyProxyListener())
server.messenger.registerOutgoingPluginChannel(this, chattyProxyChannel)

gearyAddon {
autoscan("com.mineinabyss") {
all()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.mineinabyss.chatty.components

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.bukkit.configuration.serialization.SerializableAs

@Serializable
@SerialName("chatty:hide_join_leave")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ fun Player.getChannelFromPlayer() : ChattyConfig.ChattyChannel? {
return chattyConfig.channels.entries.firstOrNull { it.key == this.playerData.channelId }?.value
}

fun Player.channelIsProxyEnabled() : Boolean {
return getChannelFromPlayer()?.proxy ?: false
}

fun Player.verifyPlayerChannel() {
if (playerData.channelId !in chattyConfig.channels)
playerData.channelId = getDefaultChat().key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fun chattyPlaceholders(player: Player, string: String) : Map<String, String> {
"player_channel_format_suffix" to channel?.format?.suffix.toString(),
"player_channel_format_message" to channel?.format?.messageFormat.toString(),
"player_channel_aliases" to channel?.channelAliases.toString(),
"player_channel_proxy_enabled" to channel?.proxy.toString(),

"ping_defaultsound" to ping.defaultPingSound,
"ping_volume" to ping.pingVolume.toString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mineinabyss.chatty.listeners

import com.mineinabyss.chatty.chattyPlugin
import com.mineinabyss.chatty.chattyProxyChannel
import com.mineinabyss.chatty.components.playerData
import com.mineinabyss.chatty.helpers.*
import com.mineinabyss.idofront.messaging.miniMsg
Expand All @@ -15,10 +17,11 @@ import org.bukkit.event.Listener

class ChatListener : Listener {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
fun AsyncChatEvent.onPlayerChat() {
player.verifyPlayerChannel()
val channel = getChannelFromId(player.playerData.channelId) ?: return
val channelId = player.playerData.channelId
val channel = getChannelFromId(channelId) ?: return
val displayName = if (channel.format.useDisplayName) player.displayName() else player.name.miniMsg()
val audiences = viewers()
audiences.clear()
Expand All @@ -31,7 +34,7 @@ class ChatListener : Listener {
.append(channel.format.messageFormat.miniMsg().append(originalMessage()))
)

val pingedPlayer = originalMessage().deserialize().checkForPlayerPings(player.playerData.channelId)
val pingedPlayer = originalMessage().deserialize().checkForPlayerPings(channelId)
if (pingedPlayer != null && pingedPlayer != player && pingedPlayer in audiences) {
message().handlePlayerPings(player, pingedPlayer)
audiences.remove(pingedPlayer)
Expand All @@ -44,6 +47,11 @@ class ChatListener : Listener {
} else audiences.forEach { audience ->
RendererExtension().render(player, displayName, message(), audience)
}

if (channel.proxy) {
//Append channel to give proxy info on what channel the message is from
player.sendPluginMessage(chattyPlugin, chattyProxyChannel, ("$channelId " + message().deserialize()).toByteArray())
}
audiences.clear()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mineinabyss.chatty.listeners

import com.mineinabyss.chatty.chattyProxyChannel
import com.mineinabyss.chatty.components.ChannelType
import com.mineinabyss.chatty.helpers.getChannelFromId
import com.mineinabyss.idofront.messaging.miniMsg
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.plugin.messaging.PluginMessageListener

class ChattyProxyListener : PluginMessageListener {
override fun onPluginMessageReceived(ch: String, player: Player, message: ByteArray) {
if (ch != chattyProxyChannel) return
// Get channel from last part of string as it is sent via the proxy message
val decoded = message.decodeToString()
val channelId = decoded.substringBefore(" ")
val channel = getChannelFromId(channelId) ?: return
val msg = decoded.replaceFirst("$channelId ", "")
when (channel.channelType) {
ChannelType.GLOBAL -> Bukkit.getOnlinePlayers()
ChannelType.RADIUS -> emptyList()
ChannelType.PERMISSION -> Bukkit.getOnlinePlayers().filter { it.hasPermission(channel.permission) }
ChannelType.PRIVATE -> emptyList() //TODO Implement this when PRIVATE is more clear
}.forEach { it.sendMessage(msg.miniMsg()) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,34 @@ package com.mineinabyss.chatty.listeners

import com.mineinabyss.chatty.components.HideJoinLeave
import com.mineinabyss.chatty.components.PlayerData
import com.mineinabyss.chatty.helpers.chattyConfig
import com.mineinabyss.chatty.helpers.messages
import com.mineinabyss.chatty.helpers.translatePlaceholders
import com.mineinabyss.chatty.helpers.verifyPlayerChannel
import com.mineinabyss.chatty.helpers.*
import com.mineinabyss.geary.papermc.access.toGeary
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.event.player.PlayerQuitEvent

class PlayerListener : Listener {

//TODO Disable if proxy should handle this
@EventHandler
fun PlayerJoinEvent.onFirstJoin() {
if (player.toGeary().has<PlayerData>()) return
if (chattyConfig.join.enabled && chattyConfig.join.firstJoin.enabled) {
if (player.toGeary().has<PlayerData>() || player.channelIsProxyEnabled()) return
if (chattyConfig.join.enabled && chattyConfig.join.firstJoin.enabled)
joinMessage(translatePlaceholders(player, messages.firstJoinMessage))
}
}

@EventHandler
fun PlayerJoinEvent.onJoin() {
player.verifyPlayerChannel()
if (chattyConfig.join.enabled && !player.toGeary().has<HideJoinLeave>()) {
if (player.toGeary().has<HideJoinLeave>() || player.channelIsProxyEnabled()) return
if (chattyConfig.join.enabled)
joinMessage(translatePlaceholders(player, messages.joinMessage))
}
}

@EventHandler
fun PlayerQuitEvent.onDisconnect() {
if (chattyConfig.leave.enabled && !player.toGeary().has<HideJoinLeave>()) {
if (player.toGeary().has<HideJoinLeave>() || player.channelIsProxyEnabled()) return
if (chattyConfig.leave.enabled)
quitMessage(translatePlaceholders(player, messages.leaveMessage))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ join:
leave:
enabled: true

proxy:
enableProxySwitchMessages: false

ping:
enabledChannels: # "all" for all channels
- "global"
Expand Down Expand Up @@ -90,3 +93,7 @@ messages:
leaveMessage: "<red>%player_name%<white> has left the server."
nickNameChanged: "Nickname set to <white><i>%player_displayname%</i></white>."
configReloaded: "<green>Chatty config reloaded."
proxyJoin: "<green>+ <white>| <aqua>%player_displayname%%player_server%)"
proxyLeave: "<red>- <white>| <aqua>%player_displayname%"
proxySwitchToMessage: "<gray>↑<white> ┃ <aqua>%player_displayname% <gray>left to <aqua>%player_proxy_new_server% server."
proxySwitchFromMessage: "<gray>↑<white> ┃ <aqua>%player_displayname% <gray>left to <aqua>%player_proxy_new_server% server."
File renamed without changes.
63 changes: 63 additions & 0 deletions chatty-velocity/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
val kotlinVersion: String by project
val velocityVersion: String by project
val coroutinesVersion: String by project

group = "com.velocitypowered"
version = "$velocityVersion+$kotlinVersion"

plugins {
kotlin("jvm")
kotlin("kapt")
kotlin("plugin.serialization")
id("com.github.johnrengelman.shadow")
`maven-publish`
}

repositories {
mavenLocal()
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
}

dependencies {
implementation(kotlin("reflect"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3")
api(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:$coroutinesVersion"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$coroutinesVersion")
implementation("net.kyori:adventure-extra-kotlin:4.10.1")

compileOnly(chattyLibs.velocity)
kapt(chattyLibs.velocity)
}

tasks.build {
dependsOn(tasks.shadowJar.get())
dependsOn("generateTemplates")
}

val templateSource = file("src/main/templates")
val templateDest = layout.buildDirectory.dir("generated/sources/templates")
tasks.create<Copy>("generateTemplates") {
val props = mapOf(
"version" to project.version
)
inputs.properties(props)
from(templateSource)
into(templateDest)
expand(props)
}

sourceSets.main {
java {
srcDir(templateDest)
}
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
artifact(tasks.shadowJar.get())
}
}
}
Loading

0 comments on commit b93b8ba

Please sign in to comment.