Skip to content

Commit a00dc66

Browse files
committed
Fixed resource pack message NPE
Fixes #385
1 parent 96da3a8 commit a00dc66

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/main/java/net/raphimc/viaproxy/proxy/packethandler/ResourcePackPacketHandler.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import net.raphimc.netminecraft.packet.impl.play.S2CPlayResourcePackPushPacket;
3232
import net.raphimc.viaproxy.ViaProxy;
3333
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
34+
import net.raphimc.viaproxy.util.logging.Logger;
3435

3536
import java.nio.charset.StandardCharsets;
3637
import java.util.List;
@@ -65,17 +66,26 @@ public boolean handleP2S(Packet packet, List<ChannelFutureListener> listeners) {
6566
private void sendResourcePack() {
6667
if (!ViaProxy.getConfig().getResourcePackUrl().isBlank()) {
6768
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+
}
7178

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);
7989
}
8090
}, 250, TimeUnit.MILLISECONDS);
8191
}

0 commit comments

Comments
 (0)