Skip to content

Commit

Permalink
Added some testing for proxy resource packs, but I could not get it t…
Browse files Browse the repository at this point in the history
…o work with my current knowledge, and it just crashes the server when using ProtocolLib on default fallback and throws an error when not using ProtocolLib
  • Loading branch information
byPixelTV committed Jul 9, 2024
1 parent ccf5b1e commit 2a299ef
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/main/kotlin/de/bypixeltv/redivelocity/RediVelocity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import com.velocitypowered.api.plugin.Plugin
import com.velocitypowered.api.proxy.ProxyServer
import de.bypixeltv.redivelocity.commands.RediVelocityCommand
import de.bypixeltv.redivelocity.config.ConfigLoader
import de.bypixeltv.redivelocity.listeners.DisconnectListener
import de.bypixeltv.redivelocity.listeners.PostLoginListener
import de.bypixeltv.redivelocity.listeners.ProxyPingListener
import de.bypixeltv.redivelocity.listeners.ServerSwitchListener
import de.bypixeltv.redivelocity.listeners.*
import de.bypixeltv.redivelocity.managers.RedisController
import de.bypixeltv.redivelocity.managers.UpdateManager
import de.bypixeltv.redivelocity.utils.ProxyIdGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import de.bypixeltv.redivelocity.config.Config
import de.bypixeltv.redivelocity.managers.RedisController
import net.kyori.adventure.text.minimessage.MiniMessage

class PostLoginListener @Inject constructor(private val rediVelocity: RediVelocity, private val redisController: RedisController, private val config: Config, private val proxyId: String, private val proxy: ProxyServer) {
class PostLoginListener @Inject constructor(private val rediVelocity: RediVelocity, private val redisController: RedisController, private val config: Config, private val proxyId: String, private val proxy: ProxyServer) {

private val miniMessage = MiniMessage.miniMessage()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package de.bypixeltv.redivelocity.listeners

import com.google.inject.Inject
import com.velocitypowered.api.event.EventTask
import com.velocitypowered.api.event.Subscribe
import com.velocitypowered.api.event.player.configuration.PlayerFinishConfigurationEvent
import com.velocitypowered.api.proxy.Player
import com.velocitypowered.api.proxy.ProxyServer
import com.velocitypowered.api.proxy.player.ResourcePackInfo
import de.bypixeltv.redivelocity.config.Config
import net.kyori.adventure.resource.ResourcePackCallback
import net.kyori.adventure.text.minimessage.MiniMessage
import java.util.concurrent.CompletableFuture

class ResourcePackListeners @Inject constructor(private val config: Config, private val proxy: ProxyServer) {

private val miniMessage = MiniMessage.miniMessage()

private fun createPackRequest(player: Player, callback: ResourcePackCallback): ResourcePackInfo {
return proxy.createResourcePackBuilder(config.resourcepackUrl)
.setId(player.uniqueId)
.setPrompt(miniMessage.deserialize(config.resourcepackMessage))
.build()
}

@Subscribe
fun onConfigurationFinish(e: PlayerFinishConfigurationEvent) : EventTask {
println("Entered configuration finish event")

// store a new countdown latch for this player
val userId = e.player.uniqueId
val future = CompletableFuture<Boolean>()

// assemble the resource pack and
val pack = createPackRequest(
e.player,
callback = ResourcePackCallback.onTerminal(
{ _, _ ->
// decrease the latch as it was successful
future.complete(true)

// inform about successful load
println("Successfully finished resource pack download of player $userId.")
},
{ _, _ ->
// remove the latch as the operation failed
future.complete(false)

// inform about failure
println("Failed resource pack download of player $userId.")
},
),
)

// send resource pack request
e.player.sendResourcePacks(pack)
println("Sending resource pack download request of player $userId.")

// await the processing
return EventTask.resumeWhenComplete(future)
}
}

0 comments on commit 2a299ef

Please sign in to comment.