Skip to content

Commit

Permalink
Try remove old resource pack
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Jan 3, 2024
1 parent fa5d986 commit 70fed16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/kotlin/one/oktw/galaxy/proxy/extension/Player.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package one.oktw.galaxy.proxy.extension

import com.velocitypowered.api.proxy.Player
import com.velocitypowered.api.proxy.server.ServerPing
import one.oktw.galaxy.proxy.Main.Companion.main

fun Player.toSamplePlayer() = ServerPing.SamplePlayer(username, uniqueId)
fun Player.sendPacket(o: Any) {
try {
val connection = this.javaClass.getMethod("getConnection").invoke(this)
connection.javaClass.getMethod("write").invoke(connection, o)
} catch (e: Exception) {
main.logger.error("Call velocity method error.", e)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ package one.oktw.galaxy.proxy.resourcepack

import com.velocitypowered.api.proxy.Player
import one.oktw.galaxy.proxy.Main.Companion.main
import one.oktw.galaxy.proxy.extension.sendPacket

class ResourcePackHelper {
companion object{
fun trySendResourcePack(player: Player, galaxy: String){
val resourcePack = main.config.galaxiesResourcePack[galaxy] ?: return
// workaround Minecraft 1.20.3 not auto unload old resource pack
try {
val packet = Class.forName("com.velocitypowered.proxy.protocol.packet.RemoveResourcePack").getConstructor().newInstance()
player.sendPacket(packet)
} catch (e: Exception) {
main.logger.error("Send remove resource pack packet error.", e)
}

player.sendResourcePackOffer(
main.proxy.createResourcePackBuilder(resourcePack.uri.toString())
.setHash(resourcePack.hash)
Expand Down

0 comments on commit 70fed16

Please sign in to comment.