From 022ed831873c425881ee068375bb47def7d82bd1 Mon Sep 17 00:00:00 2001 From: alemidev Date: Tue, 19 Apr 2022 01:17:57 +0200 Subject: [PATCH] don't stop if already stopped --- src/aiocraft/client.py | 6 ++++-- src/aiocraft/dispatcher.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/aiocraft/client.py b/src/aiocraft/client.py index 852c2df..d067e92 100644 --- a/src/aiocraft/client.py +++ b/src/aiocraft/client.py @@ -88,7 +88,8 @@ class MinecraftClient: await self._handshake(ConnectionState.STATUS) return await self._status(ping) finally: - await self.dispatcher.disconnect() + if self.dispatcher.connected: + await self.dispatcher.disconnect() async def join(self, host:str="", port:int=0, proto:int=0): if self.online_mode: @@ -99,7 +100,8 @@ class MinecraftClient: if await self._login(): await self._play() finally: - await self.dispatcher.disconnect() + if self.dispatcher.connected: + await self.dispatcher.disconnect() async def _handshake(self, state:ConnectionState): await self.dispatcher.write( diff --git a/src/aiocraft/dispatcher.py b/src/aiocraft/dispatcher.py index 98b63bd..214ebd9 100644 --- a/src/aiocraft/dispatcher.py +++ b/src/aiocraft/dispatcher.py @@ -249,6 +249,7 @@ class Dispatcher: await self._incoming.put(packet) if self.state != ConnectionState.PLAY: await self._incoming.join() # During play we can pre-process packets + except (asyncio.TimeoutError, TimeoutError): self.logger.error("Connection timed out") await self.disconnect(block=False)