diff --git a/src/main/kotlin/one/oktw/galaxy/proxy/extension/Player.kt b/src/main/kotlin/one/oktw/galaxy/proxy/extension/Player.kt index 4d4c964..e3408a3 100644 --- a/src/main/kotlin/one/oktw/galaxy/proxy/extension/Player.kt +++ b/src/main/kotlin/one/oktw/galaxy/proxy/extension/Player.kt @@ -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) + } +} diff --git a/src/main/kotlin/one/oktw/galaxy/proxy/resourcepack/ResourcePackHelper.kt b/src/main/kotlin/one/oktw/galaxy/proxy/resourcepack/ResourcePackHelper.kt index f46037d..333a1e5 100644 --- a/src/main/kotlin/one/oktw/galaxy/proxy/resourcepack/ResourcePackHelper.kt +++ b/src/main/kotlin/one/oktw/galaxy/proxy/resourcepack/ResourcePackHelper.kt @@ -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)