|
31 | 31 | import net.raphimc.netminecraft.packet.impl.play.S2CPlayResourcePackPushPacket; |
32 | 32 | import net.raphimc.viaproxy.ViaProxy; |
33 | 33 | import net.raphimc.viaproxy.proxy.session.ProxyConnection; |
| 34 | +import net.raphimc.viaproxy.util.logging.Logger; |
34 | 35 |
|
35 | 36 | import java.nio.charset.StandardCharsets; |
36 | 37 | import java.util.List; |
@@ -65,17 +66,26 @@ public boolean handleP2S(Packet packet, List<ChannelFutureListener> listeners) { |
65 | 66 | private void sendResourcePack() { |
66 | 67 | if (!ViaProxy.getConfig().getResourcePackUrl().isBlank()) { |
67 | 68 | this.proxyConnection.getChannel().eventLoop().schedule(() -> { |
68 | | - final String url = ViaProxy.getConfig().getResourcePackUrl(); |
69 | | - final boolean required = Via.getConfig().isForcedUse1_17ResourcePack(); |
70 | | - final ATextComponent message = TextComponentSerializer.LATEST.deserialize(Via.getConfig().get1_17ResourcePackPrompt().toString()); |
| 69 | + try { |
| 70 | + final String url = ViaProxy.getConfig().getResourcePackUrl(); |
| 71 | + final boolean required = Via.getConfig().isForcedUse1_17ResourcePack(); |
| 72 | + final ATextComponent message; |
| 73 | + if (Via.getConfig().get1_17ResourcePackPrompt() != null) { |
| 74 | + message = TextComponentSerializer.LATEST.deserialize(Via.getConfig().get1_17ResourcePackPrompt().toString()); |
| 75 | + } else { |
| 76 | + message = null; |
| 77 | + } |
71 | 78 |
|
72 | | - if (this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_20_3)) { |
73 | | - this.proxyConnection.getC2P().writeAndFlush(new S2CPlayResourcePackPushPacket(UUID.randomUUID(), url, "", required, message)).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); |
74 | | - } else if (this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_8)) { |
75 | | - this.proxyConnection.getC2P().writeAndFlush(new S2CPlayResourcePackPacket(url, "", required, message)).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); |
76 | | - } else if (this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_7_2)) { |
77 | | - final byte[] data = url.getBytes(StandardCharsets.UTF_8); |
78 | | - this.proxyConnection.getC2P().writeAndFlush(new S2CPlayCustomPayloadPacket("MC|RPack", data)).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); |
| 79 | + if (this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_20_3)) { |
| 80 | + this.proxyConnection.getC2P().writeAndFlush(new S2CPlayResourcePackPushPacket(UUID.randomUUID(), url, "", required, message)).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); |
| 81 | + } else if (this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_8)) { |
| 82 | + this.proxyConnection.getC2P().writeAndFlush(new S2CPlayResourcePackPacket(url, "", required, message)).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); |
| 83 | + } else if (this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_7_2)) { |
| 84 | + final byte[] data = url.getBytes(StandardCharsets.UTF_8); |
| 85 | + this.proxyConnection.getC2P().writeAndFlush(new S2CPlayCustomPayloadPacket("MC|RPack", data)).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); |
| 86 | + } |
| 87 | + } catch (Throwable e) { |
| 88 | + Logger.LOGGER.warn("Failed to send resource pack", e); |
79 | 89 | } |
80 | 90 | }, 250, TimeUnit.MILLISECONDS); |
81 | 91 | } |
|
0 commit comments