Skip to content

Commit fc767e6

Browse files
committed
why?
1 parent 54850d3 commit fc767e6

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mod_name=Channel
3030
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
3131
mod_license=GNU GPL 3.0
3232
# The mod version. See https://semver.org/
33-
mod_version=26.1.2-23+beta
33+
mod_version=26.1.2-24+beta
3434
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
3535
# This should match the base package used for the mod sources.
3636
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

src/main/java/cn/ussshenzhou/channel/subspace/client/SubspaceConnection.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,22 @@ protected void initChannel(SocketChannel ch) {
232232
}
233233

234234
public static void send(SubspacePacket packet) {
235-
if (channel != null && channel.isActive()) {
236-
var buf = new FriendlyByteBuf(channel.alloc().buffer());
237-
packet.encode(buf);
238-
channel.writeAndFlush(buf);
235+
if (channel == null) {
236+
LogUtils.getLogger().warn("channel is null. This should not happen. Skip send {}.", packet.getClass().getSimpleName());
237+
return;
238+
}
239+
if (!channel.isActive()) {
240+
LogUtils.getLogger().warn("channel is inactive. This should not happen. Skip send {}.", packet.getClass().getSimpleName());
241+
return;
239242
}
243+
var buf = new FriendlyByteBuf(channel.alloc().buffer());
244+
packet.encode(buf);
245+
channel.writeAndFlush(buf)
246+
.addListener((ChannelFutureListener) future -> {
247+
if (!future.isSuccess()) {
248+
LogUtils.getLogger().error("Failed to send {}.", packet.getClass().getSimpleName(), future.cause());
249+
}
250+
});
240251
}
241252

242253
public static void terminate() {

0 commit comments

Comments
 (0)