don't stop if already stopped

This commit is contained in:
əlemi 2022-04-19 01:17:57 +02:00
parent ca45980bcd
commit 022ed83187
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E
2 changed files with 5 additions and 2 deletions

View file

@ -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(

View file

@ -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)