refactor: reuse the packet handler executor

This commit is contained in:
ChomeNS
2025-05-25 13:09:10 +07:00
parent 393715f9da
commit a368cc6f13
2 changed files with 7 additions and 6 deletions

View File

@@ -1 +1 @@
3324
3330

View File

@@ -180,8 +180,6 @@ public class Bot extends SessionAdapter {
}
private void reconnect () {
if (session != null) session = null; // does this do nothing?
connectAttempts++;
this.listener.dispatch(Listener::onConnecting);
@@ -192,7 +190,7 @@ public class Bot extends SessionAdapter {
options.username;
}
final ClientSession session = ClientNetworkSessionFactory.factory()
final ClientNetworkSessionFactory factory = ClientNetworkSessionFactory.factory()
.setAddress(host, port)
.setProtocol(
new MinecraftProtocol(
@@ -202,8 +200,11 @@ public class Bot extends SessionAdapter {
),
null
)
)
.create();
);
if (this.session != null) factory.setPacketHandlerExecutor(this.session.getPacketHandlerExecutor());
final ClientSession session = factory.create();
this.session = session;